Class: Samovar::Many

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, description, stop: /^-/, default: nil) ⇒ Many

Returns a new instance of Many.



23
24
25
26
27
28
# File 'lib/samovar/many.rb', line 23

def initialize(key, description, stop: /^-/, default: nil)
	@key = key
	@description = description
	@stop = stop
	@default = default
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



30
31
32
# File 'lib/samovar/many.rb', line 30

def key
  @key
end

Instance Method Details

#parse(input, default = @default) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/samovar/many.rb', line 46

def parse(input, default = @default)
	if @stop and stop_index = input.index{|item| @stop === item}
		input.shift(stop_index)
	else
		input.shift(input.size)
	end || default
end

#to_aObject



36
37
38
39
40
41
42
43
44
# File 'lib/samovar/many.rb', line 36

def to_a
	usage = [to_s, @description]
	
	if @default
		usage << "Default: #{@default.inspect}"
	end
	
	return usage
end

#to_sObject



32
33
34
# File 'lib/samovar/many.rb', line 32

def to_s
	"<#{key}...>"
end