Sha256: c178e805e4859b75b22c12f5408edbfaeaad1b54e5e5518f88b3a1f0669c6553

Contents?: true

Size: 1.68 KB

Versions: 20

Compression:

Stored size: 1.68 KB

Contents

class Numeric
  def milliseconds
    self / 1000.0
  end
  alias millisecond milliseconds
  alias millisecs milliseconds
  alias millisec milliseconds

  def in_milliseconds
    self * 1000
  end

  def seconds
    self
  end
  alias second seconds
  alias sec seconds
  alias secs seconds

  def in_seconds
    self
  end

  def minutes
    self * 60
  end
  alias minute minutes
  alias min minutes
  alias mins minutes

  def in_minutes
    self / 1.minute.to_f
  end

  def hours
    self * 3600
  end
  alias hour hours

  def in_hours
    self / 1.hour.to_f
  end

  def days
    self.hours * 24
  end
  alias day days

  def in_days
    self / 1.day.to_f
  end

  def weeks
    self.days * 7
  end
  alias week weeks

  def in_weeks
    self / 1.week.to_f
  end

  def months
    self.days * 30
  end
  alias month months

  def in_months
    self / 1.month.to_f
  end

  def years
    self.days * 365
  end
  alias year years

  def in_years
    self / 1.year.to_f
  end

  def later(user_info=nil, &fire)
    NSTimer.scheduledTimerWithTimeInterval(self, target: fire, selector: 'call:', userInfo: user_info, repeats: false)
  end

  def every(user_info=nil, &fire)
    NSTimer.scheduledTimerWithTimeInterval(self, target: fire, selector: 'call:', userInfo: user_info, repeats: true)
  end
end


module SugarCube
  module Timer
    module_function

    def every(time, user_info=nil, &fire)
      time.every user_info, &fire
    end

    def after(time, user_info=nil, &fire)
      time.later user_info, &fire
    end
  end
end


class NSTimer
  def self.every(time, user_info=nil, &fire)
    time.every user_info, &fire
  end

  def self.after(time, user_info=nil, &fire)
    time.later user_info, &fire
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
sugarcube-1.0.4 lib/sugarcube-timer/timer.rb
sugarcube-1.0.3 lib/sugarcube-timer/timer.rb
sugarcube-1.0.2 lib/sugarcube-timer/timer.rb
sugarcube-1.0.1 lib/sugarcube-timer/timer.rb
sugarcube-1.0.0 lib/sugarcube-timer/timer.rb
sugarcube-0.20.25 lib/sugarcube/timer.rb
sugarcube-0.20.24 lib/sugarcube/timer.rb
sugarcube-0.20.23 lib/sugarcube/timer.rb
sugarcube-0.20.22 lib/sugarcube/timer.rb
sugarcube-0.20.21 lib/sugarcube/timer.rb
sugarcube-0.20.20 lib/sugarcube/timer.rb
sugarcube-0.20.19 lib/sugarcube/timer.rb
sugarcube-0.20.18 lib/sugarcube/timer.rb
sugarcube-0.20.17 lib/sugarcube/timer.rb
sugarcube-0.20.16 lib/sugarcube/timer.rb
sugarcube-0.20.15 lib/sugarcube/timer.rb
sugarcube-0.20.13 lib/sugarcube/timer.rb
sugarcube-0.20.12 lib/sugarcube/timer.rb
sugarcube-0.20.11 lib/sugarcube/timer.rb
sugarcube-0.20.10 lib/sugarcube/timer.rb