Module: Util
- Defined in:
- lib/analytics-ruby/util.rb
Class Method Summary collapse
-
.isoify_dates(hash) ⇒ Object
public: Returns a new hash with all the date values in the into iso8601 strings.
-
.isoify_dates!(hash) ⇒ Object
public: Converts all the date values in the into iso8601 strings in place.
-
.stringify_keys(hash) ⇒ Object
public: Return a new hash with keys as strings.
-
.symbolize_keys(hash) ⇒ Object
public: Return a new hash with keys converted from strings to symbols.
-
.symbolize_keys!(hash) ⇒ Object
public: Convert hash keys from strings to symbols in place.
-
.uid ⇒ Object
public: Returns a uid string.
Class Method Details
.isoify_dates(hash) ⇒ Object
public: Returns a new hash with all the date values in the into iso8601
strings
24 25 26 27 28 29 |
# File 'lib/analytics-ruby/util.rb', line 24 def self.isoify_dates(hash) hash.inject({}) { |memo, (k, v)| memo[k] = v.respond_to?(:iso8601) ? v.iso8601 : v memo } end |
.isoify_dates!(hash) ⇒ Object
public: Converts all the date values in the into iso8601 strings in place
33 34 35 |
# File 'lib/analytics-ruby/util.rb', line 33 def self.isoify_dates!(hash) hash.replace isoify_dates hash end |
.stringify_keys(hash) ⇒ Object
public: Return a new hash with keys as strings
17 18 19 |
# File 'lib/analytics-ruby/util.rb', line 17 def self.stringify_keys(hash) hash.inject({}) { |memo, (k,v)| memo[k.to_s] = v; memo } end |
.symbolize_keys(hash) ⇒ Object
public: Return a new hash with keys converted from strings to symbols
5 6 7 |
# File 'lib/analytics-ruby/util.rb', line 5 def self.symbolize_keys(hash) hash.inject({}) { |memo, (k,v)| memo[k.to_sym] = v; memo } end |
.symbolize_keys!(hash) ⇒ Object
public: Convert hash keys from strings to symbols in place
11 12 13 |
# File 'lib/analytics-ruby/util.rb', line 11 def self.symbolize_keys!(hash) hash.replace symbolize_keys hash end |
.uid ⇒ Object
public: Returns a uid string
39 40 41 |
# File 'lib/analytics-ruby/util.rb', line 39 def self.uid (0..16).to_a.map{|x| rand(16).to_s(16)}.join end |