Sha256: 5ac61e59c6741b8cc12227b80b2fc6dc6e759175899f57049ef031cd3eeb64c0

Contents?: true

Size: 887 Bytes

Versions: 4

Compression:

Stored size: 887 Bytes

Contents

require "shifty/roster"
require "shifty/taggable"

module Shifty
  class Gang
    attr_reader :roster, :tags

    include Taggable

    def initialize(workers = [], p = {})
      @roster = Roster.new(workers)
      self.criteria = p[:criteria]
      self.tags     = p[:tags]
    end

    def shift
      if criteria_passes?
        roster.last.shift
      else
        roster.first.supply.shift
      end
    end

    def ready_to_work?
      roster.first.ready_to_work?
    end

    def supply
      roster.first.supply
    end

    def supply=(supplier)
      roster.first.supply = supplier
    end

    def supplies(subscribing_worker)
      subscribing_worker.supply = self
      subscribing_worker
    end
    alias_method :|, :supplies

    def append(worker)
      roster << worker
    end

    class << self
      def [](*workers)
        new workers
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
shifty-0.5.0 lib/shifty/gang.rb
shifty-0.4.2 lib/shifty/gang.rb
shifty-0.4.1 lib/shifty/gang.rb
shifty-0.4.0 lib/shifty/gang.rb