Sha256: 399f03068e72e5160d517650a719732524d3249aa122f4e3e8e2944eb0510ffc

Contents?: true

Size: 1014 Bytes

Versions: 10

Compression:

Stored size: 1014 Bytes

Contents

class Numeric

  def percent
    self / 100.0
  end

  def seconds
    self
  end
  alias second seconds

  def minutes
    self * 60
  end
  alias minute minutes

  def hours
    self * 3600
  end
  alias hour hours

  def days
    self.hours * 24
  end
  alias day days

  def weeks
    self.days * 7
  end
  alias week weeks

  def months
    self.days * 30
  end
  alias month months

  def years
    self.days * 365
  end
  alias year years

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

  def every(user_info=nil, &fire)
    NSTimer.scheduledTimerWithTimeInterval(self.to_f, 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

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
sugarcube-0.8.7 lib/sugarcube/numeric.rb
sugarcube-0.8.6 lib/sugarcube/numeric.rb
sugarcube-0.8.5 lib/sugarcube/numeric.rb
sugarcube-0.8.4 lib/sugarcube/numeric.rb
sugarcube-0.8.3 lib/sugarcube/numeric.rb
sugarcube-0.8.2 lib/sugarcube/numeric.rb
sugarcube-0.8.1 lib/sugarcube/numeric.rb
sugarcube-0.8 lib/sugarcube/numeric.rb
sugarcube-0.7.9 lib/sugarcube/numeric.rb
sugarcube-0.7.7 lib/sugarcube/numeric.rb