Class: Otori::Signals
- Inherits:
-
Object
- Object
- Otori::Signals
- Defined in:
- lib/otori/signals.rb
Constant Summary collapse
- KEYS =
{ mouse: "m", touch: "t", scroll: "s", keyboard: "k", focus: "f" }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #human_rating ⇒ Object
-
#initialize(flags = {}) ⇒ Signals
constructor
A new instance of Signals.
- #to_h ⇒ Object
Constructor Details
Class Method Details
.from_json(json) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/otori/signals.rb', line 15 def self.from_json(json) raw = JSON.parse(json.to_s) raise JSON::ParserError, "expected an object" unless raw.is_a?(Hash) new(KEYS.transform_values { raw[_1] == true }) rescue JSON::ParserError new end |
.human_rating(json) ⇒ Object
24 25 26 |
# File 'lib/otori/signals.rb', line 24 def self.(json) from_json(json). end |
Instance Method Details
#human_rating ⇒ Object
36 37 38 |
# File 'lib/otori/signals.rb', line 36 def @flags.values.count(true) / KEYS.size.to_f end |
#to_h ⇒ Object
40 |
# File 'lib/otori/signals.rb', line 40 def to_h = @flags.dup |