Class: Joyent::Cloud::Pricing::Reporter
- Inherits:
-
Object
- Object
- Joyent::Cloud::Pricing::Reporter
show all
- Defined in:
- lib/pricing/reporter.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(commit = COMMIT, zones_in_use = []) ⇒ Reporter
Returns a new instance of Reporter.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Various formatting helpers follow below Note that we delegate to analyzer for majority of calls. Sorry about that method_missing :(
43
44
45
46
47
48
49
|
# File 'lib/pricing/reporter.rb', line 43
def method_missing(method, *args, &block)
if @analyzer.respond_to?(method)
@analyzer.send(method, *args, &block)
else
super
end
end
|
Instance Attribute Details
#analyzer ⇒ Object
Returns the value of attribute analyzer.
8
9
10
|
# File 'lib/pricing/reporter.rb', line 8
def analyzer
@analyzer
end
|
#commit ⇒ Object
Returns the value of attribute commit.
8
9
10
|
# File 'lib/pricing/reporter.rb', line 8
def commit
@commit
end
|
Returns the value of attribute formatter.
8
9
10
|
# File 'lib/pricing/reporter.rb', line 8
def formatter
@formatter
end
|
#print_zone_list ⇒ Object
Returns the value of attribute print_zone_list.
8
9
10
|
# File 'lib/pricing/reporter.rb', line 8
def print_zone_list
@print_zone_list
end
|
#template ⇒ Object
Returns the value of attribute template.
8
9
10
|
# File 'lib/pricing/reporter.rb', line 8
def template
@template
end
|
#zones_in_use ⇒ Object
Returns the value of attribute zones_in_use.
8
9
10
|
# File 'lib/pricing/reporter.rb', line 8
def zones_in_use
@zones_in_use
end
|
Instance Method Details
#excess_zones_for_print ⇒ Object
59
60
61
|
# File 'lib/pricing/reporter.rb', line 59
def excess_zones_for_print
zones_for_print(zone_counts_to_list(analyzer.excess_zone_counts), :yellow)
end
|
51
52
53
|
# File 'lib/pricing/reporter.rb', line 51
def format_price *args
@formatter.format_price *args
end
|
#have_commit_pricing? ⇒ Boolean
55
56
57
|
# File 'lib/pricing/reporter.rb', line 55
def have_commit_pricing?
commit.reserves.size > 0
end
|
#over_reserved_zones_for_print ⇒ Object
63
64
65
|
# File 'lib/pricing/reporter.rb', line 63
def over_reserved_zones_for_print
zones_for_print(analyzer.over_reserved_zone_counts)
end
|
#render(options = {}) ⇒ Object
29
30
31
32
33
|
# File 'lib/pricing/reporter.rb', line 29
def render(options = {})
disable_color if (options && options[:disable_color]) || ENV['NO_COLOR']
@r = self
ERB.new(template, 0, '-').result(binding)
end
|
#unknown_zones_for_print ⇒ Object
67
68
69
|
# File 'lib/pricing/reporter.rb', line 67
def unknown_zones_for_print
zone_list_for_print(analyzer.unknown_zone_counts.keys)
end
|
#zone_counts_to_list(zone_count_hash) ⇒ Object
84
85
86
87
88
89
|
# File 'lib/pricing/reporter.rb', line 84
def zone_counts_to_list zone_count_hash
zones = zone_count_hash.each_pair.
map { |flavor, count| [flavor, count, pricing.monthly(flavor) * count] }.
sort { |x, y| y[2] <=> x[2] }
zones
end
|
#zone_list_for_print(list, format = ' %-40s') ⇒ Object
80
81
82
|
# File 'lib/pricing/reporter.rb', line 80
def zone_list_for_print(list, format = ' %-40s')
list.map { |k| sprintf(format, k) }.join("\n")
end
|
#zone_props_to_string(prop_type, width, suffix = '', divide_by = 1) ⇒ Object
91
92
93
94
95
96
|
# File 'lib/pricing/reporter.rb', line 91
def zone_props_to_string(prop_type, width, suffix = '', divide_by = 1)
props = analyzer.send(prop_type)
[props[:reserved], props[:unreserved], props[:total]].map do |value|
sprintf("%#{width}d#{suffix}", value / divide_by)
end
end
|
#zones_for_print(zone_list, color = nil) ⇒ Object
71
72
73
74
75
76
77
78
|
# File 'lib/pricing/reporter.rb', line 71
def zones_for_print(zone_list, color = nil)
zone_list.map do |tuple|
flavor, count, monthly = tuple
price = formatter.format_price(monthly, 16)
price = price.send(color) if color
sprintf(" %2d x %-36s %16s", count, flavor, price)
end.join("\n")
end
|