Module: Ratchet::PricingHelper
- Defined in:
- app/helpers/ratchet/pricing_helper.rb
Constant Summary collapse
- TYPE_SIZE =
{ 'data' => { ram: 0.1, storage: 1 }, 'memory' => { ram: 0.25, storage: 0.25 }, 'memdata' => { ram: 0.25, storage: 0.25 } }
- UNITS =
units
Instance Method Summary collapse
- #nearest_size(size) ⇒ Object
- #number_to_currency(value) ⇒ Object
- #pricing_data ⇒ Object
- #pricing_slider(name, options = {}) ⇒ Object
Instance Method Details
#nearest_size(size) ⇒ Object
121 122 123 124 125 126 127 128 |
# File 'app/helpers/ratchet/pricing_helper.rb', line 121 def nearest_size(size) if size > 1024 "#{(size / 1024).round(2)} TB" else size = (size * 1024 * 1048576).round(2) # GiB -> MiB -> Bytes ActionController::Base.helpers.number_to_human_size(size, precision: 3).sub(/\.0 /,' ') end end |
#number_to_currency(value) ⇒ Object
78 79 80 |
# File 'app/helpers/ratchet/pricing_helper.rb', line 78 def number_to_currency(value) ActionController::Base.helpers.number_to_currency(value, unit: '') end |
#pricing_data ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/helpers/ratchet/pricing_helper.rb', line 22 def pricing_data @deployment_pricing ||= begin deployment_data = Site.config_data['deployments'] # Only select pricing for deployments we have planned UI for pricing = Site.config_data['pricing'].select { |d| deployment_data['slugs'][ d['slug'] ] } deployment_pricing = {} pricing.each do |deployment| slug = deployment_data['slugs'][ deployment['slug'] ] overhead = deployment['base_overhead'] || 0 type = deployment['scalables'].first['type'] type_size = TYPE_SIZE[type] # Storage/Memory configuration for this deployment type tiers = deployment['scalables'].first['price_tiers'] base_price = tiers.first['unit_cost'] # Get per unit price with no discount max_storage = deployment_data['deployments'][slug][:max_storage_units] || UNITS.last max_ram = deployment_data['deployments'][slug][:max_ram_units] || UNITS.last new_data = { type: type, units: [], price: [], price_ph: [], discount: [], savings: [], storage: [], memory: [] } units = UNITS.select {|u| tiers.first['range'][0] <= u } tiers.each do |tier| range = units.select{ |u| tier['range'].first <= u && u <= tier['range'].last } cost = tier['unit_cost'] discount = tier['discount_pct'] new_data[:units].concat range new_data[:price].concat range.map{|r| number_to_currency((cost * r) + overhead) } new_data[:price_ph].concat range.map{|r| (((cost * r) + overhead).to_f / 720).round(4) } new_data[:discount].concat range.map{|r| discount } new_data[:savings].concat range.map{|r| number_to_currency(((cost * r) + overhead) * discount/100 )} new_data[:storage].concat range.map{|r| (r < max_storage ? r : max_storage) * type_size[:storage] } new_data[:memory].concat range.map{|r| (r < max_ram ? r : max_ram) * type_size[:ram] } end deployment_pricing[slug] = new_data end deployment_pricing end end |
#pricing_slider(name, options = {}) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'app/helpers/ratchet/pricing_helper.rb', line 82 def (name, ={}) data = pricing_data[name].merge() data[:mark] = [] data[:storage].map!{ |s| nearest_size(s) } data[:memory].map!{ |s| nearest_size(s) } label_with = data[:type] == 'data' ? data[:storage] : data[:memory] data[:line_labels] = { "1" => label_with.first, "#{data[:units].size}" => label_with.last } current_discount = 0 data[:discount].each_with_index do |d, index| if d != current_discount current_discount = d data[:mark].push index + 1 end end data[:values] = data.delete(:units) data[:external_labels] = { discount: data.delete(:discount).map{|d| d == 0 ? '' : d }, savings: data.delete(:savings).map{|d| d == '0.00' ? '' : d }, storage: data.delete(:storage), memory: data.delete(:memory), price_m: data.delete(:price), price_h: data.delete(:price_ph) } data end |