Module: OneWire
- Defined in:
- lib/one_wire.rb,
lib/one_wire/base.rb,
lib/one_wire/thermometer.rb
Defined Under Namespace
Classes: Base, Thermometer
Class Method Summary collapse
-
.all(&block) ⇒ Object
def find query, &block devices = slaves.keep_if { |v| v =~ query } devices = devices.collect { |path| load(path) } devices.each &block if block_given? devices end.
- .devices ⇒ Object
- .find(query) ⇒ Object
-
.load(path) ⇒ Object
def find_by_name end.
- .slaves(&block) ⇒ Object
Class Method Details
.all(&block) ⇒ Object
def find query, &block
devices = slaves.keep_if { |v| v =~ query }
devices = devices.collect { |path| load(path) }
devices.each &block if block_given?
devices
end
22 23 24 25 26 |
# File 'lib/one_wire.rb', line 22 def all &block devices = slaves.collect { |path| load(path) rescue nil }.compact devices.each &block if block_given? devices end |
.devices ⇒ Object
46 47 48 |
# File 'lib/one_wire.rb', line 46 def devices slaves.collect { |path| load(path) } end |
.find(query) ⇒ Object
10 11 12 13 |
# File 'lib/one_wire.rb', line 10 def find query query = Regexp.new query if query.is_a? String slaves.keep_if { |v| v =~ query } end |
.load(path) ⇒ Object
def find_by_name end
37 38 39 40 41 42 43 44 |
# File 'lib/one_wire.rb', line 37 def load path case File.basename(path)[/([\da-f]{2})-[\da-f]{12}/, 1] when *Thermometer::PREFIX then return Thermometer.new(path) # when *%w{06 08 0A 0C} then Memory.new(path) when %{00} then return nil else Base.new(path) end end |
.slaves(&block) ⇒ Object
6 7 8 |
# File 'lib/one_wire.rb', line 6 def slaves &block Dir.glob(File.join(File::SEPARATOR, 'sys', 'bus', 'w1', 'devices', '*-*'), &block) end |