Sha256: 98998e758e0a856c92d880cc69d6b80dcf77e71dfcf36263e85c2c60bbfd6535
Contents?: true
Size: 689 Bytes
Versions: 1
Compression:
Stored size: 689 Bytes
Contents
module DeviceMap module DeviceData class Devices class DeviceNotFound < StandardError; end 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 def initialize(devices) @device_index = devices.each_with_object({}) do |device, device_index| device_index[device.id] = device end end def find(device_id) @device_index.fetch(device_id) do fail DeviceNotFound, "Cound not find device: #{device_id}" end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
device_map-0.1.2 | lib/device_map/device_data/devices.rb |