Class: Ragol::ArgsList

Inherits:
Object
  • Object
show all
Defined in:
lib/ragol/argslist.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#argsObject

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

Returns:

  • (Boolean)


30
31
32
# File 'lib/ragol/argslist.rb', line 30

def args_empty?
  @args.empty?
end

#current_argObject



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

Returns:

  • (Boolean)


34
35
36
# File 'lib/ragol/argslist.rb', line 34

def empty?
  @args.empty?
end

#end_of_options?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/ragol/argslist.rb', line 56

def end_of_options?
  current_arg == '--'
end

#eql?(args) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/ragol/argslist.rb', line 48

def eql? args
  @args == args
end

#next_argObject



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_argObject



26
27
28
# File 'lib/ragol/argslist.rb', line 26

def shift_arg
  @args.shift
end