Class: Revdev::InputId

Inherits:
Object
  • Object
show all
Includes:
EachValuesEqual
Defined in:
lib/revdev/input_id.rb,
lib/revdev.rb

Overview

wraper of “struct input_id” on “input.h”

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EachValuesEqual

#==

Constructor Details

#initialize(arg = nil, vendor = nil, product = nil, version = nil) ⇒ InputId

Returns a new instance of InputId.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/revdev/input_id.rb', line 10

def initialize(arg=nil, vendor=nil, product=nil, version=nil)
  if arg.kind_of? String
    raw_initialize arg
  elsif arg.kind_of? Hash
    [:bustype, :vendor, :product, :version].each do |iv|
      instance_variable_set("@#{iv}", arg[iv] || arg[iv.to_s])
    end
  elsif not ( arg.nil? or vendor.nil? or product.nil? or version.nil? )
    @bustype = arg
    @vendor = vendor
    @product = product
    @version = version
  else
    raise ArgumentError, "expected a Hash"
  end
end

Instance Attribute Details

#bustypeObject

Returns the value of attribute bustype.



8
9
10
# File 'lib/revdev/input_id.rb', line 8

def bustype
  @bustype
end

#productObject

Returns the value of attribute product.



8
9
10
# File 'lib/revdev/input_id.rb', line 8

def product
  @product
end

#vendorObject

Returns the value of attribute vendor.



8
9
10
# File 'lib/revdev/input_id.rb', line 8

def vendor
  @vendor
end

#versionObject

Returns the value of attribute version.



8
9
10
# File 'lib/revdev/input_id.rb', line 8

def version
  @version
end

Instance Method Details

#hr_bustypeObject



27
28
29
# File 'lib/revdev/input_id.rb', line 27

def hr_bustype
  REVERSE_MAPS[:BUS][@bustype]
end

#hr_versionObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/revdev/input_id.rb', line 31

def hr_version
  v = @version
  v_arr = []
  v_arr << (v & 0xff)
  2.times do
    v = (v >> 8)
    v_arr << (v & 0xff)
  end
  v_arr.reverse.join '.'
end