Module: ClickHouse::Util::Pretty

Defined in:
lib/click_house/util/pretty.rb

Constant Summary collapse

SIZE_UNITS =
%w[B KiB MiB GiB TiB Pib EiB].freeze

Class Method Summary collapse

Class Method Details

.measure(ms) ⇒ Object

rubocop:enable all


21
22
23
# File 'lib/click_house/util/pretty.rb', line 21

def measure(ms)
  "#{ms.round}MS"
end

.size(bytes) ⇒ Object

rubocop:disable all


11
12
13
14
15
16
17
18
# File 'lib/click_house/util/pretty.rb', line 11

def size(bytes)
  return '0B' if bytes == 0

  exp = (Math.log(bytes) / Math.log(1024)).to_i
  exp = 6 if exp > 6

  format('%.1f%s', bytes.to_f / 1024**exp, SIZE_UNITS[exp])
end

.squish(string) ⇒ Object


25
26
27
# File 'lib/click_house/util/pretty.rb', line 25

def squish(string)
  string.gsub(/[[:space:]]+/, ' ').strip
end