Class: Arrolio::FlowContext

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#citationsObject (readonly)

Returns the value of attribute citations.



10
11
12
# File 'lib/arrolio/flow_context.rb', line 10

def citations
  @citations
end

#heading_entriesObject (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_specObject (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_countObject

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_numberObject

Returns the value of attribute page_number.



9
10
11
# File 'lib/arrolio/flow_context.rb', line 9

def page_number
  @page_number
end

#rendererObject

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_pagesObject



33
34
35
# File 'lib/arrolio/flow_context.rb', line 33

def total_pages
  @page_count
end