Top Level Namespace

Defined Under Namespace

Modules: HamlHelpers, JSON, Machinery, Rack Classes: MachineryHelper, NilClass, Object, Server, TeeIO

Instance Method Summary collapse

Instance Method Details

#number_to_human_size(s) ⇒ Object

Copyright © 2013-2016 SUSE LLC

This program is free software; you can redistribute it and/or modify it under the terms of version 3 of the GNU General Public License as published by the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, contact SUSE LLC.

To contact SUSE about this file by physical or electronic mail, you may find current contact information at www.suse.com



18
19
20
21
22
23
24
25
26
# File 'lib/renderer_helper.rb', line 18

def number_to_human_size(s)
  unit = %W(B KiB MiB GiB TiB)
  i = s.to_i

  exp = i != 0 ? Math.log(i, 1024).floor : 0
  value = (i / 1024.0 ** exp).round(1)

  "#{"%g" % value} #{unit[exp]}"
end

#with_c_locale(&block) ⇒ Object



58
59
60
# File 'lib/helper.rb', line 58

def with_c_locale(&block)
  with_env "LC_ALL" => "C", &block
end

#with_env(env) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/helper.rb', line 62

def with_env(env)
  # ENV isn't a Hash, but a weird Hash-like object. Calling #to_hash on it
  # will copy its items into a newly created Hash instance. This approach
  # ensures that any modifications of ENV won't affect the stored value.
  saved_env = ENV.to_hash
  begin
    ENV.replace(saved_env.merge(env))
    yield
  ensure
    ENV.replace(saved_env)
  end
end