Sha256: 50cc9fb1d3213caec0c7f7330c464c2041169c019d80207ea1ef5748d738aebe

Contents?: true

Size: 763 Bytes

Versions: 6

Compression:

Stored size: 763 Bytes

Contents

module Poms
  # POMS wrapper for a single scheduled broadcast.
  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

6 entries across 6 versions & 1 rubygems

Version Path
poms-1.2.2 lib/poms/schedule_event.rb
poms-1.2.1 lib/poms/schedule_event.rb
poms-1.2.0 lib/poms/schedule_event.rb
poms-1.1.0 lib/poms/schedule_event.rb
poms-1.0.1 lib/poms/schedule_event.rb
poms-1.0.0 lib/poms/schedule_event.rb