Class: DeviceCloud::DataPoint

Inherits:
Object
  • Object
show all
Defined in:
lib/device_cloud/data_point.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element) ⇒ DataPoint

Returns a new instance of DataPoint.



14
15
16
17
18
19
20
# File 'lib/device_cloud/data_point.rb', line 14

def initialize(element)
  @id = element.xpath("id").text
  @value = element.xpath("data").text
  @timestamp = Time.at(element.xpath("timestamp").text.to_f / 1000)
  @server_timestamp = Time.at(element.xpath("serverTimestamp").text.to_f / 1000)
  @stream_id = element.xpath("streamId").text
end

Instance Attribute Details

#elementObject

Returns the value of attribute element.



12
13
14
# File 'lib/device_cloud/data_point.rb', line 12

def element
  @element
end

#idObject

Returns the value of attribute id.



12
13
14
# File 'lib/device_cloud/data_point.rb', line 12

def id
  @id
end

#server_timestampObject

Returns the value of attribute server_timestamp.



12
13
14
# File 'lib/device_cloud/data_point.rb', line 12

def server_timestamp
  @server_timestamp
end

#stream_idObject

Returns the value of attribute stream_id.



12
13
14
# File 'lib/device_cloud/data_point.rb', line 12

def stream_id
  @stream_id
end

#timestampObject

Returns the value of attribute timestamp.



12
13
14
# File 'lib/device_cloud/data_point.rb', line 12

def timestamp
  @timestamp
end

#valueObject

Returns the value of attribute value.



12
13
14
# File 'lib/device_cloud/data_point.rb', line 12

def value
  @value
end

Class Method Details

.parse(xml) ⇒ Object



5
6
7
8
9
10
# File 'lib/device_cloud/data_point.rb', line 5

def self.parse(xml)
  result = Result.new(xml)
  result.document.xpath("//result/DataPoint").map do |data_point|
    DeviceCloud::DataPoint.new data_point
  end
end