Class: Finder
- Inherits:
-
Object
- Object
- Finder
- Defined in:
- lib/bluebutton.rb
Instance Method Summary collapse
- #from_sys ⇒ Object
- #from_xinput ⇒ Object
-
#initialize(name) ⇒ Finder
constructor
A new instance of Finder.
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_sys ⇒ Object
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_xinput ⇒ Object
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 |