Sha256: 86265a73cd10a77e8bc4fb4843d64ec30c129e63c789129dc8d9d77c50f02278

Contents?: true

Size: 582 Bytes

Versions: 1

Compression:

Stored size: 582 Bytes

Contents

module Throttle
  module Bandwidth
    def parse_bandwidth(str)
      amount = nil
      units  = "KBp/s"
            
      if /(\d*)/.match(str)
        amount = Regexp.last_match(0).to_i
        
        if /((K|M|k|m)(b|B)(p|P))/.match(str)
          units  = Regexp.last_match(0)
          units.gsub!('P', 'p')
          units.gsub!('/s', '')
          units += '/s'
        end  
        
        # Maximum allowed MBps
        amount = 268 if units == "MBp/s" && amount > 268
        
        "#{amount}#{units}"
      else
        nil
      end    
    end  
  end  
end
  

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
throttle-0.0.1 lib/throttle/bandwidth.rb