Class: Samovar::ValueFlag

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

Instance Attribute Summary collapse

Attributes inherited from Flag

#prefix, #text

Instance Method Summary collapse

Methods inherited from Flag

#key, parse, #to_s

Constructor Details

#initialize(text, prefix, value) ⇒ ValueFlag

Returns a new instance of ValueFlag.



82
83
84
85
86
87
88
# File 'lib/samovar/flags.rb', line 82

def initialize(text, prefix, value)
	super(text, prefix)
	
	@value = value
	
	*@alternatives, @prefix = @prefix.split('/')
end

Instance Attribute Details

#alternativesObject (readonly)

Returns the value of attribute alternatives.



90
91
92
# File 'lib/samovar/flags.rb', line 90

def alternatives
  @alternatives
end

#valueObject (readonly)

Returns the value of attribute value.



91
92
93
# File 'lib/samovar/flags.rb', line 91

def value
  @value
end

Instance Method Details

#boolean?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/samovar/flags.rb', line 93

def boolean?
	@value.nil?
end

#parse(input) ⇒ Object



101
102
103
104
105
106
107
108
109
110
# File 'lib/samovar/flags.rb', line 101

def parse(input)
	if prefix?(input.first)
		if @value
			return input.shift(2).last
		else
			input.shift
			return key
		end
	end
end

#prefix?(token) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/samovar/flags.rb', line 97

def prefix?(token)
	@prefix == token or @alternatives.include?(token)
end