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.



8
9
10
11
12
# File 'lib/samovar/flags.rb', line 8

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

Instance Method Details

#boolean?Boolean

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

Returns:

  • (Boolean)


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

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

#countObject



27
28
29
# File 'lib/samovar/flags.rb', line 27

def count
	return @ordered.count
end

#each(&block) ⇒ Object



14
15
16
# File 'lib/samovar/flags.rb', line 14

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

#firstObject



18
19
20
# File 'lib/samovar/flags.rb', line 18

def first
	@ordered.first
end

#parse(input) ⇒ Object



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

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

#to_sObject



31
32
33
# File 'lib/samovar/flags.rb', line 31

def to_s
	"[#{@ordered.join(' | ')}]"
end