Class: Agent
- Inherits:
-
Object
- Object
- Agent
- Includes:
- DataMapper::Resource
- Defined in:
- lib/swarm/agent.rb
Class Method Summary collapse
-
.available ⇒ Object
Unique available agents.
-
.unique ⇒ Object
Unique agents.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Check if other equals self.
-
#busy? ⇒ Boolean
Check if the agent is busy.
-
#initialize(string_or_attrs) ⇒ Agent
constructor
Initialize with string_or_attrs.
Constructor Details
#initialize(string_or_attrs) ⇒ Agent
Initialize with string_or_attrs.
32 33 34 35 36 |
# File 'lib/swarm/agent.rb', line 32 def initialize string_or_attrs self.attributes = String === string_or_attrs ? { :string => string_or_attrs } : string_or_attrs end |
Class Method Details
.available ⇒ Object
Unique available agents.
74 75 76 |
# File 'lib/swarm/agent.rb', line 74 def self.available unique.delete_if { |agent| agent.busy? } end |
.unique ⇒ Object
Unique agents.
64 65 66 67 68 69 |
# File 'lib/swarm/agent.rb', line 64 def self.unique all.inject [] do |agents, agent| agents << agent unless agents.include? agent agents end end |
Instance Method Details
#==(other) ⇒ Object
Check if other equals self. Supports DataMapper join support when checking AgentJob equality, as well as against other Agent instances via their #string value.
44 45 46 47 48 |
# File 'lib/swarm/agent.rb', line 44 def == other AgentJob === other ? id == other.agent_id : super end |
#busy? ⇒ Boolean
Check if the agent is busy.
53 54 55 |
# File 'lib/swarm/agent.rb', line 53 def busy? busy end |