Class: Lich::Gemstone::Effects::Registry
- Inherits:
-
Object
- Object
- Lich::Gemstone::Effects::Registry
- Includes:
- Enumerable
- Defined in:
- documented/gemstone/effects.rb
Overview
Manages a collection of effects in the Lich system. This class includes methods to handle the registration and retrieval of effects.
Instance Method Summary collapse
-
#active?(effect) ⇒ Boolean
Checks if a given effect is currently active.
-
#each {|key, value| ... } ⇒ Enumerator
Iterates over each effect in the registry.
-
#expiration(effect) ⇒ Integer
Retrieves the expiration time of a given effect.
-
#initialize(dialog) ⇒ Registry
constructor
Initializes a new Registry instance.
-
#time_left(effect) ⇒ Float
Calculates the time left for a given effect.
-
#to_h ⇒ Hash
Converts the registry to a hash representation.
Constructor Details
#initialize(dialog) ⇒ Registry
Initializes a new Registry instance.
14 15 16 |
# File 'documented/gemstone/effects.rb', line 14 def initialize(dialog) @dialog = dialog end |
Instance Method Details
#active?(effect) ⇒ Boolean
Checks if a given effect is currently active.
45 46 47 |
# File 'documented/gemstone/effects.rb', line 45 def active?(effect) expiration(effect).to_f > Time.now.to_f end |
#each {|key, value| ... } ⇒ Enumerator
Iterates over each effect in the registry.
27 28 29 |
# File 'documented/gemstone/effects.rb', line 27 def each() to_h.each { |k, v| yield(k, v) } end |
#expiration(effect) ⇒ Integer
Retrieves the expiration time of a given effect.
34 35 36 37 38 39 40 |
# File 'documented/gemstone/effects.rb', line 34 def expiration(effect) if effect.is_a?(Regexp) to_h.find { |k, _v| k.to_s =~ effect }[1] || 0 else to_h.fetch(effect, 0) end end |
#time_left(effect) ⇒ Float
Calculates the time left for a given effect.
52 53 54 55 56 57 58 |
# File 'documented/gemstone/effects.rb', line 52 def time_left(effect) if expiration(effect) != 0 ((expiration(effect) - Time.now) / 60.to_f) else expiration(effect) end end |
#to_h ⇒ Hash
Converts the registry to a hash representation.
20 21 22 |
# File 'documented/gemstone/effects.rb', line 20 def to_h XMLData.dialogs.fetch(@dialog, {}) end |