Sha256: 7276d986c2aacce7113f50d83dbd6ceb4ce43a8eb37c3c6f12aae71af88aa691
Contents?: true
Size: 1.24 KB
Versions: 21
Compression:
Stored size: 1.24 KB
Contents
class Usher module Interface class Text def initialize(&blk) @usher = Usher.new(:delimiters => [' '], :generator => Usher::Util::Generators::Generic.new) instance_eval(&blk) if blk end def generate(name, params = nil) @usher.generator.generate(name, params) end def on(text, name = nil, &blk) r = @usher.add_route(text).to(:block => blk, :arg_type => :array) r.name(name) if name end def unrecognized(&blk) @unrecognize_block = blk end 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 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 end end end
Version data entries
21 entries across 21 versions & 1 rubygems