Class: Fixnum

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

Instance Method Summary collapse

Instance Method Details

#dayObject



30
31
32
# File 'lib/dgaff/fixnum.rb', line 30

def day
  return days
end

#daysObject



26
27
28
# File 'lib/dgaff/fixnum.rb', line 26

def days
  return self*60*60*24
end

#delimited(delimiter = ",") ⇒ Object



2
3
4
# File 'lib/dgaff/fixnum.rb', line 2

def delimited(delimiter=",")
  self.to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1#{delimiter}")
end

#generalized_time_factorObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dgaff/fixnum.rb', line 42

def generalized_time_factor
  if self < 60
    #one second
    return 1
  elsif self < 3600
    #one minute
    return 60
  elsif self < 86400
    #one hour
    return 3600
  elsif self < 604800
    #one day
    return 86400
  elsif self < 11536000
    #one week
    return 604800
  else 
    #four weeks
    return 2419200
  end
end

#percentage(round) ⇒ Object



6
7
8
# File 'lib/dgaff/fixnum.rb', line 6

def percentage(round)
  self.to_f.round(round)*10.to_s+"%"
end

#rounded_with_suffixObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dgaff/fixnum.rb', line 10

def rounded_with_suffix
  number_commafied = self.delimited.split(",")
  case number_commafied.length
  when 1
    return number_commafied.first
  when 2
    return number_commafied.first.length == 3 ? number_commafied.first+"K" : number_commafied.first+"."+number_commafied[1][0]+"K"
  when 3
    return number_commafied.first.length == 3 ? number_commafied.first+"M" : number_commafied.first+"."+number_commafied[1][0]+"M"
  when 4
    return number_commafied.first.length == 3 ? number_commafied.first+"B" : number_commafied.first+"."+number_commafied[1][0]+"B"
  when 5
    return number_commafied.first.length == 3 ? number_commafied.first+"T" : number_commafied.first+"."+number_commafied[1][0]+"T"
  end
end

#weekObject



38
39
40
# File 'lib/dgaff/fixnum.rb', line 38

def week
  return weeks
end

#weeksObject



34
35
36
# File 'lib/dgaff/fixnum.rb', line 34

def weeks
  return self*60*60*24*7
end