Class: Ragol::ArgsList
- Inherits:
-
Object
- Object
- Ragol::ArgsList
- Defined in:
- lib/ragol/argslist.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
Instance Method Summary collapse
- #[](idx) ⇒ Object
- #args_empty? ⇒ Boolean
- #current_arg ⇒ Object
- #empty? ⇒ Boolean
- #end_of_options? ⇒ Boolean
- #eql?(args) ⇒ Boolean
-
#initialize(args = Array.new) ⇒ ArgsList
constructor
A new instance of ArgsList.
- #next_arg ⇒ Object
- #shift_arg ⇒ Object
Constructor Details
#initialize(args = Array.new) ⇒ ArgsList
Returns a new instance of ArgsList.
8 9 10 |
# File 'lib/ragol/argslist.rb', line 8 def initialize args = Array.new @args = args end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
6 7 8 |
# File 'lib/ragol/argslist.rb', line 6 def args @args end |
Instance Method Details
#[](idx) ⇒ Object
52 53 54 |
# File 'lib/ragol/argslist.rb', line 52 def [] idx @args[idx] end |
#args_empty? ⇒ Boolean
30 31 32 |
# File 'lib/ragol/argslist.rb', line 30 def args_empty? @args.empty? end |
#current_arg ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/ragol/argslist.rb', line 38 def current_arg curr = @args[0] re = Regexp.new('^-(?:\d+|\w)') if md = re.match(curr) md[0] else curr end end |
#empty? ⇒ Boolean
34 35 36 |
# File 'lib/ragol/argslist.rb', line 34 def empty? @args.empty? end |
#end_of_options? ⇒ Boolean
56 57 58 |
# File 'lib/ragol/argslist.rb', line 56 def current_arg == '--' end |
#eql?(args) ⇒ Boolean
48 49 50 |
# File 'lib/ragol/argslist.rb', line 48 def eql? args @args == args end |
#next_arg ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ragol/argslist.rb', line 12 def next_arg curr = @args.shift re = Regexp.new('^- (?:(\d+)(\D+) | ([a-zA-Z])(\w+) )', Regexp::EXTENDED) if md = re.match(curr) mi = md[1] ? 1 : 3 arg, newarg = ('-' + md[mi]), ('-' + md[mi + 1]) @args.unshift newarg arg else curr end end |
#shift_arg ⇒ Object
26 27 28 |
# File 'lib/ragol/argslist.rb', line 26 def shift_arg @args.shift end |