Class: CanControlsGateway::Dispatcher
- Inherits:
-
Object
- Object
- CanControlsGateway::Dispatcher
- Defined in:
- lib/dispatcher.rb
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#raw_data ⇒ Object
readonly
Returns the value of attribute raw_data.
-
#station_id ⇒ Object
readonly
Returns the value of attribute station_id.
Instance Method Summary collapse
- #dispatch_rca ⇒ Object
-
#initialize(data) ⇒ Dispatcher
constructor
A new instance of Dispatcher.
Constructor Details
#initialize(data) ⇒ Dispatcher
Returns a new instance of Dispatcher.
14 15 16 17 18 19 20 |
# File 'lib/dispatcher.rb', line 14 def initialize data # TODO remove REXML usage - REXML is horribly slow @raw_data = REXML::Document.new("#{data}") @events = get_raw_events @station_id = REXML::XPath.first(@raw_data, "/trackingdata/attribute::station_id") @station_id = @station_id.value if @station_id end |
Instance Attribute Details
#events ⇒ Object (readonly)
Returns the value of attribute events.
12 13 14 |
# File 'lib/dispatcher.rb', line 12 def events @events end |
#raw_data ⇒ Object (readonly)
Returns the value of attribute raw_data.
12 13 14 |
# File 'lib/dispatcher.rb', line 12 def raw_data @raw_data end |
#station_id ⇒ Object (readonly)
Returns the value of attribute station_id.
12 13 14 |
# File 'lib/dispatcher.rb', line 12 def station_id @station_id end |
Instance Method Details
#dispatch_rca ⇒ Object
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 48 49 50 51 52 |
# File 'lib/dispatcher.rb', line 22 def dispatch_rca my_station = STATIONS[@station_id] # Do we know this station? if my_station @events.each do |event| # If it is a RCA mappable event send it as RCA command... if EVENTS[event.event_type] if my_station['rci_uri'] my_args = { 'action' => EVENTS[event.event_type] } Ccg.logger.info "Dispatcher: sending command : rci_uri: #{my_station['rci_uri']}, target: #{my_station['target']}, args: #{my_args.inspect}" my_command = CanControlsGateway::RcaCommand.new my_station['rci_uri'], my_station['target'], my_args Ccg.logger.info my_command.send_command else Ccg.logger.info "Device '#{my_station['device']}' not properly initialized in gom? (sender: station #{station})" end else # ???? end end else # ???? end rescue => e "ERROR: #{e.backtrace.join "\n\t"}" end |