Class: X::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/rfid-usb-gom-sensor/node.rb

Direct Known Subclasses

Attribute, Node

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = nil) ⇒ Entry

Returns a new instance of Entry.



11
12
13
# File 'lib/rfid-usb-gom-sensor/node.rb', line 11

def initialize data = nil
  @data = data
end

Instance Attribute Details

#mtimeObject

Returns the value of attribute mtime.



10
11
12
# File 'lib/rfid-usb-gom-sensor/node.rb', line 10

def mtime
  @mtime
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/rfid-usb-gom-sensor/node.rb', line 10

def name
  @name
end

#pathObject

Returns the value of attribute path.



10
11
12
# File 'lib/rfid-usb-gom-sensor/node.rb', line 10

def path
  @path
end

Class Method Details

.find(path, recurse = 0) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rfid-usb-gom-sensor/node.rb', line 31

def self.find path, recurse = 0
  json = (Gom::Remote.connection.read "#{path}.json")
  clazz, key = /:/.match(path) ? [Attribute, "attribute"] : [Node, "node"]
  a = clazz.new JSON.parse(json)[key]
  a
=begin
  json = (connection.read "#{path}.json")
  (JSON.parse json)["node"]["entries"].select do |entry|
    # 1. select attribute entries
    entry.has_key? "attribute"
  end.inject({}) do |h, a|
      # 2. make it a key, value list
      h[a["attribute"]["name"].to_sym] = a["attribute"]["value"]
      h
  end
=end
end

Instance Method Details

#to_sObject



27
28
29
# File 'lib/rfid-usb-gom-sensor/node.rb', line 27

def to_s
  "name: #{name}\npath: #{path}\nmtime: #{mtime}"
end