Class: Rbindkeys::BindResolver
- Inherits:
-
Object
- Object
- Rbindkeys::BindResolver
- Defined in:
- lib/rbindkeys.rb,
lib/rbindkeys/bind_resolver.rb
Direct Known Subclasses
Constant Summary collapse
- LOG =
LogUtils.get_logger name
- DEFAULT_VALUE =
:through
Instance Attribute Summary collapse
-
#tree ⇒ Object
readonly
Returns the value of attribute tree.
-
#two_stroke ⇒ Object
(also: #two_stroke?)
readonly
if this resolver is set by prefix key, then true else, false.
-
#upper_resolver ⇒ Object
readonly
delegate if cannot resolved.
Instance Method Summary collapse
- #bind(input, output) ⇒ Object
-
#initialize(upper_resolver = :through, two_stroke = false) ⇒ BindResolver
constructor
A new instance of BindResolver.
- #just_resolve(key_code, key_code_set) ⇒ Object
- #resolve(key_code, key_code_set) ⇒ Object
Constructor Details
#initialize(upper_resolver = :through, two_stroke = false) ⇒ BindResolver
Returns a new instance of BindResolver.
20 21 22 23 24 25 26 27 |
# File 'lib/rbindkeys/bind_resolver.rb', line 20 def initialize upper_resolver=:through, two_stroke=false @tree = {} if upper_resolver.kind_of? Symbol upper_resolver = FixResolver.instance upper_resolver end @upper_resolver = upper_resolver @two_stroke = two_stroke end |
Instance Attribute Details
#tree ⇒ Object (readonly)
Returns the value of attribute tree.
10 11 12 |
# File 'lib/rbindkeys/bind_resolver.rb', line 10 def tree @tree end |
#two_stroke ⇒ Object (readonly) Also known as: two_stroke?
if this resolver is set by prefix key, then true else, false
17 18 19 |
# File 'lib/rbindkeys/bind_resolver.rb', line 17 def two_stroke @two_stroke end |
#upper_resolver ⇒ Object (readonly)
delegate if cannot resolved
13 14 15 |
# File 'lib/rbindkeys/bind_resolver.rb', line 13 def upper_resolver @upper_resolver end |
Instance Method Details
#bind(input, output) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rbindkeys/bind_resolver.rb', line 29 def bind input, output @tree[input.last] ||= [] @tree[input.last].each do |b| if b.input == input raise DuplicateNodeError, "already this input(#{input.inspect}) was binded" end end kb = KeyBind.new input, output @tree[input.last] << kb # TODO implement a bubble insertion @tree[input.last].sort!{|a,b| b.input.length <=> a.input.length} kb end |
#just_resolve(key_code, key_code_set) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/rbindkeys/bind_resolver.rb', line 48 def just_resolve key_code, key_code_set arr = @tree[key_code] arr.each do |kb| sub = kb.input - key_code_set sub.first == kb.input.last and return kb end if not arr.nil? nil end |
#resolve(key_code, key_code_set) ⇒ Object
43 44 45 46 |
# File 'lib/rbindkeys/bind_resolver.rb', line 43 def resolve key_code, key_code_set just_resolve(key_code, key_code_set) or @upper_resolver.resolve(key_code, key_code_set) end |