Sha256: 7753611c787227a4b6acea102d792d56637bf03cc89f784f0274587fe192d4e5

Contents?: true

Size: 1.02 KB

Versions: 3

Compression:

Stored size: 1.02 KB

Contents

require 'active_support/concern'

module NetworkExecutive
  module Scheduling
    extend ActiveSupport::Concern

    def whats_on?( start_time = nil, stop_time = nil, options = {} )
      start_time ||= Time.now

      if stop_time
        with_showtimes_between( start_time, stop_time, options ) do |showtime, program|
          program = (block_given? ? yield(program) : program)

          { time:showtime, program:program }
        end
      else
        schedule.find_by_showtime start_time
      end
    end

    def with_showtimes_between( start, stop, options = {} )
      LineupRange.new( start, stop, options ).each_with_object([]) do |showtime, lineup|
        program = schedule.find_by_showtime showtime

        lineup << yield( showtime, program )
      end
    end

    def schedule
      self.class.schedule
    end

    module ClassMethods
      def schedule
        @schedule ||= ChannelSchedule.new
      end

      def every( date, options )
        schedule.add ProgramSchedule.new( date, options )
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
network_executive-0.0.4 lib/network_executive/scheduling.rb
network_executive-0.0.3 lib/network_executive/scheduling.rb
network_executive-0.0.2 lib/network_executive/scheduling.rb