Class: Arrolio::TextLayout::KnuthPlass::Penalty
- Defined in:
- lib/arrolio/text_layout/knuth_plass/item.rb
Overview
A penalty represents a potential break point. Width is the
width of the hyphen (or 0 if no hyphen). Flagged penalties
(e.g., hyphenation) incur extra cost. A penalty of Infinity
means "never break here"; -Infinity means "always break".
Instance Attribute Summary collapse
-
#char_offset ⇒ Object
readonly
Returns the value of attribute char_offset.
-
#flagged ⇒ Object
readonly
Returns the value of attribute flagged.
-
#penalty ⇒ Object
readonly
Returns the value of attribute penalty.
-
#run_index ⇒ Object
readonly
Returns the value of attribute run_index.
Attributes inherited from Item
Instance Method Summary collapse
- #forced_break? ⇒ Boolean
-
#initialize(penalty:, width: 0, flagged: false, run_index: nil, char_offset: nil) ⇒ Penalty
constructor
A new instance of Penalty.
- #no_break? ⇒ Boolean
- #penalty? ⇒ Boolean
Methods inherited from Item
Constructor Details
#initialize(penalty:, width: 0, flagged: false, run_index: nil, char_offset: nil) ⇒ Penalty
Returns a new instance of Penalty.
61 62 63 64 65 66 67 |
# File 'lib/arrolio/text_layout/knuth_plass/item.rb', line 61 def initialize(penalty:, width: 0, flagged: false, run_index: nil, char_offset: nil) super(width: width) @penalty = penalty.to_f @flagged = flagged @run_index = run_index @char_offset = char_offset end |
Instance Attribute Details
#char_offset ⇒ Object (readonly)
Returns the value of attribute char_offset.
59 60 61 |
# File 'lib/arrolio/text_layout/knuth_plass/item.rb', line 59 def char_offset @char_offset end |
#flagged ⇒ Object (readonly)
Returns the value of attribute flagged.
59 60 61 |
# File 'lib/arrolio/text_layout/knuth_plass/item.rb', line 59 def flagged @flagged end |
#penalty ⇒ Object (readonly)
Returns the value of attribute penalty.
59 60 61 |
# File 'lib/arrolio/text_layout/knuth_plass/item.rb', line 59 def penalty @penalty end |
#run_index ⇒ Object (readonly)
Returns the value of attribute run_index.
59 60 61 |
# File 'lib/arrolio/text_layout/knuth_plass/item.rb', line 59 def run_index @run_index end |
Instance Method Details
#forced_break? ⇒ Boolean
71 72 73 |
# File 'lib/arrolio/text_layout/knuth_plass/item.rb', line 71 def forced_break? @penalty == -Float::INFINITY end |
#no_break? ⇒ Boolean
75 76 77 |
# File 'lib/arrolio/text_layout/knuth_plass/item.rb', line 75 def no_break? @penalty == Float::INFINITY end |
#penalty? ⇒ Boolean
69 |
# File 'lib/arrolio/text_layout/knuth_plass/item.rb', line 69 def penalty? = true |