Class: Basher::Handler
- Inherits:
-
Object
- Object
- Basher::Handler
- Defined in:
- lib/basher/handler.rb
Constant Summary collapse
- ALPHABET =
('a'..'z').to_a.freeze
Class Attribute Summary collapse
-
.bindings ⇒ Object
readonly
Returns the value of attribute bindings.
Instance Attribute Summary collapse
-
#bindings ⇒ Object
readonly
Returns the value of attribute bindings.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(custom_bindings = {}) ⇒ Handler
constructor
A new instance of Handler.
- #invoke(input) ⇒ Object
- #letter?(input) ⇒ Boolean
Constructor Details
#initialize(custom_bindings = {}) ⇒ Handler
Returns a new instance of Handler.
19 20 21 |
# File 'lib/basher/handler.rb', line 19 def initialize(custom_bindings = {}) @bindings = self.class.bindings.merge(custom_bindings) end |
Class Attribute Details
.bindings ⇒ Object (readonly)
Returns the value of attribute bindings.
6 7 8 |
# File 'lib/basher/handler.rb', line 6 def bindings @bindings end |
Instance Attribute Details
#bindings ⇒ Object (readonly)
Returns the value of attribute bindings.
17 18 19 |
# File 'lib/basher/handler.rb', line 17 def bindings @bindings end |
Class Method Details
.bind(*keys, &action) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/basher/handler.rb', line 8 def bind(*keys, &action) @bindings ||= {} keys.map(&:to_sym).each do |input| @bindings[input] ||= [] @bindings[input] << action end end |
Instance Method Details
#invoke(input) ⇒ Object
23 24 25 26 27 |
# File 'lib/basher/handler.rb', line 23 def invoke(input) bindings.fetch(input.to_sym, []).map do |b| b.call(input) end.last end |
#letter?(input) ⇒ Boolean
29 30 31 32 |
# File 'lib/basher/handler.rb', line 29 def letter?(input) return false if input.size != 1 input =~ /[[:alpha:]]/ end |