lib/fusuma/device.rb in fusuma-2.0.0.pre vs lib/fusuma/device.rb in fusuma-2.0.0.pre2

- old
+ new

@@ -1,20 +1,19 @@ # frozen_string_literal: true require_relative './multi_logger' -require_relative './libinput_command.rb' +require_relative './libinput_command' module Fusuma # detect input device class Device - attr_reader :available - attr_reader :name - attr_reader :id + attr_reader :id, :name, :capabilities, :available - def initialize(id: nil, name: nil, available: nil) + def initialize(id: nil, name: nil, capabilities: nil, available: nil) @id = id @name = name + @capabilities = capabilities @available = available end # @param attributes [Hash] def assign_attributes(attributes) @@ -22,20 +21,26 @@ case k when :id @id = v when :name @name = v + when :capabilities + @capabilities = v when :available @available = v end end end class << self + # Return devices + # sort devices by capabilities of gesture # @return [Array] def all - @all ||= fetch_devices + @all ||= fetch_devices.sort_by do |d| + d.capabilities.match(/gesture/).to_s + end end # @raise [SystemExit] # @return [Array] def available @@ -102,10 +107,12 @@ 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 @@ -117,9 +124,15 @@ end end def name_from(line) line.match('^Device:[[:space:]]*') do |m| + m.post_match.strip + end + end + + def capabilities_from(line) + line.match('^Capabilities:[[:space:]]*') do |m| m.post_match.strip end end def available_from(line)