module SimpleSegment::Utils

Public Class Methods

included(klass) click to toggle source
# File lib/simple_segment/utils.rb, line 5
def self.included(klass)
  klass.extend(self)
end

Public Instance Methods

isoify_dates(hash) click to toggle source

public: Returns a new hash with all the date values in the into iso8601

strings
# File lib/simple_segment/utils.rb, line 22
def isoify_dates(hash)
  hash.transform_values do |v|
    maybe_datetime_in_iso8601(v)
  end
end
isoify_dates!(hash) click to toggle source

public: Converts all the date values in the into iso8601 strings in place

# File lib/simple_segment/utils.rb, line 15
def isoify_dates!(hash)
  hash.replace isoify_dates hash
end
maybe_datetime_in_iso8601(prop) click to toggle source
# File lib/simple_segment/utils.rb, line 28
def maybe_datetime_in_iso8601(prop)
  case prop
  when Time
    prop.iso8601(3)
  when DateTime
    prop.to_time.iso8601(3)
  when Date
    prop.strftime('%F')
  else
    prop
  end
end
symbolize_keys(hash) click to toggle source
# File lib/simple_segment/utils.rb, line 9
def symbolize_keys(hash)
  hash.transform_keys(&:to_sym)
end