Class: Twiddler::Config::KeyTable

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

Defined Under Namespace

Classes: KeyData

Instance Method Summary collapse

Constructor Details

#initializeKeyTable

Returns a new instance of KeyTable.



64
65
66
67
68
# File 'lib/twiddler/config.rb', line 64

def initialize
  @data = Hash.new{|h,k| KeyData.new(k, "U/#{k.inspect}")}
  @ordered = []
  @current_tags = {}
end

Instance Method Details

#[](idx, mod = nil) ⇒ Object



103
104
105
# File 'lib/twiddler/config.rb', line 103

def [](idx, mod=nil)
  return @data[idx].string(mod)
end

#[]=(idx, value) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/twiddler/config.rb', line 107

def []=(idx, value)
  if @data.has_key?(idx)
    @ordered.delete(@data[idx])
  end
  data = KeyData.new(idx, value)
  @current_tags.each_key do |name|
    data.tag(name)
  end
  @data[idx] = data
  @ordered << data
end

#clear_tagsObject



89
90
91
# File 'lib/twiddler/config.rb', line 89

def clear_tags
  @current_tags.clear
end

#each(&block) ⇒ Object



120
121
122
# File 'lib/twiddler/config.rb', line 120

def each(&block)
  @ordered.each(&block)
end

#end_tag(name) ⇒ Object



85
86
87
# File 'lib/twiddler/config.rb', line 85

def end_tag(name)
  @current_tags.delete(name.to_sym)
end

#is_tagged?(idx, tag) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/twiddler/config.rb', line 99

def is_tagged?(idx, tag)
  @data[idx].tag?(tag)
end

#mod(idx, mod, value) ⇒ Object



124
125
126
# File 'lib/twiddler/config.rb', line 124

def mod(idx, mod, value)
  @data[idx].modified(mod, value)
end

#normalized(stroke) ⇒ Object



70
71
72
73
# File 'lib/twiddler/config.rb', line 70

def normalized(stroke)
  mods = KeyData::normalized(stroke[1])
  return [stroke[0], mods]
end

#start_tag(name) ⇒ Object



81
82
83
# File 'lib/twiddler/config.rb', line 81

def start_tag(name)
  @current_tags[name.to_sym] = true
end

#tagged(name) ⇒ Object



93
94
95
96
97
# File 'lib/twiddler/config.rb', line 93

def tagged(name)
  @ordered.find_all do |key|
    key.tag?(name)
  end
end

#unknowns(list) ⇒ Object



75
76
77
78
79
# File 'lib/twiddler/config.rb', line 75

def unknowns(list)
  return list.reject do |item|
    @data.has_key?(item)
  end
end