Class: Fixnum

Inherits:
Object show all
Defined in:
lib/sugarcube/fixnum.rb

Instance Method Summary collapse

Instance Method Details

#after(date) ⇒ Object



43
44
45
# File 'lib/sugarcube/fixnum.rb', line 43

def after(date)
  date + self
end

#agoObject



39
40
41
# File 'lib/sugarcube/fixnum.rb', line 39

def ago
  self.before(NSDate.new)
end

#before(date) ⇒ Object



35
36
37
# File 'lib/sugarcube/fixnum.rb', line 35

def before(date)
  date - self
end

#henceObject



47
48
49
# File 'lib/sugarcube/fixnum.rb', line 47

def hence
  self.after(NSDate.new)
end

#nthObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sugarcube/fixnum.rb', line 18

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

#uicolor(alpha = nil) ⇒ Object

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)



8
9
10
11
12
13
14
15
16
# File 'lib/sugarcube/fixnum.rb', line 8

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