Class: MultiMovingsign::PageDefinition
- Inherits:
-
Object
- Object
- MultiMovingsign::PageDefinition
- Defined in:
- lib/multi_movingsign/page_renderer.rb
Instance Attribute Summary collapse
-
#line_definitions ⇒ Object
Returns the value of attribute line_definitions.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
-
#calculate_segments(signs, options = {}) ⇒ Object
Splits a PageDefinition into an array of PageSegments.
Instance Attribute Details
#line_definitions ⇒ Object
Returns the value of attribute line_definitions.
62 63 64 |
# File 'lib/multi_movingsign/page_renderer.rb', line 62 def line_definitions @line_definitions end |
#title ⇒ Object
Returns the value of attribute title.
61 62 63 |
# File 'lib/multi_movingsign/page_renderer.rb', line 61 def title @title end |
Class Method Details
.from_hash(hash) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/multi_movingsign/page_renderer.rb', line 64 def self.from_hash(hash) obj = self.new obj.title = hash['title'] || '' obj.line_definitions = hash['lines'].map { |ld| LineDefinition.from_hash ld } obj end |
Instance Method Details
#calculate_segments(signs, options = {}) ⇒ Object
Splits a MultiMovingsign::PageDefinition into an array of MultiMovingsign::PageSegments
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/multi_movingsign/page_renderer.rb', line 78 def calculate_segments(signs, = {}) pin_title = signs > 1 && ([:pin_title] != false) page_segments = [] line_definitions = self.line_definitions.clone.reverse index = 0 while !line_definitions.empty? include_title = pin_title || index == 0 # include the title in this line segment? line_count = include_title ? signs - 1 : signs # number of line definitions to include in this page segment (less the title if included) page_segments << PageSegment.new(include_title ? self.title : nil, line_definitions.pop(line_count).reverse) index += 1 end page_segments end |