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

: (?id: nil | String, ?name: nil | String, ?capabilities: nil, ?available: nil | bool) -> void



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

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 : () -> Array

Returns:

  • (Array)


41
42
43
44
45
# File 'lib/fusuma/device.rb', line 41

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

.availableArray

: () -> Array

Returns:

  • (Array)

Raises:

  • (SystemExit)


50
51
52
53
54
55
56
57
58
59
# File 'lib/fusuma/device.rb', line 50

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

: () -> nil



62
63
64
65
# File 'lib/fusuma/device.rb', line 62

def reset
  @all = nil
  @available = nil
end

Instance Method Details

#assign_attributes(attributes) ⇒ Object

: (Hash[untyped, untyped]) -> Hash[untyped, untyped]

Parameters:



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

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