Sha256: 818265d8faef910c04ba9f34a4803607c3cb307bed59a0e0df62dc840cefeec1

Contents?: true

Size: 624 Bytes

Versions: 7

Compression:

Stored size: 624 Bytes

Contents

module Poms
  class ScheduleEvent < Poms::Builder::NestedOpenStruct

    def initialize hash
      @hash = hash
      set_start_and_end_times
      super @hash
    end

    private

    def set_start_and_end_times
      set_starts_at
      set_ends_at
    end

    def set_starts_at
      @hash[:starts_at] = case @hash[:start]
        when String, Integer
          Time.at @hash[:start] / 1000
        when Time
          @hash[:start]
        end
    end

    def set_ends_at
      @hash['ends_at'] = @hash[:starts_at] + duration
    end

    def duration
      (@hash[:duration].to_i / 1000).seconds
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
poms-0.0.10 lib/poms/schedule_event.rb
poms-0.0.9 lib/poms/schedule_event.rb
poms-0.0.8 lib/poms/schedule_event.rb
poms-0.0.6 lib/poms/schedule_event.rb
poms-0.0.5 lib/poms/schedule_event.rb
poms-0.0.4 lib/poms/schedule_event.rb
poms-0.0.3 lib/poms/schedule_event.rb