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
: () -> Array.
-
#initialize(name_patterns:) ⇒ KeepDevice
constructor
: (name_patterns: Array) -> void.
-
#match_pattern?(string) ⇒ TrueClass, FalseClass
: (String) -> bool.
-
#print_not_found_messages ⇒ Object
: () -> nil.
-
#reset ⇒ Object
remove cache for reloading new devices : () -> void.
Constructor Details
#initialize(name_patterns:) ⇒ KeepDevice
: (name_patterns: Array) -> void
58 59 60 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 58 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.
101 102 103 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 101 def from_option @from_option end |
Instance Attribute Details
#name_patterns ⇒ Object (readonly)
Returns the value of attribute name_patterns.
62 63 64 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 62 def name_patterns @name_patterns end |
Instance Method Details
#all ⇒ Array
: () -> Array
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 73 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
: (String) -> bool
94 95 96 97 98 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 94 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
: () -> nil
86 87 88 89 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 86 def puts "Device is not found. Check following section on your config.yml" puts LibinputDeviceFilter.new.config_param_sample end |
#reset ⇒ Object
remove cache for reloading new devices : () -> void
66 67 68 69 |
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 66 def reset @all = nil Device.reset end |