Class: Samovar::Flags

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

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Flags

Returns a new instance of Flags.



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

def initialize(text)
	@text = text
	
	@ordered = text.split(/\s+\|\s+/).map{|part| Flag.new(part)}
end

Instance Method Details

#boolean?Boolean

Whether or not this flag should have a true/false value if not specified otherwise.

Returns:

  • (Boolean)


38
39
40
# File 'lib/samovar/flags.rb', line 38

def boolean?
	@ordered.count == 1 and @ordered.first.value.nil?
end

#countObject



42
43
44
# File 'lib/samovar/flags.rb', line 42

def count
	return @ordered.count
end

#each(&block) ⇒ Object



29
30
31
# File 'lib/samovar/flags.rb', line 29

def each(&block)
	@ordered.each(&block)
end

#firstObject



33
34
35
# File 'lib/samovar/flags.rb', line 33

def first
	@ordered.first
end

#parse(input) ⇒ Object



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

def parse(input)
	@ordered.each do |flag|
		if result = flag.parse(input)
			return result
		end
	end
	
	return nil
end

#to_sObject



46
47
48
# File 'lib/samovar/flags.rb', line 46

def to_s
	'[' + @ordered.join(' | ') + ']'
end