Skip to content

Instantly share code, notes, and snippets.

@carlosipe
Created March 24, 2017 00:10
Show Gist options
  • Select an option

  • Save carlosipe/79bb6a68169ed4b7570d322430f21eb1 to your computer and use it in GitHub Desktop.

Select an option

Save carlosipe/79bb6a68169ed4b7570d322430f21eb1 to your computer and use it in GitHub Desktop.
class PricingModel
def initialize(config)
@configured_components = [
:setup_fee,
:unit_price,
:quantity_interpolated_price,
:area_interpolated_price,
:sheet_price,
]
@initial_fee = config.fetch(:initial_fee) or @configured_components.delete(:setup_fee)
@quantity_checkpoints = config.fetch(:quantity_checkpoints) or @configured_components.delete(:quantity_interpolated_price)
@area_checkpoints = config.fetch(:area_checkpoints) or @configured_components.delete(:area_interpolated_price)
end
def price(price_case)
@width = price_case.fetch(:width) if @configured_components.include?(:area_interpolated_price)
# @height = price_case.fetch(.... )
@configured_components.map{|c| self.send(c)}.sum
end
private
def quantity_interpolated_price
@width * @height * Interpolator.new(@area_checkpoints)#.x ...
end
def setup_fee
@initial_fee + 0.2
end
# ...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment