Class: Separatum::Processors::TimeMachine

Inherits:
Object
  • Object
show all
Defined in:
lib/separatum/processors/time_machine.rb

Instance Method Summary collapse

Instance Method Details

#call(*hashes) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/separatum/processors/time_machine.rb', line 6

def call(*hashes)
  time_current = Time.now
  hashes.flatten.map do |hash|
    if hash.key?(:_time_machine)
      time_offset = time_current - Time.parse(hash[:_time_machine])
      new_hash = {}
      hash.each do |k, v|
        if k == :_time_machine
          next
        elsif (time = (Time.parse(v) rescue nil))
          new_hash[k] = (time + time_offset).to_s
        else
          new_hash[k] = v
        end
      end
      new_hash
    else
      hash
    end
  end
end