Class: Joyent::Cloud::Pricing::Analyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/pricing/analyzer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#commitObject

Returns the value of attribute commit.



6
7
8
# File 'lib/pricing/analyzer.rb', line 6

def commit
  @commit
end

#zone_countsObject

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

#cpusObject



102
103
104
# File 'lib/pricing/analyzer.rb', line 102

def cpus
  count_props(:cpus)
end

#diskObject



110
111
112
# File 'lib/pricing/analyzer.rb', line 110

def disk
  count_props(:disk)
end

#excess_zone_countsObject

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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


40
41
42
# File 'lib/pricing/analyzer.rb', line 40

def have_unknown_zones?
  unknown_zone_counts.size > 0
end

#monthly_commit_priceObject

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_priceObject

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_priceObject

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_priceObject

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_countsObject

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

#ramObject



106
107
108
# File 'lib/pricing/analyzer.rb', line 106

def ram
  count_props(:ram)
end

#unknown_zone_countsObject

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_totalObject



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

#upfrontObject



72
73
74
# File 'lib/pricing/analyzer.rb', line 72

def upfront
  commit.upfront
end

#yearly_full_priceObject



86
87
88
# File 'lib/pricing/analyzer.rb', line 86

def yearly_full_price
  monthly_full_price * 12
end

#yearly_overages_priceObject



82
83
84
# File 'lib/pricing/analyzer.rb', line 82

def yearly_overages_price
  monthly_overages_price * 12
end

#yearly_savingsObject



94
95
96
# File 'lib/pricing/analyzer.rb', line 94

def yearly_savings
  yearly_full_price - yearly_total
end

#yearly_savings_percentObject



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_totalObject



90
91
92
# File 'lib/pricing/analyzer.rb', line 90

def yearly_total
  yearly_overages_price + commit.yearly_price
end