Class: Samovar::Nested

Inherits:
Object
  • Object
show all
Defined in:
lib/samovar/nested.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#keyObject (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_aObject



35
36
37
# File 'lib/samovar/nested.rb', line 35

def to_a
	[@name, "One of #{@commands.keys.join(', ')}."]
end

#to_sObject



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