Class: Arcp::Lease::CostBudget

Inherits:
Data
  • Object
show all
Defined in:
lib/arcp/lease.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#per_currencyObject (readonly)

Returns the value of attribute per_currency

Returns:

  • (Object)

    the current value of per_currency



34
35
36
# File 'lib/arcp/lease.rb', line 34

def per_currency
  @per_currency
end

Class Method Details

.parse(entries) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/arcp/lease.rb', line 35

def self.parse(entries)
  h = {}
  Array(entries).each do |entry|
    ccy, amount = entry.to_s.split(':', 2)
    if ccy.nil? || amount.nil?
      raise Arcp::Errors::InvalidRequest,
            "malformed budget entry: #{entry.inspect}"
    end

    h[ccy] = BigDecimal(amount)
  end
  new(per_currency: h.freeze)
end

Instance Method Details

#currenciesObject



53
# File 'lib/arcp/lease.rb', line 53

def currencies = per_currency.keys

#remaining(currency) ⇒ Object



52
# File 'lib/arcp/lease.rb', line 52

def remaining(currency) = per_currency[currency] || BigDecimal('0')

#to_aObject



49
# File 'lib/arcp/lease.rb', line 49

def to_a = per_currency.map { |ccy, amt| "#{ccy}:#{amt.to_s('F')}" }

#to_hObject



50
# File 'lib/arcp/lease.rb', line 50

def to_h = { 'cost.budget' => to_a }