Class: DeviceMap::DeviceData::Devices
- Inherits:
-
Object
- Object
- DeviceMap::DeviceData::Devices
- Defined in:
- lib/device_map/device_data/devices.rb
Defined Under Namespace
Classes: DeviceNotFound
Class Method Summary collapse
Instance Method Summary collapse
- #find(device_id) ⇒ Object
-
#initialize(devices) ⇒ Devices
constructor
A new instance of Devices.
Constructor Details
#initialize(devices) ⇒ Devices
Returns a new instance of Devices.
15 16 17 18 19 |
# File 'lib/device_map/device_data/devices.rb', line 15 def initialize(devices) @device_index = devices.each_with_object({}) do |device, device_index| device_index[device.id] = device end end |
Class Method Details
.parse(devices_xml) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/device_map/device_data/devices.rb', line 6 def self.parse(devices_xml) devices_doc = Nokogiri::XML(devices_xml) devices = devices_doc.xpath('//device').map do |device_node| Device.parse(device_node) end new(devices) end |
Instance Method Details
#find(device_id) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/device_map/device_data/devices.rb', line 21 def find(device_id) # TODO: Return copy of <tt>Device</tt> object @device_index.fetch(device_id) do fail DeviceNotFound, "Cound not find device: #{device_id}" end end |