Class: Cinch::Plugin::Cooldown
- Inherits:
-
Object
- Object
- Cinch::Plugin::Cooldown
- Defined in:
- lib/cinch/plugin/cooldown.rb
Overview
An alteration to the Plugin Module to allow for configurable cooldowns.
Instance Attribute Summary collapse
-
#duration ⇒ Object
Returns the value of attribute duration.
-
#expires_at ⇒ Object
Returns the value of attribute expires_at.
-
#time ⇒ Object
Returns the value of attribute time.
Instance Method Summary collapse
- #cooled_down? ⇒ Boolean
-
#initialize(duration, time = Time.now) ⇒ Cooldown
constructor
A new instance of Cooldown.
- #time_till_expire ⇒ Object
- #time_till_expire_in_words ⇒ Object
Constructor Details
#initialize(duration, time = Time.now) ⇒ Cooldown
Returns a new instance of Cooldown.
8 9 10 11 12 |
# File 'lib/cinch/plugin/cooldown.rb', line 8 def initialize(duration, time = Time.now) @time = time @duration = duration @expires_at = @time + @duration end |
Instance Attribute Details
#duration ⇒ Object
Returns the value of attribute duration.
6 7 8 |
# File 'lib/cinch/plugin/cooldown.rb', line 6 def duration @duration end |
#expires_at ⇒ Object
Returns the value of attribute expires_at.
6 7 8 |
# File 'lib/cinch/plugin/cooldown.rb', line 6 def expires_at @expires_at end |
#time ⇒ Object
Returns the value of attribute time.
6 7 8 |
# File 'lib/cinch/plugin/cooldown.rb', line 6 def time @time end |
Instance Method Details
#cooled_down? ⇒ Boolean
25 26 27 |
# File 'lib/cinch/plugin/cooldown.rb', line 25 def cooled_down? time_till_expire.zero? end |
#time_till_expire ⇒ Object
19 20 21 22 23 |
# File 'lib/cinch/plugin/cooldown.rb', line 19 def time_till_expire period = @expires_at - Time.now return 0 if period < 0 period end |
#time_till_expire_in_words ⇒ Object
14 15 16 17 |
# File 'lib/cinch/plugin/cooldown.rb', line 14 def time_till_expire_in_words return 'until right now' if (expires_at - Time.now) < 0 TimeLord::Period.new(expires_at, Time.now).to_words end |