Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#to_sizeObject



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

def to_size
  amount,unit = self.split(" ")
  if amount and unit
    case unit.downcase
    when "bytes","b","by"
      amount.to_i
    when "mb","megabytes","mbs","m","mi","mo"
      (amount.to_f * 1024).to_i
    when "gb","gigabytes","gbs","g","gi"
      (amount.to_f * 1024 * 1024).to_i
    else
      nil
    end
  else
    nil
  end
end

#to_timeObject



4
5
6
# File 'lib/core_ext/string.rb', line 4

def to_time
  Chronic.parse(self)
end