Class: Arrolio::TextLayout::KnuthPlass::ItemBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/arrolio/text_layout/knuth_plass/item_builder.rb

Overview

Converts a list of InlineRun values into KnuthPlass::Item sequences (Box, Glue, Penalty). Each word becomes a Box; spaces become Glue; potential break points become Penalty items.

Constant Summary collapse

HYPHEN_PENALTY =
50.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runs, measurer:) ⇒ ItemBuilder

Returns a new instance of ItemBuilder.



15
16
17
18
# File 'lib/arrolio/text_layout/knuth_plass/item_builder.rb', line 15

def initialize(runs, measurer:)
  @runs = runs
  @measurer = measurer
end

Instance Attribute Details

#measurerObject (readonly)

Returns the value of attribute measurer.



13
14
15
# File 'lib/arrolio/text_layout/knuth_plass/item_builder.rb', line 13

def measurer
  @measurer
end

#runsObject (readonly)

Returns the value of attribute runs.



13
14
15
# File 'lib/arrolio/text_layout/knuth_plass/item_builder.rb', line 13

def runs
  @runs
end

Instance Method Details

#buildObject



20
21
22
23
24
25
26
27
# File 'lib/arrolio/text_layout/knuth_plass/item_builder.rb', line 20

def build
  items = []
  @runs.each_with_index do |run, run_idx|
    build_items_for_run(run, run_idx, items)
  end
  items << FINISHED
  items
end