Module: MovingsignApi::PrettyKeyable::ClassMethods

Defined in:
lib/movingsign_api/commands/internal/pretty_keyable.rb

Instance Method Summary collapse

Instance Method Details

#codesObject



45
46
47
# File 'lib/movingsign_api/commands/internal/pretty_keyable.rb', line 45

def codes
  class_variable_get(:@@CODES)
end

#keysObject



41
42
43
# File 'lib/movingsign_api/commands/internal/pretty_keyable.rb', line 41

def keys
  class_variable_get(:@@KEYS)
end

#parse_to_key(input) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/movingsign_api/commands/internal/pretty_keyable.rb', line 33

def parse_to_key(input)
  if index = (keys.index(input) || codes.index(input))
    keys[index]
  else
    nil
  end
end

#register(key, code) ⇒ Object

registers the specified key and code pair as synonymous



24
25
26
27
28
29
30
31
# File 'lib/movingsign_api/commands/internal/pretty_keyable.rb', line 24

def register(key, code)
  keys << key
  codes << code

  define_singleton_method(key) do
    key
  end
end