Class: TrafficBiller

Inherits:
Biller show all
Defined in:
service/billers/traffic.rb

Overview

Biller for VM in- and outbound traffic costs

Instance Method Summary collapse

Methods inherited from Biller

#billing_period, #costs, #initialize

Constructor Details

This class inherits a constructor from Biller

Instance Method Details

#bill(bill:, state:, delta:, record:) ⇒ Object

See Also:



21
22
23
24
25
26
27
# File 'service/billers/traffic.rb', line 21

def bill bill:, state:, delta:, record:
  if record.class == TrafficRecord then
    bill[:rx] = state[:rx] / 1e+9 * @costs[:rx]
    bill[:tx] = state[:tx] / 1e+9 * @costs[:tx]
  end
  bill
end

#check_billerObject

Checking if Traffic costs are given, otherwise there is no point to calculate it



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'service/billers/traffic.rb', line 4

def check_biller
  @cost = JSON.parse(costs['TRAFFIC_COST'])
  return false if @cost.nil?

  @cost = @cost.to_f
  @costs = { rx: @cost, tx: @cost } # Will Add support for differnt rx and tx prices

  return @costs.values.inject(0) do | r, c |
    r += c.to_f
  rescue
    r
  end > 0
rescue
  return false
end