Sha256: 5d7364e8d43cfaa0601b663947af9e932498db68b7cd4931e17fcfeb67f11547

Contents?: true

Size: 1.23 KB

Versions: 74

Compression:

Stored size: 1.23 KB

Contents

# -*- coding: utf-8 -*-

module Gren
  module DisplayUtil
    def time_s(time)
      t = time.truncate
      h = t / 3600
      t = t % 3600
      m = t / 60
      t = t % 60
      t += round(time - time.prec_i, 2)
      
      if (h > 0 && m > 0)
        "#{h}h #{m}m #{t}s"
      elsif (m > 0)
        "#{m}m #{t}s"
      else
        "#{t}sec"
      end
    end
    module_function :time_s

    def round(n, d)
      (n * 10 ** d).round / 10.0 ** d
    end
    module_function :round

    def size_s(size)
      tb = 1024 ** 4
      gb = 1024 ** 3
      mb = 1024 ** 2
      kb = 1024

      if (size >= tb)
        round(size / tb.prec_f, 2).to_s + "TB"
      elsif (size >= gb)
        round(size / gb.prec_f, 2).to_s + "GB"
      elsif (size >= mb)
        round(size / mb.prec_f, 2).to_s + "MB"
      elsif (size >= kb)
        round(size / kb.prec_f, 2).to_s + "KB"
      else
        size.to_s + "Byte"
      end
    end
    module_function :size_s

    def dump_methods(c)
      unless c.is_a?(Class)
        c = c.class
      end
      
      while (true)
        p c
        break if (c == Object)
        puts "↓  " + c.public_instance_methods(false).inspect
        c = c.superclass
      end
    end
    module_function :dump_methods
  end
end

Version data entries

74 entries across 74 versions & 3 rubygems

Version Path
milkode-1.8.9.2 lib/milkode/common/display_util.rb
milkode-1.8.9.1 lib/milkode/common/display_util.rb
milkode-1.8.9 lib/milkode/common/display_util.rb
milkode-1.8.8 lib/milkode/common/display_util.rb
milkode-1.8.7 lib/milkode/common/display_util.rb
milkode-1.8.6 lib/milkode/common/display_util.rb
milkode-1.8.5 lib/milkode/common/display_util.rb
milkode-1.8.4 lib/milkode/common/display_util.rb
milkode-1.8.3 lib/milkode/common/display_util.rb
milkode-1.8.2 lib/milkode/common/display_util.rb
milkode-1.8.1 lib/milkode/common/display_util.rb
milkode-1.8.0 lib/milkode/common/display_util.rb
milkode-1.7.1 lib/milkode/common/display_util.rb
milkode-1.7.0 lib/milkode/common/display_util.rb
milkode-1.6.1 lib/milkode/common/display_util.rb
milkode-1.6.0 lib/milkode/common/display_util.rb
milkode-1.5.0 lib/milkode/common/display_util.rb
milkode-1.4.0 lib/milkode/common/display_util.rb
milkode-1.3.0 lib/milkode/common/display_util.rb
milkode-1.2.0 lib/milkode/common/display_util.rb