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.
52 53 54 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 52 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.
91 92 93 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 91 def from_option @from_option end |
Instance Attribute Details
#name_patterns ⇒ Object (readonly)
Returns the value of attribute name_patterns.
56 57 58 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 56 def name_patterns @name_patterns end |
Instance Method Details
#all ⇒ Array
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 65 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
84 85 86 87 88 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 84 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
77 78 79 80 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 77 def puts 'Device is not found. Check following section on your config.yml' puts LibinputDeviceFilter.new.config_param_sample end |