Class: Twiddler::Config::KeyTable::KeyData

Inherits:
Object
  • Object
show all
Defined in:
lib/twiddler/config.rb

Constant Summary collapse

ModAliases =
Hash.new{|h,k| k}.merge!(
  "rsft" => "shift",
  "lsft" => "shift",
  "rctl" => "control",
  "lctl" => "control",
  "lalt" => "alt",
  "ralt" => "alt",
  "lgui" => "gui",
  "rgui" => "gui"
)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(num, name) ⇒ KeyData

Returns a new instance of KeyData.



16
17
18
19
20
# File 'lib/twiddler/config.rb', line 16

def initialize(num, name)
  @code = num
  @data = { :unmod => name }
  @tags = {}
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



21
22
23
# File 'lib/twiddler/config.rb', line 21

def code
  @code
end

Class Method Details

.normalized(mod) ⇒ Object



52
53
54
55
56
57
# File 'lib/twiddler/config.rb', line 52

def self.normalized(mod)
  unless Array === mod
    mod = mod.split("-")
  end
  return mod.map{|i| ModAliases[i.downcase]}.sort.join("-")
end

Instance Method Details

#===(chord) ⇒ Object



48
49
50
# File 'lib/twiddler/config.rb', line 48

def ===(chord)
  chord.single? and chord[0][0] == @code
end

#has_mod?(mod) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/twiddler/config.rb', line 44

def has_mod?(mod)
  @data.has_key?(normalized(mod))
end

#modified(mod, value) ⇒ Object



31
32
33
# File 'lib/twiddler/config.rb', line 31

def modified(mod, value)
  @data[normalized(mod)] = value
end

#normalized(mod) ⇒ Object



59
60
61
# File 'lib/twiddler/config.rb', line 59

def normalized(mod)
  self.class.normalized(mod)
end

#string(mod = nil) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/twiddler/config.rb', line 35

def string(mod=nil)
  return @data[:unmod] if mod.nil? or mod.empty?
  if data = @data[normalized(mod)]
    return data
  else
    return "#{mod}-#{@data[:unmod]}"
  end
end

#tag(name) ⇒ Object



23
24
25
# File 'lib/twiddler/config.rb', line 23

def tag(name)
  @tags[name.to_sym] = true
end

#tag?(name) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/twiddler/config.rb', line 27

def tag?(name)
  @tags.has_key?(name)
end