Class: DeviceCloud::DataStream

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

Constant Summary collapse

RESOURCE_PATH =
'/ws/DataStream'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(element) ⇒ DataStream

Returns a new instance of DataStream.



15
16
17
# File 'lib/device_cloud/data_stream.rb', line 15

def initialize(element)
  @element = element
end

Instance Attribute Details

#elementObject

Returns the value of attribute element.



13
14
15
# File 'lib/device_cloud/data_stream.rb', line 13

def element
  @element
end

Class Method Details

.parse(xml) ⇒ Object



6
7
8
9
10
11
# File 'lib/device_cloud/data_stream.rb', line 6

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

Instance Method Details

#current_idObject



31
32
33
# File 'lib/device_cloud/data_stream.rb', line 31

def current_id
  current.id
end

#delete(client) ⇒ Object



19
20
21
# File 'lib/device_cloud/data_stream.rb', line 19

def delete(client)
  client.delete RESOURCE_PATH + "/" + stream_id
end

#device_idObject



39
40
41
# File 'lib/device_cloud/data_stream.rb', line 39

def device_id
  stream_id_parse[1]
end

#device_pathObject



55
56
57
# File 'lib/device_cloud/data_stream.rb', line 55

def device_path
  "dia/channel/#{device_id}/#{mac.to_s(16).rjust(16,"0")}/"
end

#macObject



43
44
45
# File 'lib/device_cloud/data_stream.rb', line 43

def mac
  path.to_i(16)
end

#nameObject



51
52
53
# File 'lib/device_cloud/data_stream.rb', line 51

def name
  stream_id_parse[3]
end

#pathObject



47
48
49
# File 'lib/device_cloud/data_stream.rb', line 47

def path
  stream_id_parse[2]
end

#stream_idObject



35
36
37
# File 'lib/device_cloud/data_stream.rb', line 35

def stream_id
  element.xpath("streamId").text
end

#timestampObject



27
28
29
# File 'lib/device_cloud/data_stream.rb', line 27

def timestamp
  current.timestamp
end

#valueObject



23
24
25
# File 'lib/device_cloud/data_stream.rb', line 23

def value
  current.value
end