class Hash
Override ruby Hash
Obj
Attributes
get_url_params[RW]
Attr to be external accessible
Public Class Methods
from_xml(xml)
click to toggle source
# File lib/br_open_data/hash.rb, line 60 def self.from_xml(xml) Nori.new.parse xml end
Public Instance Methods
it_keys_to_get_param()
click to toggle source
Convert it keys to get params
# File lib/br_open_data/hash.rb, line 18 def it_keys_to_get_param self.it_keys_to_sym self.get_url_params = '?' 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 else param="#{key}=#{self[key]}" end self.get_url_params = self.get_url_params+param end # Remove the last char: & self.get_url_params = self.get_url_params[0..self.get_url_params.length-2] if self.get_url_params.index('\\') self.get_url_params end
it_keys_to_sym()
click to toggle source
Convert string keys to symbol keys
# File lib/br_open_data/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) self[key].each{|v| v.it_keys_to_sym if v.is_a?Hash} if self[key].is_a?Array 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/br_open_data/hash.rb, line 45 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