Class: Fusuma::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/fusuma/device.rb

Overview

detect input device

Defined Under Namespace

Classes: LineParser

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, name: nil, available: nil) ⇒ Device

Returns a new instance of Device.



8
9
10
11
12
# File 'lib/fusuma/device.rb', line 8

def initialize(id: nil, name: nil, available: nil)
  @id = id
  @name = name
  @available = available
end

Instance Attribute Details

#availableObject

Returns the value of attribute available.



6
7
8
# File 'lib/fusuma/device.rb', line 6

def available
  @available
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/fusuma/device.rb', line 4

def id
  @id
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/fusuma/device.rb', line 5

def name
  @name
end

Class Method Details

.availableArray

Returns:

  • (Array)

Raises:

  • (SystemExit)


27
28
29
30
31
32
33
34
35
# File 'lib/fusuma/device.rb', line 27

def available
  @available ||= fetch_available.tap do |d|
    MultiLogger.debug(available_devices: d)
    raise 'Touchpad is not found' if d.empty?
  end
rescue RuntimeError => ex
  MultiLogger.error(ex.message)
  exit 1
end

.given_device=(name) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/fusuma/device.rb', line 42

def given_device=(name)
  return if name.nil?
  @available = available.select { |d| d.name == name }
  return unless names.empty?
  MultiLogger.error("Device #{name} is not found.\n
     Check available device with: $ fusuma --list-devices\n")
  exit 1
end

.idsArray

Returns:

  • (Array)


16
17
18
# File 'lib/fusuma/device.rb', line 16

def ids
  available.map(&:id)
end

.namesArray

Returns:

  • (Array)


21
22
23
# File 'lib/fusuma/device.rb', line 21

def names
  available.map(&:name)
end

.resetObject



37
38
39
# File 'lib/fusuma/device.rb', line 37

def reset
  @available = nil
end