Module: Hungry::Util
Instance Method Summary collapse
- #is_numeric?(value) ⇒ Boolean
- #log(message, type = :info) ⇒ Object
- #params_from_uri(uri) ⇒ Object
- #parse_json(json) ⇒ Object
- #uri_with_params(uri, params = {}) ⇒ Object
Instance Method Details
#is_numeric?(value) ⇒ Boolean
32 33 34 |
# File 'lib/hungry/util.rb', line 32 def is_numeric?(value) !!(value.to_s =~ /^[+-]?[\d]+(\.[\d]+){0,1}$/) end |
#log(message, type = :info) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/hungry/util.rb', line 7 def log(, type = :info) if Hungry.logger = "[Hungry] #{}" Hungry.logger.send(type, ) end end |
#params_from_uri(uri) ⇒ Object
18 19 20 21 |
# File 'lib/hungry/util.rb', line 18 def params_from_uri(uri) uri = URI.parse(uri) unless uri.is_a?(URI) parse_query(uri.query) if uri.query.present? end |
#parse_json(json) ⇒ Object
14 15 16 |
# File 'lib/hungry/util.rb', line 14 def parse_json(json) Hungry.json_parser.call(json) end |
#uri_with_params(uri, params = {}) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/hungry/util.rb', line 23 def uri_with_params(uri, params = {}) params = params.map { |k,v| "#{k}=#{CGI.escape(v.to_s)}" } .join('&') .presence [uri, params].compact .join('?') end |