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.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/choosy/parser.rb', line 9 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.
7 8 9 |
# File 'lib/choosy/parser.rb', line 7 def command @command end |
#flags ⇒ Object (readonly)
Returns the value of attribute flags.
7 8 9 |
# File 'lib/choosy/parser.rb', line 7 def flags @flags end |
#terminals ⇒ Object (readonly)
Returns the value of attribute terminals.
7 8 9 |
# File 'lib/choosy/parser.rb', line 7 def terminals @terminals end |
Instance Method Details
#lazy? ⇒ Boolean
47 48 49 |
# File 'lib/choosy/parser.rb', line 47 def lazy? @lazy end |
#parse!(argv, result = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/choosy/parser.rb', line 21 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 |