Module: Wonkavision::Plugins::Timeline::ClassMethods

Defined in:
lib/wonkavision/plugins/timeline.rb

Instance Method Summary collapse

Instance Method Details

#convert_time(time) ⇒ Object



53
54
55
56
57
58
# File 'lib/wonkavision/plugins/timeline.rb', line 53

def convert_time(time)
  if (time.is_a?(Hash)) && (time.keys.include?(:date) || time.keys.include?(:time))
    time = "#{time[:date]} #{time[:time]}".strip
  end
  time ? time.to_time : nil
end

#extract_event_time(event_data, event_path) ⇒ Object



60
61
62
# File 'lib/wonkavision/plugins/timeline.rb', line 60

def extract_event_time(event_data,event_path)
  convert_time(event_data.delete(event_time_key.to_s)) || Time.now.utc
end

#milestone(name, *args) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/wonkavision/plugins/timeline.rb', line 29

def milestone(name,*args)
  timeline_milestones << event(name,*args) do
    ctx = @wonkavision_event_context
    event_time = self.class.extract_event_time(ctx.data,ctx.path)
    prev_event_time = self[timeline_field][name]
    unless prev_event_time
      self[timeline_field][name] = event_time
      #If the event being processed happened earlier than a previously
      #recorded event, we don't want to overwrite state of the activity, as
      #it is already more up to date than the incoming event.
      latest_ms = self[latest_milestone_field]
      unless latest_ms &&
                     (last_event = self[timeline_field][latest_ms]) &&
                     last_event > event_time
        self.class.update_activity(self,ctx.data)
        self[latest_milestone_field] = name
      end
      :updated
    else
      :handled #If there was a previous event time for this milestone, we will just skip this event
    end
  end
end