Class: Integer

Inherits:
Object show all
Defined in:
lib/overload/integer.rb,
lib/common/string_base.rb

Instance Method Summary collapse

Instance Method Details

#dottedObject



12
13
14
# File 'lib/overload/integer.rb', line 12

def dotted
  self.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1.').reverse
end

#pluralize(desc) ⇒ Object



2
3
4
5
6
7
8
9
10
# File 'lib/overload/integer.rb', line 2

def pluralize desc
  if self == 0
    "no #{desc.to_s.pluralize}"
  elsif self == 1
    "#{self} #{desc}"
  else
    "#{self.dotted} #{desc.to_s.pluralize}"
  end
end

#string_idObject



75
76
77
# File 'lib/common/string_base.rb', line 75

def string_id
  StringBase.encode self
end

#to_filesizeObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/overload/integer.rb', line 16

def to_filesize
  base = 1024
  out = lambda do
    {
      'B'  => base,
      'KB' => base * base,
      'MB' => base * base * base,
      'GB' => base * base * base * base,
      'TB' => base * base * base * base * base
    }.each_pair { |e, s| return "#{(self.to_f / (s / base)).round(1)} #{e}" if self < s }
  end.call

  out.sub('.0 B', ' B')
end