Class: AMON::Device
Overview
An AMON device, containing any number of readings, and measurements for those readings.
Instance Attribute Summary
Attributes inherited from Document
Attributes included from JSONHelper
Instance Method Summary collapse
-
#customer_ref ⇒ String
The metadata “customer_ref” field; convenience method.
-
#description ⇒ String
The description for the device.
-
#earliest_measurement ⇒ Time
The latest measurement start date, if provided.
-
#id ⇒ String
The id of the device.
-
#latest_measurement ⇒ Time
The latest measurement start date, if provided.
-
#location_name ⇒ String
The location for the device.
-
#measurements(entity_id, start_date, end_date, raw = false) ⇒ Array<Measurement>
Measurements for this device.
-
#measurements_by_name(entity_id, start_date, end_date, raw = false) ⇒ Hash<String => Measurement>
A hash allowing #measurements to be retrieved by their Measurement#name.
-
#metadata ⇒ Metadata
The metadata for the device.
-
#parent_uuid ⇒ String
The deviceId for the device’s parent device.
-
#readings ⇒ Array<Reading>
The readings for the device.
-
#readings_by_type ⇒ Hash<String => Reading>
A hash allowing #readings to be retrieved by their Reading#type.
-
#uuid ⇒ String
The deviceId for the device.
Methods inherited from Document
Constructor Details
This class inherits a constructor from AMON::Document
Instance Method Details
#customer_ref ⇒ String
Returns The metadata “customer_ref” field; convenience method.
40 41 42 |
# File 'lib/amon/device.rb', line 40 def customer_ref @customer_ref ||= .customer_ref end |
#description ⇒ String
Returns The description for the device.
25 26 27 |
# File 'lib/amon/device.rb', line 25 def description @description ||= json['description'] end |
#earliest_measurement ⇒ Time
Returns The latest measurement start date, if provided.
9 |
# File 'lib/amon/device.rb', line 9 field :earliest_measurement, :name => 'earliestMeasurement', :as => Time |
#id ⇒ String
Returns The id of the device.
6 |
# File 'lib/amon/device.rb', line 6 field :id, :name => 'deviceId' |
#latest_measurement ⇒ Time
Returns The latest measurement start date, if provided.
12 |
# File 'lib/amon/device.rb', line 12 field :latest_measurement, :name => 'latestMeasurement', :as => Time |
#location_name ⇒ String
Returns The location for the device.
30 31 32 |
# File 'lib/amon/device.rb', line 30 def location_name @location_name ||= json['location']['name'] end |
#measurements(entity_id, start_date, end_date, raw = false) ⇒ Array<Measurement>
Returns Measurements for this device.
60 61 62 |
# File 'lib/amon/device.rb', line 60 def measurements(entity_id, start_date, end_date, raw = false) session.measurements(entity_id, id, start_date, end_date, raw) end |
#measurements_by_name(entity_id, start_date, end_date, raw = false) ⇒ Hash<String => Measurement>
Returns A hash allowing #measurements to be retrieved by their Measurement#name.
69 70 71 72 73 74 75 |
# File 'lib/amon/device.rb', line 69 def measurements_by_name(entity_id, start_date, end_date, raw = false) measurements(entity_id, start_date, end_date, raw).inject({}) do |measurements_by_name, measurement| measurements_by_name[measurement.name] ||= [] measurements_by_name[measurement.name] << measurement measurements_by_name end end |
#metadata ⇒ Metadata
Returns The metadata for the device.
35 36 37 |
# File 'lib/amon/device.rb', line 35 def @metadata ||= Metadata.new(self, json['metadata']) end |
#parent_uuid ⇒ String
Returns The deviceId for the device’s parent device.
20 21 22 |
# File 'lib/amon/device.rb', line 20 def parent_uuid @parent_uuid ||= json['parentId'] end |
#readings ⇒ Array<Reading>
Returns The readings for the device.
45 46 47 |
# File 'lib/amon/device.rb', line 45 def readings @readings ||= json['readings'].map { |reading| Reading.new(self, reading) } end |
#readings_by_type ⇒ Hash<String => Reading>
Returns A hash allowing #readings to be retrieved by their Reading#type.
51 52 53 54 55 56 |
# File 'lib/amon/device.rb', line 51 def readings_by_type readings.inject({}) do |readings_by_type, reading| readings_by_type[reading.type] = reading readings_by_type end end |
#uuid ⇒ String
Returns The deviceId for the device.
15 16 17 |
# File 'lib/amon/device.rb', line 15 def uuid @uuid ||= json['deviceId'] end |