Class: ShipHero::Util::Helpers
- Inherits:
-
Object
- Object
- ShipHero::Util::Helpers
- Defined in:
- lib/ship_hero/util/helpers.rb
Class Method Summary collapse
-
.encode(str) ⇒ Object
Escape special characters.
-
.http_build_query(params) ⇒ String
Build the HTTP query from the given parameters.
-
.to_bool(str) ⇒ Object
String to bool.
-
.to_date_time(str) ⇒ Object
String to DateTime.
Class Method Details
.encode(str) ⇒ Object
Escape special characters
21 22 23 |
# File 'lib/ship_hero/util/helpers.rb', line 21 def encode(str) CGI.escape(str).gsub('.', '%2E').gsub('-', '%2D') end |
.http_build_query(params) ⇒ String
Build the HTTP query from the given parameters
15 16 17 |
# 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) ⇒ Object
String to bool
27 28 29 30 |
# 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) ⇒ Object
String to DateTime
34 35 36 37 38 39 40 |
# File 'lib/ship_hero/util/helpers.rb', line 34 def to_date_time(str) begin Time.parse(str) rescue str end end |