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
Returns the value of attribute from_option.
Instance Attribute Summary collapse
-
#name_patterns ⇒ Object
readonly
Returns the value of attribute name_patterns.
Instance Method Summary collapse
- #all ⇒ Array
-
#initialize(name_patterns:) ⇒ KeepDevice
constructor
A new instance of KeepDevice.
- #match_pattern?(string) ⇒ TrueClass, FalseClass
- #print_not_found_messages ⇒ Object
-
#reset ⇒ Object
remove cache for reloading new devices.
Constructor Details
#initialize(name_patterns:) ⇒ KeepDevice
Returns a new instance of KeepDevice.
53 54 55 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 53 def initialize(name_patterns:) @name_patterns = name_patterns | Array(self.class.from_option) end |
Class Attribute Details
.from_option ⇒ Object
Returns the value of attribute from_option.
92 93 94 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 92 def from_option @from_option end |
Instance Attribute Details
#name_patterns ⇒ Object (readonly)
Returns the value of attribute name_patterns.
57 58 59 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 57 def name_patterns @name_patterns end |
Instance Method Details
#all ⇒ Array
66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 66 def all @all ||= if @name_patterns.empty? Device.available else Device.all.select do |device| match_pattern?(device.name) end end.tap do |devices| if devices.empty? end end |
#match_pattern?(string) ⇒ TrueClass, FalseClass
85 86 87 88 89 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 85 def match_pattern?(string) return true if @name_patterns.empty? @name_patterns.any? { |name_pattern| string.match(name_pattern) } end |
#print_not_found_messages ⇒ Object
78 79 80 81 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 78 def puts "Device is not found. Check following section on your config.yml" puts LibinputDeviceFilter.new.config_param_sample end |