Class: Cuttlebone::Definition
- Inherits:
-
Object
- Object
- Cuttlebone::Definition
- Defined in:
- lib/cuttlebone/definition.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#commands ⇒ Object
Returns the value of attribute commands.
-
#prompt ⇒ Object
Returns the value of attribute prompt.
Instance Method Summary collapse
-
#initialize(object_or_class, options = {}, &definition) ⇒ Definition
constructor
A new instance of Definition.
- #match(object) ⇒ Object
- #proc_for(command) ⇒ Object
Constructor Details
#initialize(object_or_class, options = {}, &definition) ⇒ Definition
Returns a new instance of Definition.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cuttlebone/definition.rb', line 33 def initialize object_or_class, ={}, &definition raise ArgumentError, 'missing block' unless block_given? @object_or_class = object_or_class @options = @commands = [] #Array.new(proc { |c| [:self, c, '', nil] }) @prompt = proc { |c| '' } @parser = Parser.new(self) @parser.instance_eval(&definition) end |
Instance Attribute Details
#commands ⇒ Object
Returns the value of attribute commands.
31 32 33 |
# File 'lib/cuttlebone/definition.rb', line 31 def commands @commands end |
#prompt ⇒ Object
Returns the value of attribute prompt.
31 32 33 |
# File 'lib/cuttlebone/definition.rb', line 31 def prompt @prompt end |
Instance Method Details
#match(object) ⇒ Object
46 47 48 49 |
# File 'lib/cuttlebone/definition.rb', line 46 def match object @object_or_class === object # TODO :if :unless options end |
#proc_for(command) ⇒ Object
51 52 53 54 55 |
# File 'lib/cuttlebone/definition.rb', line 51 def proc_for command string_or_regexp, block, description = commands.find { |(sr,b,d)| sr === command } || raise(UnknownCommandError, "Unknown command: #{command.inspect}!") return([ block, $~.captures ]) if $~ return([ block, [] ]) end |