Class: Choosy::Parser
- Inherits:
-
Object
- Object
- Choosy::Parser
- Defined in:
- lib/choosy/parser.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#flags ⇒ Object
readonly
Returns the value of attribute flags.
-
#terminals ⇒ Object
readonly
Returns the value of attribute terminals.
Instance Method Summary collapse
-
#initialize(command, lazy = nil, terminals = nil) ⇒ Parser
constructor
A new instance of Parser.
- #lazy? ⇒ Boolean
- #parse!(argv, result = nil) ⇒ Object
Constructor Details
#initialize(command, lazy = nil, terminals = nil) ⇒ Parser
Returns a new instance of Parser.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/choosy/parser.rb', line 5 def initialize(command, lazy=nil, terminals=nil) @command = command @lazy = lazy || false @terminals = terminals || [] @flags = {} return if command..nil? command..each do |o| verify_option(o) end end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
3 4 5 |
# File 'lib/choosy/parser.rb', line 3 def command @command end |
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
3 4 5 |
# File 'lib/choosy/parser.rb', line 3 def flags @flags end |
#terminals ⇒ Object (readonly)
Returns the value of attribute terminals.
3 4 5 |
# File 'lib/choosy/parser.rb', line 3 def terminals @terminals end |
Instance Method Details
#lazy? ⇒ Boolean
43 44 45 |
# File 'lib/choosy/parser.rb', line 43 def lazy? @lazy end |
#parse!(argv, result = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/choosy/parser.rb', line 17 def parse!(argv, result=nil) index = 0 result ||= ParseResult.new(@command, false) while index < argv.length case argv[index] when '-' if lazy? result.unparsed << '-' index += 1 else raise Choosy::ParseError.new("Unfinished option '-'") end when '--' result.unparsed << '--' if lazy? index = parse_rest(argv, index, result) when /^-/ index = parse_option(argv, index, result) else index = parse_arg(argv, index, result) end end result end |