class FastSpring::Build::LocalizedStorePrices

Attributes

localized_pricing[R]
products[R]

Public Class Methods

new(pricing) click to toggle source
# File lib/fastspring-saasy/build/localized_store_prices.rb, line 6
def initialize(pricing)
  @pricing = pricing || []
  @products = []
  @localized_pricing = {}
end

Public Instance Methods

build() click to toggle source
# File lib/fastspring-saasy/build/localized_store_prices.rb, line 12
def build
  return if @pricing.empty?
  parsed = @pricing.split("\n").map { |f| f.split("=") }
  @localized_pricing = Hash[parsed]
  build_products
  self
end

Private Instance Methods

build_products() click to toggle source
# File lib/fastspring-saasy/build/localized_store_prices.rb, line 22
def build_products
  product_names = []
  @localized_pricing.keys.each do |key|
    product = /product_[0-9]/.match(key)
    product_names << product.to_s unless product.nil?
  end
  create_localized_products_for(product_names.uniq)
end
create_localized_products_for(product_names) click to toggle source
# File lib/fastspring-saasy/build/localized_store_prices.rb, line 31
def create_localized_products_for(product_names)
  product_names.each do |product|
    keys = @localized_pricing.select { |key, value| key.to_s.match(/#{product}/) }
    @products << LocalizedStorePrice.new(product, keys)
  end
end