Class: MultiMovingsign::PageRenderer
- Inherits:
-
Object
- Object
- MultiMovingsign::PageRenderer
- Defined in:
- lib/multi_movingsign/page_renderer.rb
Overview
Renders a page definition (Hash/YAML) into something that is easily displayable by the MovingsignApi (page solution)
Constant Summary collapse
- DEFAULT_CHARACTER_WIDTH =
5
Instance Method Summary collapse
-
#render(page, options = {}) ⇒ Hash
A page solution hash.
Instance Method Details
#render(page, options = {}) ⇒ Hash
Returns a page solution hash.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/multi_movingsign/page_renderer.rb', line 11 def render(page, = {}) # Vocabulary - Terms used here # # Sign # A single LED sign, stacked vertically with other LED signs...together forming a screen # Screen # N LED signs stacked vertically. Together they can display a screen of information at a time # Page Definition # A page of information to be broken up and displayed on available signs, consisting of a title and n Line Definitions. # Line Definition # A line of information from the page definition. NOTE: a single line might turn into multiple screens of information # Line Segment # A piece of a line definition, displayed on it's own sign, seprate from previous line segments of the same line. # signs_available = ([:count] || 1) page_title = page['title'] line_definitions = page['lines'] pin_title = signs_available > 1 page_definition = PageDefinition.from_hash page page_segments = page_definition.calculate_segments(signs_available) screens = page_segments.map { |s| s.calculate_screens(signs_available, screen_width) }.flatten ## Preview Solution #screens.each do |screen| # puts "----" # (0..(signs_available-1)).each do |i| # puts screen.line(i) # end #end #puts "----" signs = (0..(signs_available-1)).map { |sign_index| {'content' => screens.map { |s| s.line(sign_index) }.join("\n")} } {'signs' => signs, 'lines' => screens.length} end |