Class: SpeedtestNet::Formatter::Speed

Inherits:
Object
  • Object
show all
Defined in:
lib/speedtest_net/formatter/speed.rb

Constant Summary collapse

UNITS =
%w[bps Kbps Mbps Gbps Tbps].freeze

Class Method Summary collapse

Class Method Details

.call(speed) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/speedtest_net/formatter/speed.rb', line 9

def call(speed)
  i = 0
  while speed >= 1000
    speed /= 1000
    i += 1
  end
  format('%<speed>.2f %<unit>s', speed: speed, unit: UNITS[i])
end