Class: Arrolio::Output::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/arrolio/output/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number:, template_name:, page_size:, regions:, static_regions: {}, template_role: :body, header_text: nil, footer_text: nil, header_align: :right, footer_align: :center, footnotes: []) ⇒ Page

Returns a new instance of Page.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/arrolio/output/page.rb', line 10

def initialize(number:, template_name:, page_size:,
               regions:, static_regions: {}, template_role: :body,
               header_text: nil, footer_text: nil,
               header_align: :right, footer_align: :center,
               footnotes: [])
  @number = number.to_i
  @template_name = template_name.to_sym
  @template_role = template_role.to_sym
  @page_size = [page_size[0].to_f, page_size[1].to_f].freeze
  @regions = regions.transform_keys(&:to_sym).freeze
  @static_regions = static_regions.transform_keys(&:to_sym).freeze
  @header_text = header_text
  @footer_text = footer_text
  @header_align = header_align.to_sym
  @footer_align = footer_align.to_sym
  @footnotes = Array(footnotes).freeze
  freeze
end

Instance Attribute Details

Returns the value of attribute footer_align.



6
7
8
# File 'lib/arrolio/output/page.rb', line 6

def footer_align
  @footer_align
end

Returns the value of attribute footer_text.



6
7
8
# File 'lib/arrolio/output/page.rb', line 6

def footer_text
  @footer_text
end

#footnotesObject (readonly)

Returns the value of attribute footnotes.



6
7
8
# File 'lib/arrolio/output/page.rb', line 6

def footnotes
  @footnotes
end

#header_alignObject (readonly)

Returns the value of attribute header_align.



6
7
8
# File 'lib/arrolio/output/page.rb', line 6

def header_align
  @header_align
end

#header_textObject (readonly)

Returns the value of attribute header_text.



6
7
8
# File 'lib/arrolio/output/page.rb', line 6

def header_text
  @header_text
end

#numberObject (readonly)

Returns the value of attribute number.



6
7
8
# File 'lib/arrolio/output/page.rb', line 6

def number
  @number
end

#page_sizeObject (readonly)

Returns the value of attribute page_size.



6
7
8
# File 'lib/arrolio/output/page.rb', line 6

def page_size
  @page_size
end

#regionsObject (readonly)

Returns the value of attribute regions.



6
7
8
# File 'lib/arrolio/output/page.rb', line 6

def regions
  @regions
end

#static_regionsObject (readonly)

Returns the value of attribute static_regions.



6
7
8
# File 'lib/arrolio/output/page.rb', line 6

def static_regions
  @static_regions
end

#template_nameObject (readonly)

Returns the value of attribute template_name.



6
7
8
# File 'lib/arrolio/output/page.rb', line 6

def template_name
  @template_name
end

#template_roleObject (readonly)

Returns the value of attribute template_role.



6
7
8
# File 'lib/arrolio/output/page.rb', line 6

def template_role
  @template_role
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/arrolio/output/page.rb', line 48

def ==(other)
  other.is_a?(self.class) &&
    number == other.number &&
    template_name == other.template_name &&
    template_role == other.template_role &&
    page_size == other.page_size &&
    regions == other.regions &&
    static_regions == other.static_regions &&
    header_text == other.header_text &&
    footer_text == other.footer_text &&
    footnotes == other.footnotes
end

#body_regionObject



29
30
31
# File 'lib/arrolio/output/page.rb', line 29

def body_region
  @regions[:body]
end

#each_box(&block) ⇒ Object



41
42
43
44
45
46
# File 'lib/arrolio/output/page.rb', line 41

def each_box(&block)
  return enum_for(:each_box) unless block_given?

  @static_regions.each_value { |r| r.placed_boxes.each(&block) }
  @regions.each_value { |r| r.placed_boxes.each(&block) }
end

#hashObject



63
64
65
66
# File 'lib/arrolio/output/page.rb', line 63

def hash
  [self.class, number, template_name, template_role, page_size,
   regions, static_regions, header_text, footer_text, footnotes].hash
end

#heightObject



37
38
39
# File 'lib/arrolio/output/page.rb', line 37

def height
  @page_size[1]
end

#widthObject



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

def width
  @page_size[0]
end