Class: Keyremac::Key

Inherits:
Object
  • Object
show all
Includes:
Keyable
Defined in:
lib/keyremac/dump.rb,
lib/keyremac/key.rb

Overview

key

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Keyable

#add_rule, #consumer_key?, #overlaid, #to

Constructor Details

#initialize(name) ⇒ Key

Returns a new instance of Key.



72
73
74
75
76
77
78
79
80
81
# File 'lib/keyremac/key.rb', line 72

def initialize(name)
  @mods = Set.new

  if key = SHIFT_TABLE[name]
    @code = SYMBOL_TABLE[key] || key
    self.shift
  else
    @code = SYMBOL_TABLE[name] || name
  end
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



66
67
68
# File 'lib/keyremac/key.rb', line 66

def code
  @code
end

#modsObject (readonly)

Returns the value of attribute mods.



66
67
68
# File 'lib/keyremac/key.rb', line 66

def mods
  @mods
end

Instance Method Details

#add_mod(mod) ⇒ Object



83
84
85
86
# File 'lib/keyremac/key.rb', line 83

def add_mod(mod)
  @mods.add mod
  self
end

#dump(xml) ⇒ Object



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

def dump(xml)
  if @mods.empty?
    "KeyCode::#{code.upcase}"
  else
    mods = @mods.to_a
    mods = mods.map { |mod|
      mod = mod.to_s
      if mod =~ /^VK_/
        mod
      else
        "ModifierFlag::#{mod}"
      end
    }
    mods = mods.join(' | ')
    "KeyCode::#{code.upcase}, #{mods}"
  end
end

#to_keyObject



68
69
70
# File 'lib/keyremac/key.rb', line 68

def to_key
  self
end