Class: MiOS::Device
- Inherits:
-
Object
- Object
- MiOS::Device
- Defined in:
- lib/mios/device.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#base_uri ⇒ Object
readonly
Returns the value of attribute base_uri.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#initialize(client, base_uri, data) ⇒ Device
constructor
A new instance of Device.
- #inspect ⇒ Object
- #method_missing(method, *args) ⇒ Object
- #reload ⇒ Object
Constructor Details
#initialize(client, base_uri, data) ⇒ Device
Returns a new instance of Device.
5 6 7 8 |
# File 'lib/mios/device.rb', line 5 def initialize(client, base_uri, data) @client, @base_uri = client, base_uri parse(data) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/mios/device.rb', line 14 def method_missing(method, *args) if @attributes.has_key?(method.to_s) @attributes[method.to_s] else super end end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
3 4 5 |
# File 'lib/mios/device.rb', line 3 def attributes @attributes end |
#base_uri ⇒ Object (readonly)
Returns the value of attribute base_uri.
3 4 5 |
# File 'lib/mios/device.rb', line 3 def base_uri @base_uri end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
3 4 5 |
# File 'lib/mios/device.rb', line 3 def client @client end |
Instance Method Details
#inspect ⇒ Object
10 11 12 |
# File 'lib/mios/device.rb', line 10 def inspect "#<MiOS::Device:0x#{'%x' % (self.object_id << 1)} name=#{@attributes['name']}>" end |
#reload ⇒ Object
22 23 24 25 26 |
# File 'lib/mios/device.rb', line 22 def reload parse(MultiJson.load(@client.get("#{@base_uri}/data_request", {:id => 'status', :DeviceNum => attributes['id'], :output_format => :json}).content)["Device_Num_#{attributes['id']}"], true) self end |