Class: Joyent::Cloud::Pricing::Analyzer
- Inherits:
-
Object
- Object
- Joyent::Cloud::Pricing::Analyzer
- Defined in:
- lib/pricing/analyzer.rb
Instance Attribute Summary collapse
-
#commit ⇒ Object
Returns the value of attribute commit.
-
#zone_counts ⇒ Object
Returns the value of attribute zone_counts.
Instance Method Summary collapse
- #cpus ⇒ Object
- #disk ⇒ Object
-
#excess_zone_counts ⇒ Object
Zones that are not on commit, i.e on demand.
- #have_excess_zones? ⇒ Boolean
- #have_over_reserved_zones? ⇒ Boolean
- #have_unknown_zones? ⇒ Boolean
-
#initialize(commit, flavors = []) ⇒ Analyzer
constructor
A new instance of Analyzer.
-
#monthly_commit_price ⇒ Object
Monthly for all of the commits.
-
#monthly_full_price ⇒ Object
Non-discounted full price.
- #monthly_full_price_for(zones) ⇒ Object
-
#monthly_overages_price ⇒ Object
Excess zones cost this much.
-
#monthly_total_price ⇒ Object
Commits + excess non reserved zones.
-
#over_reserved_zone_counts ⇒ Object
Zones that are committed, but do not exist.
- #ram ⇒ Object
-
#unknown_zone_counts ⇒ Object
Zones with flavor that’s not recognized, and therefore unknown.
- #unknown_zone_total ⇒ Object
- #upfront ⇒ Object
- #yearly_full_price ⇒ Object
- #yearly_overages_price ⇒ Object
- #yearly_savings ⇒ Object
- #yearly_savings_percent ⇒ Object
- #yearly_total ⇒ Object
Constructor Details
#initialize(commit, flavors = []) ⇒ Analyzer
Returns a new instance of Analyzer.
8 9 10 11 |
# File 'lib/pricing/analyzer.rb', line 8 def initialize(commit, flavors = []) @commit = commit @zone_counts = count_dupes(flavors).symbolize_keys end |
Instance Attribute Details
#commit ⇒ Object
Returns the value of attribute commit.
6 7 8 |
# File 'lib/pricing/analyzer.rb', line 6 def commit @commit end |
#zone_counts ⇒ Object
Returns the value of attribute zone_counts.
6 7 8 |
# File 'lib/pricing/analyzer.rb', line 6 def zone_counts @zone_counts end |
Instance Method Details
#cpus ⇒ Object
102 103 104 |
# File 'lib/pricing/analyzer.rb', line 102 def cpus count_props(:cpus) end |
#disk ⇒ Object
110 111 112 |
# File 'lib/pricing/analyzer.rb', line 110 def disk count_props(:disk) end |
#excess_zone_counts ⇒ Object
Zones that are not on commit, i.e on demand
14 15 16 17 18 |
# File 'lib/pricing/analyzer.rb', line 14 def excess_zone_counts h = {} zone_counts.each_pair { |flavor, count| diff = count - quantity_for(flavor); h[flavor] = diff if diff > 0 } h end |
#have_excess_zones? ⇒ Boolean
44 45 46 |
# File 'lib/pricing/analyzer.rb', line 44 def have_excess_zones? excess_zone_counts.size > 0 end |
#have_over_reserved_zones? ⇒ Boolean
48 49 50 |
# File 'lib/pricing/analyzer.rb', line 48 def have_over_reserved_zones? over_reserved_zone_counts.size > 0 end |
#have_unknown_zones? ⇒ Boolean
40 41 42 |
# File 'lib/pricing/analyzer.rb', line 40 def have_unknown_zones? unknown_zone_counts.size > 0 end |
#monthly_commit_price ⇒ Object
Monthly for all of the commits
63 64 65 |
# File 'lib/pricing/analyzer.rb', line 63 def monthly_commit_price commit.monthly_price end |
#monthly_full_price ⇒ Object
Non-discounted full price
53 54 55 |
# File 'lib/pricing/analyzer.rb', line 53 def monthly_full_price monthly_full_price_for(zone_counts) end |
#monthly_full_price_for(zones) ⇒ Object
76 77 78 79 80 |
# File 'lib/pricing/analyzer.rb', line 76 def monthly_full_price_for zones count_for_all zones do |flavor| (commit.discount.nil?) ? pricing.monthly(flavor) : commit.discount.apply(pricing.monthly(flavor)) end end |
#monthly_overages_price ⇒ Object
Excess zones cost this much
58 59 60 |
# File 'lib/pricing/analyzer.rb', line 58 def monthly_overages_price monthly_full_price_for(excess_zone_counts) end |
#monthly_total_price ⇒ Object
Commits + excess non reserved zones
68 69 70 |
# File 'lib/pricing/analyzer.rb', line 68 def monthly_total_price monthly_overages_price + monthly_commit_price end |
#over_reserved_zone_counts ⇒ Object
Zones that are committed, but do not exist
21 22 23 24 25 |
# File 'lib/pricing/analyzer.rb', line 21 def over_reserved_zone_counts h = {} zone_counts.each_pair { |flavor, count| diff = count - quantity_for(flavor); h[flavor] = -diff if diff < 0 } h end |
#ram ⇒ Object
106 107 108 |
# File 'lib/pricing/analyzer.rb', line 106 def ram count_props(:ram) end |
#unknown_zone_counts ⇒ Object
Zones with flavor that’s not recognized, and therefore unknown
28 29 30 31 32 |
# File 'lib/pricing/analyzer.rb', line 28 def unknown_zone_counts h = {} zone_counts.each_pair { |flavor, count| h[flavor] = count if pricing.flavor(flavor).nil? } h end |
#unknown_zone_total ⇒ Object
34 35 36 37 38 |
# File 'lib/pricing/analyzer.rb', line 34 def unknown_zone_total count_for_all(unknown_zone_counts) do |flavor| 1 end.to_i end |
#upfront ⇒ Object
72 73 74 |
# File 'lib/pricing/analyzer.rb', line 72 def upfront commit.upfront end |
#yearly_full_price ⇒ Object
86 87 88 |
# File 'lib/pricing/analyzer.rb', line 86 def yearly_full_price monthly_full_price * 12 end |
#yearly_overages_price ⇒ Object
82 83 84 |
# File 'lib/pricing/analyzer.rb', line 82 def yearly_overages_price monthly_overages_price * 12 end |
#yearly_savings ⇒ Object
94 95 96 |
# File 'lib/pricing/analyzer.rb', line 94 def yearly_savings yearly_full_price - yearly_total end |
#yearly_savings_percent ⇒ Object
98 99 100 |
# File 'lib/pricing/analyzer.rb', line 98 def yearly_savings_percent 100 * (yearly_full_price - yearly_total) / yearly_full_price end |
#yearly_total ⇒ Object
90 91 92 |
# File 'lib/pricing/analyzer.rb', line 90 def yearly_total yearly_overages_price + commit.yearly_price end |