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.



10
11
12
13
14
# File 'lib/fusuma/device.rb', line 10

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

Instance Attribute Details

#availableObject (readonly)

Returns the value of attribute available.



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

def available
  @available
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.allArray

Returns:

  • (Array)


32
33
34
# File 'lib/fusuma/device.rb', line 32

def all
  @all ||= fetch_devices
end

.availableArray

Returns:

  • (Array)

Raises:

  • (SystemExit)


38
39
40
41
42
43
44
45
46
47
# File 'lib/fusuma/device.rb', line 38

def available
  @available ||= all.select(&:available).tap do |d|
    MultiLogger.debug(available_devices: d)
    raise 'Touchpad is not found' if d.empty?
  end
rescue RuntimeError => e
  # FIXME: should not exit without Runner class
  MultiLogger.error(e.message)
  exit 1
end

.resetObject



49
50
51
52
# File 'lib/fusuma/device.rb', line 49

def reset
  @all = nil
  @available = nil
end

Instance Method Details

#assign_attributes(attributes) ⇒ Object

Parameters:



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/fusuma/device.rb', line 17

def assign_attributes(attributes)
  attributes.each do |k, v|
    case k
    when :id
      @id = v
    when :name
      @name = v
    when :available
      @available = v
    end
  end
end