Class: RubyHid::Store
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- RubyHid::Store
- Defined in:
- lib/ruby_hid/store.rb
Instance Attribute Summary collapse
-
#device ⇒ Object
Returns the value of attribute device.
Instance Method Summary collapse
-
#initialize ⇒ Store
constructor
A new instance of Store.
- #normalise(key) ⇒ Object
- #normalised_hash ⇒ Object
Constructor Details
#initialize ⇒ Store
Returns a new instance of Store.
7 8 9 10 11 |
# File 'lib/ruby_hid/store.rb', line 7 def initialize super init_observers init_device end |
Instance Attribute Details
#device ⇒ Object
Returns the value of attribute device.
5 6 7 |
# File 'lib/ruby_hid/store.rb', line 5 def device @device end |
Instance Method Details
#normalise(key) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ruby_hid/store.rb', line 13 def normalise(key) value = @table[key] if value if Store.(key) value else # it's an axis range = Store.value_range(key) if range.respond_to?(:size) size = range.size else size = (range.max - range.min).abs + 1 end (value - range.min).to_f / size end else 0 end end |
#normalised_hash ⇒ Object
32 33 34 35 36 37 |
# File 'lib/ruby_hid/store.rb', line 32 def normalised_hash @table.keys.inject({}) do |result, key| result[key] = normalise(key) result end end |