Class: OneWire::Device
Instance Method Summary collapse
- #dir ⇒ Object
-
#initialize(address, options = {}) ⇒ Device
constructor
A new instance of Device.
- #present? ⇒ Boolean
- #read(attribute) ⇒ Object
- #write(attribute, value) ⇒ Object
Methods included from Retry
Constructor Details
#initialize(address, options = {}) ⇒ Device
Returns a new instance of Device.
5 6 7 8 9 |
# File 'lib/one_wire/device.rb', line 5 def initialize(address, = {}) = @path = [:uncached] ? "/uncached/#{address}" : "/#{address}" @path.squeeze!("/") end |
Instance Method Details
#dir ⇒ Object
26 27 28 |
# File 'lib/one_wire/device.rb', line 26 def dir Directory.new(@path) end |
#present? ⇒ Boolean
11 12 13 14 15 16 |
# File 'lib/one_wire/device.rb', line 11 def present? Transaction.presence(@path, ) true rescue Errno::ENOENT false end |
#read(attribute) ⇒ Object
18 19 20 |
# File 'lib/one_wire/device.rb', line 18 def read(attribute) with_retry { Transaction.read("#{@path}/#{attribute}").response.data || raise(BadRead) } end |
#write(attribute, value) ⇒ Object
22 23 24 |
# File 'lib/one_wire/device.rb', line 22 def write(attribute, value) with_retry { Transaction.write("#{@path}/#{attribute}", value) } end |