Class: Samovar::Split

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, description, marker: '--', default: nil) ⇒ Split

Returns a new instance of Split.



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

def initialize(key, description, marker: '--', default: nil)
	@key = key
	@description = description
	@marker = marker
	@default = default
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



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

def key
  @key
end

Instance Method Details

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



46
47
48
49
50
# File 'lib/samovar/split.rb', line 46

def parse(input, default = @default)
	if offset = input.index(@marker)
		input.pop(input.size - offset).tap(&:shift)
	end || default
end

#to_aObject



36
37
38
39
40
41
42
43
44
# File 'lib/samovar/split.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/split.rb', line 32

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