Class: Samovar::Flags
- Inherits:
-
Object
- Object
- Samovar::Flags
- Defined in:
- lib/samovar/flags.rb
Overview
Represents a collection of flag alternatives for an option.
Flags parse text like ‘-f/–flag <value>` into individual flag parsers.
Instance Method Summary collapse
-
#boolean? ⇒ Boolean
Whether this flag should have a true/false value if not specified otherwise.
-
#count ⇒ Object
The number of flag alternatives.
-
#each(&block) ⇒ Object
Iterate over each flag.
-
#first ⇒ Object
Get the first flag.
-
#initialize(text) ⇒ Flags
constructor
Initialize a new flags parser.
-
#parse(input) ⇒ Object
Parse a flag from the input.
-
#to_s ⇒ Object
Generate a string representation for usage output.
Constructor Details
Instance Method Details
#boolean? ⇒ Boolean
Whether this flag should have a true/false value if not specified otherwise.
37 38 39 |
# File 'lib/samovar/flags.rb', line 37 def boolean? @ordered.count == 1 and @ordered.first.boolean? end |
#count ⇒ Object
The number of flag alternatives.
44 45 46 |
# File 'lib/samovar/flags.rb', line 44 def count return @ordered.count end |
#each(&block) ⇒ Object
Iterate over each flag.
23 24 25 |
# File 'lib/samovar/flags.rb', line 23 def each(&block) @ordered.each(&block) end |
#first ⇒ Object
Get the first flag.
30 31 32 |
# File 'lib/samovar/flags.rb', line 30 def first @ordered.first end |
#parse(input) ⇒ Object
Parse a flag from the input.
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/samovar/flags.rb', line 59 def parse(input) @ordered.each do |flag| result = flag.parse(input) if result != nil return result end end return nil end |
#to_s ⇒ Object
Generate a string representation for usage output.
51 52 53 |
# File 'lib/samovar/flags.rb', line 51 def to_s "[#{@ordered.join(' | ')}]" end |