Class: Halffare::PriceSbb
- Inherits:
-
PriceGuess
- Object
- PriceBase
- PriceGuess
- Halffare::PriceSbb
- Defined in:
- lib/halffare/price_sbb.rb
Overview
More accurate price strategy
Uses a static table for price conversions, falling back on guess strategy if no entry found
Instance Method Summary collapse
- #get(order) ⇒ Object
-
#initialize(force_guess_fallback = false) ⇒ PriceSbb
constructor
A new instance of PriceSbb.
- #price_guess_get ⇒ Object
Methods inherited from PriceBase
Constructor Details
#initialize(force_guess_fallback = false) ⇒ PriceSbb
Returns a new instance of PriceSbb.
11 12 13 |
# File 'lib/halffare/price_sbb.rb', line 11 def initialize(force_guess_fallback = false) @force_guess_fallback = force_guess_fallback end |
Instance Method Details
#get(order) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/halffare/price_sbb.rb', line 15 def get(order) log_debug "looking for an existing rule..." rules.each { |rule| rule.each { |match, definition| if order.description =~ /#{match}/u case when definition['scale'] != nil log_debug "found scale rule: #{definition}" return price_scale(definition, order) when definition['set'] != nil log_debug "found set rule: #{definition}" return price_set(definition, order) when definition['choices'] != nil log_debug "found choices rules: #{definition}" return price_choices(definition, order) end end } } log_result "no satisfying match found" if Halffare.debug return price_guess_get(order) if @force_guess_fallback ask_for_price(order) end |
#price_guess_get ⇒ Object
8 |
# File 'lib/halffare/price_sbb.rb', line 8 alias :price_guess_get :get |