Class: MetaBridge::Device
- Inherits:
-
Object
- Object
- MetaBridge::Device
- Defined in:
- lib/meta_bridge/device.rb
Constant Summary collapse
- DEFAULT_IP =
'0.0.0.0'- DEFAULT_MAC =
'00:00:00:00:00:00'- ONLINE_STATE =
'device'.freeze
Instance Attribute Summary collapse
-
#bridge ⇒ Object
readonly
Returns the value of attribute bridge.
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#mac ⇒ Object
readonly
Returns the value of attribute mac.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(hsh = {}) ⇒ Device
constructor
A new instance of Device.
- #log ⇒ Object
- #online? ⇒ Boolean
Constructor Details
#initialize(hsh = {}) ⇒ Device
Returns a new instance of Device.
27 28 29 30 31 32 33 34 |
# File 'lib/meta_bridge/device.rb', line 27 def initialize(hsh = {}) @ip = hsh[:ip] || MetaBridge::Device::DEFAULT_IP @mac = hsh[:mac] || MetaBridge::Device::DEFAULT_MAC @port = hsh[:port] || MetaBridge::DEFAULT_PORT @bridge = hsh[:bridge] || MetaBridge::Bridge.new @bridge.device_id = "#{ip}:#{port}" end |
Instance Attribute Details
#bridge ⇒ Object (readonly)
Returns the value of attribute bridge.
13 14 15 |
# File 'lib/meta_bridge/device.rb', line 13 def bridge @bridge end |
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
10 11 12 |
# File 'lib/meta_bridge/device.rb', line 10 def ip @ip end |
#mac ⇒ Object (readonly)
Returns the value of attribute mac.
11 12 13 |
# File 'lib/meta_bridge/device.rb', line 11 def mac @mac end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
12 13 14 |
# File 'lib/meta_bridge/device.rb', line 12 def port @port end |
Class Method Details
.all(opts = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/meta_bridge/device.rb', line 16 def all(opts = {}) proxy = opts.delete(:proxy) || MetaBridge::ARP.new devices = proxy.connections.map do |con| MetaBridge::Device.new(con.merge(opts)) end devices.select { |d| d.online? } end |
Instance Method Details
#log ⇒ Object
40 41 42 |
# File 'lib/meta_bridge/device.rb', line 40 def log bridge.logcat end |
#online? ⇒ Boolean
36 37 38 |
# File 'lib/meta_bridge/device.rb', line 36 def online? bridge.get_state == ONLINE_STATE end |