Class: MultiMovingsign::Signs
- Inherits:
-
Object
- Object
- MultiMovingsign::Signs
- Defined in:
- lib/multi_movingsign/signs.rb
Overview
Represents a collection of Signs that you want to drive in unison
Instance Attribute Summary collapse
-
#signs ⇒ Object
Returns the value of attribute signs.
Instance Method Summary collapse
-
#initialize(options) ⇒ Signs
constructor
A new instance of Signs.
- #length ⇒ Object
- #show_identity ⇒ Object
-
#show_page_solution(solution) ⇒ Object
Sends/show the specified page solution on the signs.
Constructor Details
#initialize(options) ⇒ Signs
Returns a new instance of Signs.
9 10 11 12 13 14 15 |
# File 'lib/multi_movingsign/signs.rb', line 9 def initialize() if .kind_of?(Array) && .all? { |v| v.kind_of?(Sign) } self.signs = else raise InvalidInputError, "Invalid Signs#new options" end end |
Instance Attribute Details
#signs ⇒ Object
Returns the value of attribute signs.
6 7 8 |
# File 'lib/multi_movingsign/signs.rb', line 6 def signs @signs end |
Instance Method Details
#length ⇒ Object
35 36 37 |
# File 'lib/multi_movingsign/signs.rb', line 35 def length self.signs.length end |
#show_identity ⇒ Object
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 |