Sha256: d82ee3701e0f3e70c7bce240aceefbc56b816551402ccdc53ac00ec7d99d780f

Contents?: true

Size: 708 Bytes

Versions: 2

Compression:

Stored size: 708 Bytes

Contents

require "conference_tracker/talk"
require "conference_tracker/track"

module ConferenceTracker
  class Scheduler
    TRACK = "Track"

    def initialize(talks, talk = Talk, track = Track)
      @talks = talk.bulk(talks.to_a).sort { |a,b| b.to_i <=> a.to_i }
      @track = track
    end

    def call
      collect.to_a.reject(&:empty?).each_with_index.map do |track, i|
        track.name = "#{TRACK} #{i+1}:"
        track.schedule << ""
      end
    end

    private def collect
      return if @talks.empty?
      @talks.reduce([]) do |tracks, talk|
        tracks.each { |track| track.add(talk) }
        tracks << @track.new.add(talk) unless talk.scheduled?
        tracks
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
conference_tracker-1.1.1 lib/conference_tracker/scheduler.rb
conference_tracker-1.1.0 lib/conference_tracker/scheduler.rb