module UsefulUtilities::Size::CdnSpeed

Possible units:

:bit  - bits
:kbit - kilobits
:Mbit - megabits
:Gbit - gigabits
:Tbit - terabits

Used SI standard en.wikipedia.org/wiki/Binary_prefix

Decimal
1 K = 1000

Public Instance Methods

to_cdn_gbps(speed, unit) click to toggle source

@param speed [Numeric] @param unit [Symbol] @return [Numeric] size in CDN gigabits per second

# File lib/useful_utilities/size/cdn_speed.rb, line 20
def to_cdn_gbps(speed, unit)
  to_giga(speed, bit_prefix(unit))/8
end

Private Instance Methods

bit_prefix(unit) click to toggle source
# File lib/useful_utilities/size/cdn_speed.rb, line 26
def bit_prefix(unit)
  case unit
  when :bit  then :B
  when :kbit then :KB
  when :Mbit then :MB
  when :Gbit then :GB
  when :Tbit then :TB
  else unsupported_unit!(unit)
  end
end
unsupported_unit!(unit) click to toggle source
# File lib/useful_utilities/size/cdn_speed.rb, line 37
def unsupported_unit!(unit)
  raise ArgumentError.new("Unsupported unit - #{ unit }")
end