class MultiMovingsign::Signs

Represents a collection of {Sign}s that you want to drive in unison

Attributes

signs[RW]

Public Class Methods

new(options) click to toggle source

@param options [Array<Sign>] an array of {Sign} instances

# 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

Public Instance Methods

length() click to toggle source
# File lib/multi_movingsign/signs.rb, line 35
def length
  self.signs.length
end
show_identity() click to toggle source
# 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) click to toggle source

Sends/show the specified page solution on the signs

# 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