Class: WeatherLink::SensorData

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/weatherlink/sensor_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, sensor_data) ⇒ SensorData

Returns a new instance of SensorData.



9
10
11
12
13
14
15
16
# File 'lib/weatherlink/sensor_data.rb', line 9

def initialize(client, sensor_data)
  @client = client
  @sensor_data = HashWrapper.new(sensor_data)
  @records = @sensor_data['data'].map do |data|
    SensorRecord.new(client, client.attach_units(data))
  end
  super(@records.first)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/weatherlink/sensor_data.rb', line 7

def client
  @client
end

#recordsObject (readonly)

Returns the value of attribute records.



7
8
9
# File 'lib/weatherlink/sensor_data.rb', line 7

def records
  @records
end

#sensor_dataObject (readonly)

Returns the value of attribute sensor_data.



7
8
9
# File 'lib/weatherlink/sensor_data.rb', line 7

def sensor_data
  @sensor_data
end

Instance Method Details

#archive?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/weatherlink/sensor_data.rb', line 50

def archive?
  record_type.archive?
end

#current_conditions?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/weatherlink/sensor_data.rb', line 46

def current_conditions?
  record_type.current_conditions?
end

#descriptionObject



58
59
60
# File 'lib/weatherlink/sensor_data.rb', line 58

def description
  record_type.description
end

#health?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/weatherlink/sensor_data.rb', line 42

def health?
  record_type.health?
end

#inspectObject



22
23
24
# File 'lib/weatherlink/sensor_data.rb', line 22

def inspect
  to_s
end

#lsidObject



26
27
28
# File 'lib/weatherlink/sensor_data.rb', line 26

def lsid
  sensor_data.lsid
end

#record_typeObject



38
39
40
# File 'lib/weatherlink/sensor_data.rb', line 38

def record_type
  @record_type ||= client.api.class.record_type(sensor_data.data_structure_type)
end

#sensorObject



30
31
32
# File 'lib/weatherlink/sensor_data.rb', line 30

def sensor
  @sensor ||= @client.sensors.select { |sensor| sensor.lsid == lsid }.first
end

#sensor_typeObject



34
35
36
# File 'lib/weatherlink/sensor_data.rb', line 34

def sensor_type
  sensor_data.sensor_type
end

#to_sObject



18
19
20
# File 'lib/weatherlink/sensor_data.rb', line 18

def to_s
  "#<#{self.class.name} lsid=#{lsid} (#{record_type.description}, #{records.size} records)>"
end

#weather?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/weatherlink/sensor_data.rb', line 54

def weather?
  record_type.current_conditions? || record_type.archive?
end