module OneWire
Public Class Methods
all(&block)
click to toggle source
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
# 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()
click to toggle source
# File lib/one_wire.rb, line 46 def devices slaves.collect { |path| load(path) } end
find(query)
click to toggle source
# 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)
click to toggle source
def find_by_name end
# 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)
click to toggle source
# File lib/one_wire.rb, line 6 def slaves &block Dir.glob(File.join(File::SEPARATOR, 'sys', 'bus', 'w1', 'devices', '*-*'), &block) end