class MultiMovingsign::PageDefinition

Attributes

line_definitions[RW]
title[RW]

Public Class Methods

from_hash(hash) click to toggle source
# 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

Public Instance Methods

calculate_segments(signs, options = {}) click to toggle source

Splits a {PageDefinition} into an array of {PageSegment}s

@param signs [Integer] the number of signs (lines) available to render to @param options [Hash] @option options [Boolean] :pin_title

# 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