class Hash

Overwrite ruby Hash Obj

Attributes

get_url_params[RW]

Attr to be external accessible

Public Instance Methods

it_keys_to_get_param() click to toggle source

Convert it keys to get params

# File lib/nitro_pay/hash.rb, line 25
def it_keys_to_get_param
  self.it_keys_to_sym
  self.get_url_params = '?' if self.get_url_params.nil?

  self.keys.each do |key|
    self.get_url_params = self.get_url_params+'&' unless self.get_url_params.length == 1

    # Nested obj_attrs
    if self[key].is_a?(Hash)
      hash_name = key
      hash_obj = self[key]

      # Hash to GET URL
      param = to_nested_get_param hash_name, hash_obj
    end

    self.get_url_params = self.get_url_params+param
  end

  # Remove the last char: &
  return self.get_url_params[0..self.get_url_params.length-2]
end
it_keys_to_sym() click to toggle source

Convert string keys to symbol keys

# File lib/nitro_pay/hash.rb, line 7
def it_keys_to_sym
  self.keys.each do |key|
    self[key].it_keys_to_sym if self[key].is_a?(Hash)

    if self[key].is_a?(Array)
      hashes = self[key]
      hashes.each do |current_hash|
        current_hash.it_keys_to_sym
      end
    end

    self[(key.to_sym rescue key) || key] = self.delete(key)
  end

  return self
end
to_nested_get_param(hash_name, hash_obj) click to toggle source

SetUp a hash to hash URL GET

# File lib/nitro_pay/hash.rb, line 49
def to_nested_get_param(hash_name, hash_obj)
  # initial value
  get_nested_params = ''

  # foreach keys to mount the URL_PARAM
  hash_obj.keys.each do |key|
    key_param = hash_obj[key].to_nested_get_param key, hash_obj[key] if hash_obj[key].is_a?(Hash)
    key_param = "#{hash_name}[#{key}]=#{hash_obj[key]}&" unless hash_obj[key].is_a?(Hash)
    get_nested_params = get_nested_params+key_param
  end

  # return
  get_nested_params
end