Class: MultiMovingsign::PageDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/multi_movingsign/page_renderer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#line_definitionsObject

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

#titleObject

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

Parameters:

  • signs (Integer)

    the number of signs (lines) available to render to

  • options (Hash) (defaults to: {})

Options Hash (options):

  • +:pin_title+ (Boolean)


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, options = {})
  pin_title = signs > 1 && (options[: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