Class: Finder

Inherits:
Object
  • Object
show all
Defined in:
lib/bluebutton.rb

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Finder

Returns a new instance of Finder.



65
66
67
# File 'lib/bluebutton.rb', line 65

def initialize name
  @name = name
end

Instance Method Details

#from_sysObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/bluebutton.rb', line 69

def from_sys
  finded = Dir.glob("/sys/**/name").select do |file|
    File.read(file).downcase[@name.downcase]
  end.first

  raise "Can't find device info '#{@name}' in /sys/**/*" if finded.nil?

  device = "/dev/" + Dir.glob("#{File.dirname(finded)}/**/uevent").map do |file|
    File.read(file).split("\n").select{|s| s['DEVNAME']}.compact.first
  end.compact.flatten.first.split("=")[1] rescue nil

  raise "Can't find device file for '#{@name}' in #{File.dirname(finded)}/**/uevent" if device.nil?

  return device
end

#from_xinputObject



85
86
87
88
89
90
91
92
# File 'lib/bluebutton.rb', line 85

def from_xinput
  if device =`xinput`.split("\n").compact.map(&:strip).select{|l| l.downcase[@name.downcase]}.first
    puts "find:#{device}"
    return /id=(\d+)/.match(device)[1]
  end
rescue
  return nil
end