Class: Arrolio::TextLayout::Line
- Inherits:
-
Object
- Object
- Arrolio::TextLayout::Line
- Defined in:
- lib/arrolio/text_layout/line.rb
Overview
One laid-out line: a list of PlacedRun tuples plus the line's content width, target width, and alignment.
Defined Under Namespace
Classes: PlacedRun
Instance Attribute Summary collapse
-
#align ⇒ Object
readonly
Returns the value of attribute align.
-
#max_width ⇒ Object
readonly
Returns the value of attribute max_width.
-
#placed_runs ⇒ Object
readonly
Returns the value of attribute placed_runs.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #empty? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(placed_runs, width:, max_width:, align: :left) ⇒ Line
constructor
A new instance of Line.
- #justified? ⇒ Boolean
- #justify_stretch ⇒ Object
- #x_offset ⇒ Object
Constructor Details
#initialize(placed_runs, width:, max_width:, align: :left) ⇒ Line
Returns a new instance of Line.
17 18 19 20 21 22 23 |
# File 'lib/arrolio/text_layout/line.rb', line 17 def initialize(placed_runs, width:, max_width:, align: :left) @placed_runs = placed_runs.freeze @width = width.to_f @max_width = max_width.to_f @align = align freeze end |
Instance Attribute Details
#align ⇒ Object (readonly)
Returns the value of attribute align.
15 16 17 |
# File 'lib/arrolio/text_layout/line.rb', line 15 def align @align end |
#max_width ⇒ Object (readonly)
Returns the value of attribute max_width.
15 16 17 |
# File 'lib/arrolio/text_layout/line.rb', line 15 def max_width @max_width end |
#placed_runs ⇒ Object (readonly)
Returns the value of attribute placed_runs.
15 16 17 |
# File 'lib/arrolio/text_layout/line.rb', line 15 def placed_runs @placed_runs end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
15 16 17 |
# File 'lib/arrolio/text_layout/line.rb', line 15 def width @width end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
51 52 53 54 55 56 57 |
# File 'lib/arrolio/text_layout/line.rb', line 51 def ==(other) other.is_a?(self.class) && placed_runs == other.placed_runs && width == other.width && max_width == other.max_width && align == other.align end |
#empty? ⇒ Boolean
25 26 27 |
# File 'lib/arrolio/text_layout/line.rb', line 25 def empty? @placed_runs.empty? end |
#hash ⇒ Object
61 62 63 |
# File 'lib/arrolio/text_layout/line.rb', line 61 def hash [self.class, placed_runs, width, max_width, align].hash end |
#justified? ⇒ Boolean
37 38 39 |
# File 'lib/arrolio/text_layout/line.rb', line 37 def justified? @align == :justify end |
#justify_stretch ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/arrolio/text_layout/line.rb', line 41 def justify_stretch return 0.0 unless justified? return 0.0 if @width >= @max_width gaps = word_gap_count return 0.0 if gaps.zero? (@max_width - @width) / gaps.to_f end |
#x_offset ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/arrolio/text_layout/line.rb', line 29 def x_offset case @align when :center then ((@max_width - @width) / 2.0) when :right then (@max_width - @width) else 0.0 end end |