Class: VisualWidth::Formatter::Align
- Inherits:
-
Object
- Object
- VisualWidth::Formatter::Align
- Includes:
- VisualWidth
- Defined in:
- lib/visual_width/formatter.rb
Constant Summary
Constants included from VisualWidth
Ambiguous, EAST_ASIAN, VisualWidth::Fullwide, VERSION, Wide
Instance Method Summary collapse
- #center(cell, width) ⇒ Object
-
#initialize(east_asian: VisualWidth::EAST_ASIAN) ⇒ Align
constructor
A new instance of Align.
- #left(cell, width) ⇒ Object
- #right(cell, width) ⇒ Object
Methods included from VisualWidth
count, each_width, measure, truncate
Constructor Details
#initialize(east_asian: VisualWidth::EAST_ASIAN) ⇒ Align
Returns a new instance of Align.
7 8 9 |
# File 'lib/visual_width/formatter.rb', line 7 def initialize(east_asian: VisualWidth::EAST_ASIAN) @east_asian = east_asian end |
Instance Method Details
#center(cell, width) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/visual_width/formatter.rb', line 23 def center(cell, width) align(cell, width) do |line, fill| half = fill / 2.0 (' ' * half.floor) + line + (' ' * half.ceil) end end |
#left(cell, width) ⇒ Object
11 12 13 14 15 |
# File 'lib/visual_width/formatter.rb', line 11 def left(cell, width) align(cell, width) do |line, fill| line + (' ' * fill) end end |
#right(cell, width) ⇒ Object
17 18 19 20 21 |
# File 'lib/visual_width/formatter.rb', line 17 def right(cell, width) align(cell, width) do |line, fill| (' ' * fill) + line end end |