Class: MultiMovingsign::Signs

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

Overview

Represents a collection of Signs that you want to drive in unison

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Signs

Returns a new instance of Signs.

Parameters:



9
10
11
12
13
14
15
# File 'lib/multi_movingsign/signs.rb', line 9

def initialize(options)
  if options.kind_of?(Array) && options.all? { |v| v.kind_of?(Sign) }
    self.signs = options
  else
    raise InvalidInputError, "Invalid Signs#new options"
  end
end

Instance Attribute Details

#signsObject

Returns the value of attribute signs.



6
7
8
# File 'lib/multi_movingsign/signs.rb', line 6

def signs
  @signs
end

Instance Method Details

#lengthObject



35
36
37
# File 'lib/multi_movingsign/signs.rb', line 35

def length
  self.signs.length
end

#show_identityObject



31
32
33
# File 'lib/multi_movingsign/signs.rb', line 31

def show_identity
  self.signs.each_with_index { |s, i| s.show_text "#{i} #{s.path}" }
end

#show_page_solution(solution) ⇒ Object

Sends/show the specified page solution on the signs



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/multi_movingsign/signs.rb', line 18

def show_page_solution(solution)
  threads = []
  solution['signs'].each_with_index do |hash, i|
    threads << Thread.new do
      # Prepend "\xFDB" to set color to HIGH RED
      # .gsub("\n", "\x7F") - replace new lines with the sign specific newline character
      text = "\xFDB" + hash['content'].gsub("\n", "\x7F")
      self.signs[i].show_text text, :display_pause => 3
    end
  end
  threads.each { |t| t.join }
end