class ElectricSlide::AgentStrategy::FixedPriority

Public Class Methods

new() click to toggle source
# File lib/electric_slide/agent_strategy/fixed_priority.rb, line 6
def initialize
  @priorities = {}
end

Public Instance Methods

<<(agent) click to toggle source
# File lib/electric_slide/agent_strategy/fixed_priority.rb, line 39
def <<(agent)
  raise ArgumentError, "Agents must have a specified priority" unless agent.respond_to?(:priority)

  priority = agent.priority || 999999
  @priorities[priority] ||= []

  unless @priorities[priority].include?(agent)
    delete(agent)
    @priorities[priority] << agent
  end
end
agent_available?() click to toggle source
# File lib/electric_slide/agent_strategy/fixed_priority.rb, line 10
def agent_available?
  !!@priorities.detect do |priority, agents|
    agents.present?
  end
end
available_agent_summary() click to toggle source

Returns information about the number of available agents The data returned depends on the AgentStrategy in use. @return [Hash] Summary information about agents available, depending on strategy :total: The total number of available agents :priorities: A Hash containing the number of available agents at each priority

# File lib/electric_slide/agent_strategy/fixed_priority.rb, line 21
def available_agent_summary
  @priorities.inject({}) do |summary, data|
    priority, agents = *data
    summary[:total] ||= 0
    summary[:total] += agents.count
    summary[:priorities] ||= {}
    summary[:priorities][priority] = agents.count
    summary
  end
end
checkout_agent() click to toggle source
# File lib/electric_slide/agent_strategy/fixed_priority.rb, line 32
def checkout_agent
  _, agents = @priorities.sort.detect do |priority, agents|
    agents.present?
  end
  agents.shift
end
delete(agent) click to toggle source
# File lib/electric_slide/agent_strategy/fixed_priority.rb, line 51
def delete(agent)
  @priorities.detect do |priority, agents|
    agents.delete(agent)
  end
end