Class: AMON::Device

Inherits:
Document show all
Defined in:
lib/amon/device.rb

Overview

An AMON device, containing any number of readings, and measurements for those readings.

Instance Attribute Summary

Attributes inherited from Document

#session

Attributes included from JSONHelper

#json

Instance Method Summary collapse

Methods inherited from Document

#==, #initialize

Constructor Details

This class inherits a constructor from AMON::Document

Instance Method Details

#customer_refString

Returns The metadata “customer_ref” field; convenience method.

Returns:

  • (String)

    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

#descriptionString

Returns The description for the device.

Returns:

  • (String)

    The description for the device



25
26
27
# File 'lib/amon/device.rb', line 25

def description
  @description ||= json['description']
end

#earliest_measurementTime

Returns The latest measurement start date, if provided.

Returns:

  • (Time)

    The latest measurement start date, if provided



9
# File 'lib/amon/device.rb', line 9

field :earliest_measurement, :name => 'earliestMeasurement', :as => Time

#idString

Returns The id of the device.

Returns:

  • (String)

    The id of the device



6
# File 'lib/amon/device.rb', line 6

field :id, :name => 'deviceId'

#latest_measurementTime

Returns The latest measurement start date, if provided.

Returns:

  • (Time)

    The latest measurement start date, if provided



12
# File 'lib/amon/device.rb', line 12

field :latest_measurement, :name => 'latestMeasurement', :as => Time

#location_nameString

Returns The location for the device.

Returns:

  • (String)

    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.

Returns:

  • (Array<Measurement>)

    Measurements for this device

See Also:



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.

Returns:

See Also:



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

#metadataMetadata

Returns The metadata for the device.

Returns:

  • (Metadata)

    The metadata for the device



35
36
37
# File 'lib/amon/device.rb', line 35

def 
  @metadata ||= Metadata.new(self, json['metadata'])
end

#parent_uuidString

Returns The deviceId for the device’s parent device.

Returns:

  • (String)

    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

#readingsArray<Reading>

Returns The readings for the device.

Returns:

  • (Array<Reading>)

    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_typeHash<String => Reading>

Returns A hash allowing #readings to be retrieved by their Reading#type.

Returns:



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

#uuidString

Returns The deviceId for the device.

Returns:

  • (String)

    The deviceId for the device



15
16
17
# File 'lib/amon/device.rb', line 15

def uuid
  @uuid ||= json['deviceId']
end