Class: Fusuma::Plugin::Filters::LibinputDeviceFilter::KeepDevice

Inherits:
Object
  • Object
show all
Defined in:
lib/fusuma/plugin/filters/libinput_device_filter.rb

Overview

Select Device to keep

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

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_optionObject

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_patternsObject (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

#allArray

Returns:

  • (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|
    print_not_found_messages if devices.empty?
  end
end

#match_pattern?(string) ⇒ TrueClass, FalseClass

Returns:

  • (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


78
79
80
81
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 78

def print_not_found_messages
  puts "Device is not found. Check following section on your config.yml"
  puts LibinputDeviceFilter.new.config_param_sample
end

#resetObject

remove cache for reloading new devices



60
61
62
63
# File 'lib/fusuma/plugin/filters/libinput_device_filter.rb', line 60

def reset
  @all = nil
  Device.reset
end