Class: Aargvark::Argument

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg_array) ⇒ Argument

Returns a new instance of Argument.



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/aargvark.rb', line 156

def initialize (arg_array)
  @sub_args = []
  @subarg_range = [0,0]

  if arg_array.class != Array
    if arg_array.class == String
      if arg_array.is_arg?
        @letter = arg_array
      end 
    else
      raise ArgumentError, "\"#{arg_array}\" is not a valid argument.  Arguments and the details" +
                           " thereof must be entered as an Array in the format:" +
                           "[\"-n\", \"--argument-alias\", [true/false, :string/:integer/:float], etc...]"
    end
  else
    if arg_array[0].is_arg?
      @letter = arg_array[0]
    elsif arg_array[0].is_noarg?
      @noarg = true
    else
      raise ArgumentError, "The first item in each Argument array must be either a lowercase letter preceded by" +
                         " a hyphen or the symbol :noarg.  Please go back and make sure that your argument arrays conform to" +
                         " these standards."
    end
  end

  if arg_array.size > 1
    
    #If the second item in an argument array is an alias, set the alias for the
    #argument as that value.
    if arg_array[1].is_alias?
      @alias = arg_array[1]
    end

    if arg_array[1] == :required || arg_array[2] == :required
      @required = true
    else
      @required = false
    end
    
    first_subarg = 1
    if @alias
      first_subarg += 1
    end

    if @required
      first_subarg += 1
    end
    
    first_subarg.upto(arg_array.size - 1) do |x|
      if arg_array[x].is_subarg?
        @sub_args << arg_array[x]
      end
    end
  end

  @sub_args.each do |subarg|
    @subarg_range[0] += 1 if subarg.to_s == "true"
    @subarg_range[1] += 1
  end

end

Instance Attribute Details

#aliasObject

Returns the value of attribute alias.



154
155
156
# File 'lib/aargvark.rb', line 154

def alias
  @alias
end

#letterObject

Returns the value of attribute letter.



154
155
156
# File 'lib/aargvark.rb', line 154

def letter
  @letter
end

#noargObject

Returns the value of attribute noarg.



154
155
156
# File 'lib/aargvark.rb', line 154

def noarg
  @noarg
end

#requiredObject

Returns the value of attribute required.



154
155
156
# File 'lib/aargvark.rb', line 154

def required
  @required
end

#sub_argsObject

Returns the value of attribute sub_args.



154
155
156
# File 'lib/aargvark.rb', line 154

def sub_args
  @sub_args
end

#subarg_rangeObject

Returns the value of attribute subarg_range.



154
155
156
# File 'lib/aargvark.rb', line 154

def subarg_range
  @subarg_range
end