Class: Samovar::Flag

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

Direct Known Subclasses

BooleanFlag, ValueFlag

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, prefix, alternatives = nil) ⇒ Flag

Returns a new instance of Flag.



58
59
60
61
62
# File 'lib/samovar/flags.rb', line 58

def initialize(text, prefix, alternatives = nil)
	@text = text
	@prefix = prefix
	@alternatives = alternatives
end

Instance Attribute Details

#alternativesObject (readonly)

Returns the value of attribute alternatives.



66
67
68
# File 'lib/samovar/flags.rb', line 66

def alternatives
  @alternatives
end

#prefixObject (readonly)

Returns the value of attribute prefix.



65
66
67
# File 'lib/samovar/flags.rb', line 65

def prefix
  @prefix
end

#textObject (readonly)

Returns the value of attribute text.



64
65
66
# File 'lib/samovar/flags.rb', line 64

def text
  @text
end

Class Method Details

.parse(text) ⇒ Object



48
49
50
51
52
53
54
55
56
# File 'lib/samovar/flags.rb', line 48

def self.parse(text)
	if text =~ /(.*?)\s(\<.*?\>)/
		ValueFlag.new(text, $1, $2)
	elsif text =~ /--\[no\]-(.*?)$/
		BooleanFlag.new(text, "--#{$1}")
	else
		ValueFlag.new(text, text, nil)
	end
end

Instance Method Details

#boolean?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/samovar/flags.rb', line 76

def boolean?
	false
end

#keyObject



72
73
74
# File 'lib/samovar/flags.rb', line 72

def key
	@key ||= @prefix.sub(/^-*/, '').gsub('-', '_').to_sym
end

#to_sObject



68
69
70
# File 'lib/samovar/flags.rb', line 68

def to_s
	@text
end