Created
March 24, 2017 00:10
-
-
Save carlosipe/79bb6a68169ed4b7570d322430f21eb1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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