class Dovado::Router::Traffic::Amount

Data amount data type. Extends Numeric and can be used as an Integer with the addition of getting the amount as bytes, kilobytes, megabytes or gigabytes.

@since 1.0.2

Constants

DEFAULT_KILO_BASE

The default base of a kilobyte.

Attributes

sim_id[RW]

Public Class Methods

new(value=0, base=DEFAULT_KILO_BASE) click to toggle source

Create a new Amount object.

Note: You can set the default base for a kilobyte in the router admin interface to 1000 or 1024, you should use the same base here to get the right figures. The base can differ from one operator to another.

@param [Numeric] value value of this {Amount}, defaults to 0. @param [Integer] base the base of a kilobyte.

# File lib/dovado/router/traffic/amount.rb, line 25
def initialize(value=0, base=DEFAULT_KILO_BASE)
  raise ArgumentError.new "Argument is not numeric: #{value}" unless value.is_a? Numeric
  @value = value
  @base = base
end

Public Instance Methods

b() click to toggle source

Shortcut to {#bytes}.

# File lib/dovado/router/traffic/amount.rb, line 37
def b
  bytes
end
bytes() click to toggle source

The {Amount} in bytes.

# File lib/dovado/router/traffic/amount.rb, line 32
def bytes
  @value * @base
end
gb() click to toggle source

Shortcut to {#gigabytes}.

# File lib/dovado/router/traffic/amount.rb, line 67
def gb
  gigabytes
end
gigabytes() click to toggle source

The {Amount} in gigabytes.

# File lib/dovado/router/traffic/amount.rb, line 62
def gigabytes
  (megabytes / @base.to_f).round(2)
end
kb() click to toggle source

Shortcut to {#kilobytes}.

# File lib/dovado/router/traffic/amount.rb, line 47
def kb
  kilobytes
end
kilobytes() click to toggle source

The {Amount} in kilobytes.

# File lib/dovado/router/traffic/amount.rb, line 42
def kilobytes
  @value
end
mb() click to toggle source

Shortcut to {#megabytes}.

# File lib/dovado/router/traffic/amount.rb, line 57
def mb
  megabytes
end
megabytes() click to toggle source

The {Amount} in megabytes.

# File lib/dovado/router/traffic/amount.rb, line 52
def megabytes
  (kilobytes / @base.to_f).round(2)
end