Class: FloorCalculator::Pricer
- Inherits:
-
Object
- Object
- FloorCalculator::Pricer
- Defined in:
- lib/floor_calculator/pricer.rb
Instance Attribute Summary collapse
-
#destination ⇒ Object
readonly
Returns the value of attribute destination.
-
#markups ⇒ Object
readonly
Returns the value of attribute markups.
-
#offer ⇒ Object
readonly
Returns the value of attribute offer.
-
#partial_results ⇒ Object
readonly
Returns the value of attribute partial_results.
-
#source_catalog ⇒ Object
readonly
Returns the value of attribute source_catalog.
-
#weight ⇒ Object
readonly
Returns the value of attribute weight.
Instance Method Summary collapse
- #calculate_floor ⇒ Object
- #cost_method(name, options) ⇒ Object
-
#initialize(offer, weight, markups) ⇒ Pricer
constructor
A new instance of Pricer.
- #prepare_options(offer, price) ⇒ Object
- #round_to_20s(price) ⇒ Object
Constructor Details
#initialize(offer, weight, markups) ⇒ Pricer
Returns a new instance of Pricer.
7 8 9 10 11 12 13 14 15 |
# File 'lib/floor_calculator/pricer.rb', line 7 def initialize(offer, weight, markups) @partial_results = {} @markups = markups @weight = weight @offer = offer @source_catalog = offer[:source_catalog] @types = markups['pipelines']['floor_calculation'] @destination = offer.catalog end |
Instance Attribute Details
#destination ⇒ Object (readonly)
Returns the value of attribute destination.
5 6 7 |
# File 'lib/floor_calculator/pricer.rb', line 5 def destination @destination end |
#markups ⇒ Object (readonly)
Returns the value of attribute markups.
5 6 7 |
# File 'lib/floor_calculator/pricer.rb', line 5 def markups @markups end |
#offer ⇒ Object (readonly)
Returns the value of attribute offer.
5 6 7 |
# File 'lib/floor_calculator/pricer.rb', line 5 def offer @offer end |
#partial_results ⇒ Object (readonly)
Returns the value of attribute partial_results.
5 6 7 |
# File 'lib/floor_calculator/pricer.rb', line 5 def partial_results @partial_results end |
#source_catalog ⇒ Object (readonly)
Returns the value of attribute source_catalog.
5 6 7 |
# File 'lib/floor_calculator/pricer.rb', line 5 def source_catalog @source_catalog end |
#weight ⇒ Object (readonly)
Returns the value of attribute weight.
5 6 7 |
# File 'lib/floor_calculator/pricer.rb', line 5 def weight @weight end |
Instance Method Details
#calculate_floor ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/floor_calculator/pricer.rb', line 17 def calculate_floor floor = offer.price @types.each do |method| floor = cost_method(method, (offer, floor)) end round_to_20s(floor.fractional) end |
#cost_method(name, options) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/floor_calculator/pricer.rb', line 25 def cost_method(name, ) calculated_value = Solver.calculate(markups, name, ).round(4) @partial_results[name] = calculated_value result = [:price] + calculated_value result end |
#prepare_options(offer, price) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/floor_calculator/pricer.rb', line 37 def (offer, price) { source: offer[:source_catalog], country: offer.country.to_s.downcase, destination: offer.catalog, price: price, condition: offer.condition, weight: weight, fast: offer[:fast] } end |
#round_to_20s(price) ⇒ Object
33 34 35 |
# File 'lib/floor_calculator/pricer.rb', line 33 def round_to_20s(price) (price % 20) > 0 ? ((price.to_i / 20) + 1) * 20 : price end |