Class: Fusuma::Plugin::Filters::LibinputDeviceFilter::KeepDevice
- Inherits:
-
Object
- Object
- Fusuma::Plugin::Filters::LibinputDeviceFilter::KeepDevice
- Defined in:
- lib/fusuma/plugin/filters/libinput_device_filter.rb
Overview
Select Device to keep
Class Attribute Summary collapse
-
.from_option ⇒ Object
TODO: remove from_option and command line options.
Instance Method Summary collapse
- #all ⇒ Array
-
#initialize(name_patterns:) ⇒ KeepDevice
constructor
A new instance of KeepDevice.
- #match_pattern?(string) ⇒ TrueClass, FalseClass
-
#reset ⇒ Object
remove cache for reloading new devices.
Constructor Details
#initialize(name_patterns:) ⇒ KeepDevice
Returns a new instance of KeepDevice.
41 42 43 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 41 def initialize(name_patterns:) @name_patterns = name_patterns | Array(self.class.from_option) end |
Class Attribute Details
.from_option ⇒ Object
TODO: remove from_option and command line options
72 73 74 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 72 def from_option @from_option end |
Instance Method Details
#all ⇒ Array
52 53 54 55 56 57 58 59 60 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 52 def all @all ||= if @name_patterns.empty? Device.available else Device.all.select do |device| match_pattern?(device.name) end end end |
#match_pattern?(string) ⇒ TrueClass, FalseClass
64 65 66 67 68 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 64 def match_pattern?(string) return true if @name_patterns.empty? @name_patterns.any? { |name_pattern| string.match(name_pattern) } end |