class Fusuma::Device::LineParser
parse line and generate devices
Attributes
lines[R]
Public Class Methods
new()
click to toggle source
# File lib/fusuma/device.rb, line 80 def initialize @lines = [] end
Public Instance Methods
available_from(line)
click to toggle source
# File lib/fusuma/device.rb, line 139 def available_from(line) # NOTE: is natural scroll available? if line =~ /^Nat.scrolling: / return false if line =~ %r{n/a} return true # disabled / enabled end nil end
capabilities_from(line)
click to toggle source
# File lib/fusuma/device.rb, line 133 def capabilities_from(line) line.match('^Capabilities:[[:space:]]*') do |m| m.post_match.strip end end
extract_attribute(line:)
click to toggle source
@param line [String] @return [Hash]
# File lib/fusuma/device.rb, line 107 def extract_attribute(line:) if (id = id_from(line)) { id: id } elsif (name = name_from(line)) { name: name } elsif (capabilities = capabilities_from(line)) { capabilities: capabilities } elsif (available = available_from(line)) { available: available } else {} end end
generate_devices()
click to toggle source
@return [Array]
# File lib/fusuma/device.rb, line 90 def generate_devices lines.each_with_object([]) do |line, devices| attributes = extract_attribute(line: line) next if attributes == {} if attributes[:name] # when detected new line including device name devices << Device.new # next device end devices.last.assign_attributes(attributes) unless devices.empty? end end
id_from(line)
click to toggle source
# File lib/fusuma/device.rb, line 121 def id_from(line) line.match('^Kernel:[[:space:]]*') do |m| m.post_match.match(/event[0-9]+/).to_s end end
name_from(line)
click to toggle source
# File lib/fusuma/device.rb, line 127 def name_from(line) line.match('^Device:[[:space:]]*') do |m| m.post_match.strip end end
push(line)
click to toggle source
@param line [String]
# File lib/fusuma/device.rb, line 85 def push(line) lines.push(line) end