class Soapforce::Result

Attributes

raw_hash[R]

Public Class Methods

new(result_hash = {}) click to toggle source
# File lib/soapforce/result.rb, line 9
def initialize(result_hash = {})
  @raw_hash = result_hash
end

Public Instance Methods

[](index) click to toggle source
# File lib/soapforce/result.rb, line 13
def [](index)
  # If index is a symbol, try :field_name, "fieldName", "field_name"
  if index.is_a?(Symbol)
    if @raw_hash.key?(index)
      @raw_hash[index]
    elsif index.to_s.include?('_')
      camel_key = index.to_s.gsub(/\_(\w{1})/) { |cap| cap[1].upcase }
      @raw_hash[camel_key]
    else
      @raw_hash[index.to_s]
    end
  elsif index.is_a?(String)
    # If index is a String, try fieldName, :fieldName, :field_name
    if @raw_hash.key?(index)
      @raw_hash[index]
    elsif @raw_hash.key?(index.to_sym)
      @raw_hash[index.to_sym]
    else
      @raw_hash[index.snakecase.to_sym]
    end
  end
end