Module: SimpleSegment::Utils

Included in:
Batch, Client, Configuration, Operations::Operation
Defined in:
lib/simple_segment/utils.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



5
6
7
# File 'lib/simple_segment/utils.rb', line 5

def self.included(klass)
  klass.extend(self)
end

Instance Method Details

#isoify_dates(hash) ⇒ Object

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

strings


22
23
24
25
26
# 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) ⇒ Object

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



15
16
17
# File 'lib/simple_segment/utils.rb', line 15

def isoify_dates!(hash)
  hash.replace isoify_dates hash
end

#maybe_datetime_in_iso8601(prop) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
# 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) ⇒ Object



9
10
11
# File 'lib/simple_segment/utils.rb', line 9

def symbolize_keys(hash)
  hash.transform_keys(&:to_sym)
end