Class: Joyent::Cloud::Pricing::Formatter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#currency_format, #monthly_from_hourly

Constructor Details

#initialize(config) ⇒ Formatter

Returns a new instance of Formatter.



14
15
16
# File 'lib/pricing/formatter.rb', line 14

def initialize(config)
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



12
13
14
# File 'lib/pricing/formatter.rb', line 12

def config
  @config
end

Instance Method Details

#format_monthly_price(flavor, width = 0) ⇒ Object



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

def format_monthly_price(flavor, width = 0)
  format_price(monthly_price(flavor), width)
end

#format_price(value, width = 0) ⇒ Object



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

def format_price(value, width = 0)
  value = 0 if value.nil?
  value > 0 ? sprintf("%#{width}s", currency_format(sprintf("$%.2f", value))) : " " * width
end

#monthly_price(flavor) ⇒ Object



18
19
20
# File 'lib/pricing/formatter.rb', line 18

def monthly_price(flavor)
  monthly_from_hourly(config.cost(flavor) || 0)
end