Sha256: 5624bbb45b6dfd332e29f11efffdb00e0834a20a25d6f4f7db9f5dc41272bf5a

Contents?: true

Size: 1 KB

Versions: 48

Compression:

Stored size: 1 KB

Contents

class Fixnum

  #     0xffffff.uicolor
  #     0xffffff.uicolor(0.33)
  # =>
  #     UIColor.colorWithRed(1.0, green:1.0, blue: 1.0, alpha:1.0)
  #     UIColor.colorWithRed(1.0, green:1.0, blue: 1.0, alpha:0.33)
  def uicolor(alpha=nil)
    alpha = 1.0 if alpha.nil?

    red = ((self & 0xFF0000) >> 16).to_f / 255.0
    green = ((self & 0xFF00) >> 8).to_f / 255.0
    blue = (self & 0xFF).to_f / 255.0

    UIColor.colorWithRed(red, green:green, blue:blue, alpha:alpha.to_f)
  end

  def nth
    # if the first two digits of rank are between 11 and 20, it's an
    # 'up-teenth' kinda number
    if self % 100 < 10 || self % 100 > 20
      case self % 10
      when 1
        return "st"
      when 2
        return "nd"
      when 3
        return "rd"
      end
    end

    return "th"
  end

  def ordinalize
    return "#{self}#{nth}"
  end

  def before(date)
    date - self
  end

  def ago
    self.before(NSDate.new)
  end

  def after(date)
    date + self
  end

  def hence
    self.after(NSDate.new)
  end

end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
sugarcube-0.18.5 lib/sugarcube/fixnum.rb
sugarcube-0.18.4 lib/sugarcube/fixnum.rb
sugarcube-0.18.3 lib/sugarcube/fixnum.rb
sugarcube-0.18.2 lib/sugarcube/fixnum.rb
sugarcube-0.18.1 lib/sugarcube/fixnum.rb
sugarcube-0.18.0 lib/sugarcube/fixnum.rb
sugarcube-0.16.9 lib/sugarcube/fixnum.rb
sugarcube-0.16.5 lib/sugarcube/fixnum.rb