Class: Usher::Interface::Text
- Inherits:
-
Object
- Object
- Usher::Interface::Text
- Defined in:
- lib/usher/interface/text.rb
Instance Method Summary collapse
- #generate(name, params = nil) ⇒ Object
-
#initialize(&blk) ⇒ Text
constructor
A new instance of Text.
- #on(text, name = nil, &blk) ⇒ Object
- #on_with_hash(text, name = nil, &blk) ⇒ Object
- #run(text) ⇒ Object
- #unrecognized(&blk) ⇒ Object
Constructor Details
Instance Method Details
#generate(name, params = nil) ⇒ Object
10 11 12 |
# File 'lib/usher/interface/text.rb', line 10 def generate(name, params = nil) @usher.generator.generate(name, params) end |
#on(text, name = nil, &blk) ⇒ Object
14 15 16 17 |
# File 'lib/usher/interface/text.rb', line 14 def on(text, name = nil, &blk) r = @usher.add_route(text).to(:block => blk, :arg_type => :array) r.name(name) if name end |
#on_with_hash(text, name = nil, &blk) ⇒ Object
23 24 25 26 |
# File 'lib/usher/interface/text.rb', line 23 def on_with_hash(text, name = nil, &blk) r = @usher.add_route(text).to(:block => blk, :arg_type => :hash) r.name(name) if name end |
#run(text) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/usher/interface/text.rb', line 28 def run(text) response = @usher.recognize_path(text.strip) if response case response.path.route.destination[:arg_type] when :hash response.path.route.destination[:block].call(response.params.inject({}){|h,(k,v)| h[k]=v; h }) when :array response.path.route.destination[:block].call(*response.params.collect{|p| p.last}) end else @unrecognize_block ? @unrecognize_block.call(text) : nil end end |
#unrecognized(&blk) ⇒ Object
19 20 21 |
# File 'lib/usher/interface/text.rb', line 19 def unrecognized(&blk) @unrecognize_block = blk end |