Class: Joyent::Cloud::Pricing::Reserve

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/pricing/reserve.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#currency_format, #monthly_from_hourly

Constructor Details

#initialize(flavor, config) ⇒ Reserve

Returns a new instance of Reserve.



7
8
9
10
11
12
13
# File 'lib/pricing/reserve.rb', line 7

def initialize(flavor, config)
  @flavor   = flavor.to_sym
  @prepay   = config[:prepay].to_f
  @monthly  = config[:monthly].to_f
  @quantity = config[:quantity].to_i
  @years    = config[:years]
end

Instance Attribute Details

#flavorObject

Returns the value of attribute flavor.



5
6
7
# File 'lib/pricing/reserve.rb', line 5

def flavor
  @flavor
end

#monthlyObject

Returns the value of attribute monthly.



5
6
7
# File 'lib/pricing/reserve.rb', line 5

def monthly
  @monthly
end

#prepayObject

Returns the value of attribute prepay.



5
6
7
# File 'lib/pricing/reserve.rb', line 5

def prepay
  @prepay
end

#quantityObject

Returns the value of attribute quantity.



5
6
7
# File 'lib/pricing/reserve.rb', line 5

def quantity
  @quantity
end

#yearsObject

Returns the value of attribute years.



5
6
7
# File 'lib/pricing/reserve.rb', line 5

def years
  @years
end

Instance Method Details

#monthly_averagedObject



15
16
17
# File 'lib/pricing/reserve.rb', line 15

def monthly_averaged
  (total_payout / (@years * 12)).round(2)
end

#monthly_discountObject



27
28
29
# File 'lib/pricing/reserve.rb', line 27

def monthly_discount
  (total_discount / 12 / years).round(2)
end

#monthly_discount_percentObject



31
32
33
# File 'lib/pricing/reserve.rb', line 31

def monthly_discount_percent
  (100 * monthly_discount / monthly_full_price).round(2)
end

#monthly_full_priceObject



35
36
37
# File 'lib/pricing/reserve.rb', line 35

def monthly_full_price
  pricing.monthly flavor
end

#to_hashObject



39
40
41
# File 'lib/pricing/reserve.rb', line 39

def to_hash
  {prepay: prepay, monthly: monthly, years: years, quantity: quantity}
end

#total_discountObject



23
24
25
# File 'lib/pricing/reserve.rb', line 23

def total_discount
  (monthly_full_price * 12 * years).round(2) - total_payout
end

#total_payoutObject



19
20
21
# File 'lib/pricing/reserve.rb', line 19

def total_payout
  (@prepay + @years * 12 * @monthly).round(2)
end