Class: KeyEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/vtparser/keymap.rb

Overview

Logic taken from vidarh/keyboard_map gem

github.com/vidarh/keyboard_map

See examples/keymap.rb for usage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, *modifiers, args: nil) ⇒ KeyEvent

Returns a new instance of KeyEvent.



14
15
16
17
18
# File 'lib/vtparser/keymap.rb', line 14

def initialize(key, *modifiers, args: nil)
  @key = key
  @args = args
  @modifiers = modifiers.map(&:to_sym).to_set
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



12
13
14
# File 'lib/vtparser/keymap.rb', line 12

def args
  @args
end

#keyObject (readonly)

Returns the value of attribute key.



12
13
14
# File 'lib/vtparser/keymap.rb', line 12

def key
  @key
end

#modifiersObject (readonly)

Returns the value of attribute modifiers.



12
13
14
# File 'lib/vtparser/keymap.rb', line 12

def modifiers
  @modifiers
end

Instance Method Details

#==(other) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/vtparser/keymap.rb', line 28

def ==(other)
  case other
  when KeyEvent
    self.modifiers == other.modifiers && self.key == other.key
  when Symbol
    self.to_sym == other
  else
    self.to_s == other
  end
end

#to_sObject



20
21
22
# File 'lib/vtparser/keymap.rb', line 20

def to_s
  (modifiers.to_a.sort << key).join('_')
end

#to_symObject



24
25
26
# File 'lib/vtparser/keymap.rb', line 24

def to_sym
  to_s.to_sym
end