class ShipHero::Util::Helpers
Public Class Methods
encode(str)
click to toggle source
Escape special characters @param [String] str
# File lib/ship_hero/util/helpers.rb, line 21 def encode(str) CGI.escape(str).gsub('.', '%2E').gsub('-', '%2D') end
http_build_query(params)
click to toggle source
Build the HTTP query from the given parameters @param [Hash] params @return [String] query string
# File lib/ship_hero/util/helpers.rb, line 15 def http_build_query(params) params.collect{ |k,v| "#{k}=#{encode(v)}" }.reverse.join('&') end
to_bool(str)
click to toggle source
String to bool @param [String] str
# File lib/ship_hero/util/helpers.rb, line 27 def to_bool(str) return true if str == true || str =~ (/(true|t|yes|y|1)$/i) return false if str == false || str == nil || str == '' || str =~ (/(false|f|no|n|0)$/i) end
to_date_time(str)
click to toggle source
String to DateTime @param [String] str
# File lib/ship_hero/util/helpers.rb, line 34 def to_date_time(str) begin Time.parse(str) rescue str end end