class Trooper::Arsenal

Public Class Methods

actions() click to toggle source

Public: Storage for the defined actions.

Examples

Arsenal.actions # => [<Action>, <Action>]

Returns the actions arsenal.

# File lib/trooper/arsenal.rb, line 81
def actions
  @actions ||= new
end
reset!() click to toggle source

Public: Clears the arsenals storage of all strategies and actions.

Examples

Arsenal.reset! # => true

Returns true.

# File lib/trooper/arsenal.rb, line 92
def reset!
  @strategies, @actions = nil
  true
end
strategies() click to toggle source

Public: Storage for the defined strategies.

Examples

Arsenal.strategies # => [<Strategy>, <Strategy>]

Returns the strategies arsenal.

# File lib/trooper/arsenal.rb, line 70
def strategies
  @strategies ||= new
end

Public Instance Methods

[](name)
Alias for: find_by_name
add(weapon) click to toggle source

Public: Add a 'weapon' to the arsenal.

weapon - An object that responds to a name method e.g 'weapon.name' .

Examples

Arsenal.actions.add(<Action>) # => <Action>

Returns the weapon passed.

# File lib/trooper/arsenal.rb, line 29
def add(weapon)
  if weapon.ok?
    remove weapon.name
    self << weapon 
  end
  weapon
end
clear!() click to toggle source

Public: Clears the arsenals storage array.

Examples

Arsenal.strategies.clear! # => []

Returns an empty array.

# File lib/trooper/arsenal.rb, line 57
def clear!
  self.clear
end
find_by_name(name) click to toggle source

Public: Find an item in the arsenal.

name - The name of the weapon object, weapon object must respond to name.

Examples

Arsenal.strategies.find_by_name(:my_stratergy) # => <Strategy>
Arsenal.strategies[:my_stratergy] # => <Strategy>

Returns the duplicated String.

# File lib/trooper/arsenal.rb, line 15
def find_by_name(name)
  detect { |weapon| weapon.name == name }
end
Also aliased as: []
remove(name) click to toggle source

Public: Removes a 'weapon' from the arsenal.

name - The name of the arsenal to delete.

Examples

Arsenal.actions.remove(:my_action) # => [<Action>]

Returns self.

# File lib/trooper/arsenal.rb, line 46
def remove(name)
  self.delete_if {|w| w.name == name}
end