Class: Twterm::KeyMapper::AbstractKeyMapper

Inherits:
Object
  • Object
show all
Defined in:
lib/twterm/key_mapper/abstract_key_mapper.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dict) ⇒ AbstractKeyMapper

Returns a new instance of AbstractKeyMapper.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/twterm/key_mapper/abstract_key_mapper.rb', line 8

def initialize(dict)
  commands = self.class.commands

  dict ||= {}

  dict.keys.each do |k|
    raise NoSuchCommand.new(self.class.category, k) unless commands.include?(k)
  end

  @mappings = Hash[dict.map { |k, v| [k, translate(v)] }]
  @dict = dict
end

Class Method Details

.commandsObject



26
27
28
# File 'lib/twterm/key_mapper/abstract_key_mapper.rb', line 26

def self.commands
  self::DEFAULT_MAPPINGS.keys
end

Instance Method Details

#[](key) ⇒ Object

Raises:



21
22
23
24
# File 'lib/twterm/key_mapper/abstract_key_mapper.rb', line 21

def [](key)
  raise NoSuchCommand.new(self.class.category, key) unless @mappings.keys.include?(key)
  @mappings[key]
end

#to_hObject



30
31
32
# File 'lib/twterm/key_mapper/abstract_key_mapper.rb', line 30

def to_h
  @dict
end