Class: Arrolio::FlowContext
- Inherits:
-
Object
- Object
- Arrolio::FlowContext
- Defined in:
- lib/arrolio/flow_context.rb
Overview
State threaded through every flowable fit/emit call. Holds page-level state flowables need: current page number, total page count (filled in between pass 1 and pass 2), the running citation table, and the LayoutSpec for style resolution.
Instance Attribute Summary collapse
-
#citations ⇒ Object
readonly
Returns the value of attribute citations.
-
#heading_entries ⇒ Object
readonly
Returns the value of attribute heading_entries.
-
#layout_spec ⇒ Object
readonly
Returns the value of attribute layout_spec.
-
#page_count ⇒ Object
Returns the value of attribute page_count.
-
#page_number ⇒ Object
Returns the value of attribute page_number.
-
#renderer ⇒ Object
Returns the value of attribute renderer.
Instance Method Summary collapse
- #citation_for(ref_id) ⇒ Object
-
#initialize(layout_spec:, page_number: 1, page_count: nil) ⇒ FlowContext
constructor
A new instance of FlowContext.
- #record_citation(ref_id, page_number) ⇒ Object
- #record_heading(number:, title:, level:, page_number:, id: nil) ⇒ Object
- #total_pages ⇒ Object
Constructor Details
#initialize(layout_spec:, page_number: 1, page_count: nil) ⇒ FlowContext
Returns a new instance of FlowContext.
12 13 14 15 16 17 18 |
# File 'lib/arrolio/flow_context.rb', line 12 def initialize(layout_spec:, page_number: 1, page_count: nil) @layout_spec = layout_spec @page_number = page_number @page_count = page_count @citations = {} @heading_entries = [] end |
Instance Attribute Details
#citations ⇒ Object (readonly)
Returns the value of attribute citations.
10 11 12 |
# File 'lib/arrolio/flow_context.rb', line 10 def citations @citations end |
#heading_entries ⇒ Object (readonly)
Returns the value of attribute heading_entries.
10 11 12 |
# File 'lib/arrolio/flow_context.rb', line 10 def heading_entries @heading_entries end |
#layout_spec ⇒ Object (readonly)
Returns the value of attribute layout_spec.
10 11 12 |
# File 'lib/arrolio/flow_context.rb', line 10 def layout_spec @layout_spec end |
#page_count ⇒ Object
Returns the value of attribute page_count.
9 10 11 |
# File 'lib/arrolio/flow_context.rb', line 9 def page_count @page_count end |
#page_number ⇒ Object
Returns the value of attribute page_number.
9 10 11 |
# File 'lib/arrolio/flow_context.rb', line 9 def page_number @page_number end |
#renderer ⇒ Object
Returns the value of attribute renderer.
9 10 11 |
# File 'lib/arrolio/flow_context.rb', line 9 def renderer @renderer end |
Instance Method Details
#citation_for(ref_id) ⇒ Object
20 21 22 |
# File 'lib/arrolio/flow_context.rb', line 20 def citation_for(ref_id) @citations[ref_id.to_s] end |
#record_citation(ref_id, page_number) ⇒ Object
24 25 26 |
# File 'lib/arrolio/flow_context.rb', line 24 def record_citation(ref_id, page_number) @citations[ref_id.to_s] ||= page_number end |
#record_heading(number:, title:, level:, page_number:, id: nil) ⇒ Object
28 29 30 31 |
# File 'lib/arrolio/flow_context.rb', line 28 def record_heading(number:, title:, level:, page_number:, id: nil) @heading_entries << { number: number, title: title, level: level, page_number: page_number, id: id } end |
#total_pages ⇒ Object
33 34 35 |
# File 'lib/arrolio/flow_context.rb', line 33 def total_pages @page_count end |