Class: Joyent::Cloud::Pricing::Commit
- Inherits:
-
Object
- Object
- Joyent::Cloud::Pricing::Commit
- Defined in:
- lib/pricing/commit.rb
Instance Attribute Summary collapse
-
#custom ⇒ Object
map of image names to prices.
-
#discount ⇒ Object
map of image names to prices.
-
#reserves ⇒ Object
map of image names to prices.
Class Method Summary collapse
Instance Method Summary collapse
- #flavor_counts ⇒ Object
-
#initialize(hash = {}, custom = nil, discount = nil) ⇒ Commit
constructor
A new instance of Commit.
- #monthly_price ⇒ Object
- #reserve_for(flavor) ⇒ Object
- #total_zones ⇒ Object
- #upfront_price ⇒ Object
- #yearly_price ⇒ Object
- #years ⇒ Object
Constructor Details
#initialize(hash = {}, custom = nil, discount = nil) ⇒ Commit
Returns a new instance of Commit.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pricing/commit.rb', line 16 def initialize(hash = {}, custom = nil, discount = nil) @config = hash.symbolize_keys self.reserves = {} @config.each_pair do |flavor, config| self.reserves[flavor] = Reserve.new(flavor, config) end if custom Joyent::Cloud::Pricing::Configuration.instance.merge(custom) end if discount discount = discount.symbolize_keys self.discount = Joyent::Cloud::Pricing::Discount.type(discount[:type], discount[:value]) end end |
Instance Attribute Details
#custom ⇒ Object
map of image names to prices
14 15 16 |
# File 'lib/pricing/commit.rb', line 14 def custom @custom end |
#discount ⇒ Object
map of image names to prices
14 15 16 |
# File 'lib/pricing/commit.rb', line 14 def discount @discount end |
#reserves ⇒ Object
map of image names to prices
14 15 16 |
# File 'lib/pricing/commit.rb', line 14 def reserves @reserves end |
Class Method Details
.from_yaml(filename = COMMIT_FILENAME) ⇒ Object
7 8 9 10 |
# File 'lib/pricing/commit.rb', line 7 def from_yaml(filename = COMMIT_FILENAME) hash = YAML.load(File.read(filename)) new(hash['reserved'] || {}, hash['custom'], hash['discount']) end |
Instance Method Details
#flavor_counts ⇒ Object
55 56 57 58 59 |
# File 'lib/pricing/commit.rb', line 55 def flavor_counts zone_list = {} reserves.keys.each{|zone| zone_list[zone] = reserves[zone].quantity} zone_list end |
#monthly_price ⇒ Object
35 36 37 |
# File 'lib/pricing/commit.rb', line 35 def monthly_price sum_of &->(reserve) {reserve.monthly } end |
#reserve_for(flavor) ⇒ Object
31 32 33 |
# File 'lib/pricing/commit.rb', line 31 def reserve_for flavor reserves[flavor.to_sym] end |
#total_zones ⇒ Object
43 44 45 |
# File 'lib/pricing/commit.rb', line 43 def total_zones sum_of &->(reserve) {1} end |
#upfront_price ⇒ Object
39 40 41 |
# File 'lib/pricing/commit.rb', line 39 def upfront_price sum_of &->(reserve) {reserve.prepay} end |
#yearly_price ⇒ Object
47 48 49 |
# File 'lib/pricing/commit.rb', line 47 def yearly_price upfront_price + 12 * monthly_price end |
#years ⇒ Object
51 52 53 |
# File 'lib/pricing/commit.rb', line 51 def years reserves.empty? ? 0 : reserves.values.first.years end |