class Fuelcell::Action::ArgResults

Attributes

map[R]
raw[R]

Public Class Methods

new(array, hash) click to toggle source
# File lib/fuelcell/action/arg_results.rb, line 8
def initialize(array, hash)
  @raw, @map = validate_results(array, hash)
end

Public Instance Methods

[](key) click to toggle source
# File lib/fuelcell/action/arg_results.rb, line 13
def [](key)
  return raw[key] if key.is_a?(Integer)
  value(key)
end

Protected Instance Methods

index(key) click to toggle source
# File lib/fuelcell/action/arg_results.rb, line 36
def index(key)
  map[key]
end
index?(key) click to toggle source
# File lib/fuelcell/action/arg_results.rb, line 32
def index?(key)
  map.key?(key)
end
method_missing(method, *args, &_block) click to toggle source
# File lib/fuelcell/action/arg_results.rb, line 21
def method_missing(method, *args, &_block)
  method = method.to_s
  return map.key?(method.chomp('?')) if method[-1] == '?'
  value(method)
end
value(key) click to toggle source
# File lib/fuelcell/action/arg_results.rb, line 27
def value(key)
  return nil unless index?(key)
  raw[index(key)]
end

Private Instance Methods

validate_results(array, hash) click to toggle source
# File lib/fuelcell/action/arg_results.rb, line 42
def validate_results(array, hash)
  hash.each do |(key, value)|
    unless value.is_a?(Integer)
      fail ArgumentError, "hash value for #{key} must be an integer"
    end

    unless array.at(value)
      fail ArgumentError,
            "arg definition #{key} does not point to value in args array"
    end
  end
  [array, hash]
end