Top Level Namespace

Defined Under Namespace

Classes: Aargvark, String, Symbol

Instance Method Summary collapse

Instance Method Details

#is_subarg?(throw_errors = true) ⇒ Boolean

Returns:

  • (Boolean)


256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/aargvark.rb', line 256

def is_subarg?(throw_errors = true)
  if self.class != Array
    return false
    if throw_errors
      raise ArgumentError, "Sub-arguments must be entered as an array, in the format:"
                           + "[true/false, :string/:integer/:float]"
    end
  else
    has_true_false = self[0].to_s.match(/^true|false$/)
    result = self[1].to_s.match(/^string|integer|float$/)
    has_subarg_type = result && self[1].class == Symbol ? true : false
    if ! has_true_false
      return false
      if throw_errors
        raise ArgumentError, "The first value in each sub-argument array must be either 'true' or 'false'"
      end
    elsif ! has_subarg_type
      return false
      if throw_errors
        raise ArgumentError, "The second value in each sub-argument array must be either :string, :integer or :float"
      end
    else
      return true
    end
  end
end