Class: PfrpgUtility::Effect
- Inherits:
-
Object
- Object
- PfrpgUtility::Effect
- Defined in:
- lib/pfrpg_utility/effect.rb
Instance Attribute Summary collapse
-
#affect ⇒ Object
Returns the value of attribute affect.
-
#key ⇒ Object
Returns the value of attribute key.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #apply(character) ⇒ Object
-
#initialize(type, key, value, affect = nil) ⇒ Effect
constructor
A new instance of Effect.
Constructor Details
#initialize(type, key, value, affect = nil) ⇒ Effect
Returns a new instance of Effect.
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/pfrpg_utility/effect.rb', line 3 def initialize(type, key, value, affect=nil) # standard effect proc; add a value basic = Proc.new do |character, attribute, value| character.bonuses.plus(attribute, value) end affect ||= basic @type = type @key = key @value = value @affect = affect end |
Instance Attribute Details
#affect ⇒ Object
Returns the value of attribute affect.
2 3 4 |
# File 'lib/pfrpg_utility/effect.rb', line 2 def affect @affect end |
#key ⇒ Object
Returns the value of attribute key.
2 3 4 |
# File 'lib/pfrpg_utility/effect.rb', line 2 def key @key end |
#type ⇒ Object
Returns the value of attribute type.
2 3 4 |
# File 'lib/pfrpg_utility/effect.rb', line 2 def type @type end |
#value ⇒ Object
Returns the value of attribute value.
2 3 4 |
# File 'lib/pfrpg_utility/effect.rb', line 2 def value @value end |
Class Method Details
.load(effects_string) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/pfrpg_utility/effect.rb', line 15 def self.load(effects_string) return effects_string if effects_string.instance_of? Array return [ effects_string ] if effects_string.instance_of? PfrpgUtility::Effect return [] if effects_string.nil? || effects_string.empty? unless effects_string.instance_of? String ap "Error effect: " ap effects_string end raise Exception unless effects_string.instance_of? String effects_string.split(";").map { |effect| parse_effect(effect) } end |
.parse_effect(string) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/pfrpg_utility/effect.rb', line 27 def self.parse_effect(string) p = string.split(":") type = p[0] key = p[1] value = p[2] PfrpgUtility::Effect.new(type, key, value) end |
Instance Method Details
#apply(character) ⇒ Object
35 36 37 |
# File 'lib/pfrpg_utility/effect.rb', line 35 def apply(character) @affect.call(character, @key, @value) end |