Top Level Namespace
Defined Under Namespace
Modules: Spoonacular
Instance Method Summary collapse
Instance Method Details
#querify(object) ⇒ Object
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/spoonacular/querify.rb', line 1 def querify(object) if object.is_a? String return object.gsub(/,\s?/, "%2C").gsub(" ", "+") elsif object.is_a? Array return object.join("%2C").gsub(" ", "+") elsif object.is_a? Hash result = [] object.each do |key, value| result << "#{to_camel_case(key.to_s)}=#{querify(value)}" end return result.join("&") end end |
#to_camel_case(string) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/spoonacular/querify.rb', line 15 def to_camel_case(string) string.chars.length.times do |i| if string[i] == "_" string[i+1] = string[i+1].upcase end end return string.delete "_" end |