Class: Arcp::Lease::CostBudget
- Inherits:
-
Data
- Object
- Data
- Arcp::Lease::CostBudget
- Defined in:
- lib/arcp/lease.rb
Instance Attribute Summary collapse
-
#per_currency ⇒ Object
readonly
Returns the value of attribute per_currency.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#per_currency ⇒ Object (readonly)
Returns the value of attribute 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
#currencies ⇒ Object
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_a ⇒ Object
49 |
# File 'lib/arcp/lease.rb', line 49 def to_a = per_currency.map { |ccy, amt| "#{ccy}:#{amt.to_s('F')}" } |
#to_h ⇒ Object
50 |
# File 'lib/arcp/lease.rb', line 50 def to_h = { 'cost.budget' => to_a } |