Sha256: c5aafb38f46ec2deb24bb69f30432a4d970fa9e3e62c47fa8487569c22ea3cc1

Contents?: true

Size: 727 Bytes

Versions: 5

Compression:

Stored size: 727 Bytes

Contents

# -*- coding: utf-8 -*-
module Cinch
  module Plugin
    # An alteration to the Plugin Module to allow for configurable cooldowns.
    class Cooldown
      attr_accessor :time, :duration, :expires_at

      def initialize(duration, time = Time.now)
        @time = time
        @duration = duration
        @expires_at = @time + @duration
      end

      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

      def time_till_expire
        period = @expires_at - Time.now
        return 0 if period < 0
        period
      end

      def cooled_down?
        time_till_expire.zero?
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
cinch-cooldown-1.2.1 lib/cinch/plugin/cooldown.rb
cinch-cooldown-1.2.0 lib/cinch/plugin/cooldown.rb
cinch-cooldown-1.1.7 lib/cinch/plugin/cooldown.rb
cinch-cooldown-1.1.5 lib/cinch/plugin/cooldown.rb
cinch-cooldown-1.1.3 lib/cinch/plugin/cooldown.rb