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, capabilities: nil, available: nil) ⇒ Device

Returns a new instance of Device.



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

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

Instance Attribute Details

#availableObject (readonly)

Returns the value of attribute available.



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

def available
  @available
end

#capabilitiesObject (readonly)

Returns the value of attribute capabilities.



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

def capabilities
  @capabilities
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Class Method Details

.allArray

Return devices sort devices by capabilities of gesture

Returns:

  • (Array)


38
39
40
41
42
# File 'lib/fusuma/device.rb', line 38

def all
  @all ||= fetch_devices.partition do |d|
    d.capabilities.match?(/gesture/)
  end.flatten
end

.availableArray

Returns:

  • (Array)

Raises:

  • (SystemExit)


46
47
48
49
50
51
52
53
54
55
# File 'lib/fusuma/device.rb', line 46

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



57
58
59
60
# File 'lib/fusuma/device.rb', line 57

def reset
  @all = nil
  @available = nil
end

Instance Method Details

#assign_attributes(attributes) ⇒ Object

Parameters:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fusuma/device.rb', line 19

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