Class: Samovar::Nested
- Inherits:
-
Object
- Object
- Samovar::Nested
- Defined in:
- lib/samovar/nested.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(name, commands, key: :command) ⇒ Nested
constructor
A new instance of Nested.
- #parse(input) ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
- #usage(rows) ⇒ Object
Constructor Details
#initialize(name, commands, key: :command) ⇒ Nested
Returns a new instance of Nested.
23 24 25 26 27 |
# File 'lib/samovar/nested.rb', line 23 def initialize(name, commands, key: :command) @name = name @commands = commands @key = key end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
29 30 31 |
# File 'lib/samovar/nested.rb', line 29 def key @key end |
Instance Method Details
#parse(input) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/samovar/nested.rb', line 39 def parse(input) if command = @commands[input.first] input.shift # puts "Instantiating #{command} with #{input}" command.new(input) end end |
#to_a ⇒ Object
35 36 37 |
# File 'lib/samovar/nested.rb', line 35 def to_a [@name, "One of #{@commands.keys.join(', ')}."] end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/samovar/nested.rb', line 31 def to_s @name end |
#usage(rows) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/samovar/nested.rb', line 48 def usage(rows) rows << self @commands.each do |key, klass| klass.usage(rows, key) end end |