Class: QuickTravel::ProductConfiguration
- Inherits:
-
Object
- Object
- QuickTravel::ProductConfiguration
- Defined in:
- lib/quick_travel/product_configuration.rb
Instance Attribute Summary collapse
-
#extra_pick_configurations ⇒ Object
readonly
Returns the value of attribute extra_pick_configurations.
-
#product ⇒ Object
readonly
Returns the value of attribute product.
Instance Method Summary collapse
- #applied_rules ⇒ Object
- #available? ⇒ Boolean
- #available_extra_pick_configurations ⇒ Object
- #deselect! ⇒ Object
-
#initialize(product) ⇒ ProductConfiguration
constructor
A new instance of ProductConfiguration.
- #price ⇒ Object
- #price_for_rack_rate ⇒ Object
- #price_per_passenger_type(passenger_type_id) ⇒ Object
- #price_without_rules ⇒ Object
- #priced? ⇒ Boolean
- #select! ⇒ Object
- #select_extra_pick(extra_pick) ⇒ Object
- #select_extra_picks(extra_picks) ⇒ Object
- #selected? ⇒ Boolean
- #selected_extra_pick_configurations ⇒ Object
- #total_applied_rules ⇒ Object
- #total_price ⇒ Object
- #total_price_for_rack_rate ⇒ Object
- #total_price_without_rules ⇒ Object
Constructor Details
#initialize(product) ⇒ ProductConfiguration
Returns a new instance of ProductConfiguration.
9 10 11 12 13 14 |
# File 'lib/quick_travel/product_configuration.rb', line 9 def initialize(product) @product = product @selected = false @extra_pick_configurations = product.extras.map { |extra_pick| self.class.new(extra_pick) } end |
Instance Attribute Details
#extra_pick_configurations ⇒ Object (readonly)
Returns the value of attribute extra_pick_configurations.
6 7 8 |
# File 'lib/quick_travel/product_configuration.rb', line 6 def extra_pick_configurations @extra_pick_configurations end |
#product ⇒ Object (readonly)
Returns the value of attribute product.
6 7 8 |
# File 'lib/quick_travel/product_configuration.rb', line 6 def product @product end |
Instance Method Details
#applied_rules ⇒ Object
61 62 63 |
# File 'lib/quick_travel/product_configuration.rb', line 61 def applied_rules pricing_details.applied_rules.uniq end |
#available? ⇒ Boolean
28 29 30 31 |
# File 'lib/quick_travel/product_configuration.rb', line 28 def available? @product.available? && selected_extra_pick_configurations.all?(&:available?) end |
#available_extra_pick_configurations ⇒ Object
77 78 79 |
# File 'lib/quick_travel/product_configuration.rb', line 77 def available_extra_pick_configurations @extra_pick_configurations.select(&:available?) end |
#deselect! ⇒ Object
20 21 22 |
# File 'lib/quick_travel/product_configuration.rb', line 20 def deselect! @selected = false end |
#price ⇒ Object
37 38 39 |
# File 'lib/quick_travel/product_configuration.rb', line 37 def price pricing_details.minimum_price_with_adjustments end |
#price_for_rack_rate ⇒ Object
45 46 47 |
# File 'lib/quick_travel/product_configuration.rb', line 45 def price_for_rack_rate pricing_details_for_rack_rate.minimum_price_with_adjustments end |
#price_per_passenger_type(passenger_type_id) ⇒ Object
69 70 71 |
# File 'lib/quick_travel/product_configuration.rb', line 69 def price_per_passenger_type(passenger_type_id) pricing_details.price_per_pax_type[passenger_type_id] end |
#price_without_rules ⇒ Object
41 42 43 |
# File 'lib/quick_travel/product_configuration.rb', line 41 def price_without_rules pricing_details_without_rules.minimum_price_with_adjustments end |
#priced? ⇒ Boolean
33 34 35 |
# File 'lib/quick_travel/product_configuration.rb', line 33 def priced? @product.try(:pricing_details).present? end |
#select! ⇒ Object
16 17 18 |
# File 'lib/quick_travel/product_configuration.rb', line 16 def select! @selected = true end |
#select_extra_pick(extra_pick) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/quick_travel/product_configuration.rb', line 87 def select_extra_pick(extra_pick) extra_pick_configuration = configuration_for(extra_pick) if extra_pick_configuration.nil? fail ArgumentError, 'That extra pick does not belong to the product' end extra_pick_configuration.select! end |
#select_extra_picks(extra_picks) ⇒ Object
81 82 83 84 85 |
# File 'lib/quick_travel/product_configuration.rb', line 81 def select_extra_picks(extra_picks) extra_picks.each do |extra_pick| select_extra_pick(extra_pick) end end |
#selected? ⇒ Boolean
24 25 26 |
# File 'lib/quick_travel/product_configuration.rb', line 24 def selected? @selected end |
#selected_extra_pick_configurations ⇒ Object
73 74 75 |
# File 'lib/quick_travel/product_configuration.rb', line 73 def selected_extra_pick_configurations @extra_pick_configurations.select(&:selected?) end |
#total_applied_rules ⇒ Object
65 66 67 |
# File 'lib/quick_travel/product_configuration.rb', line 65 def total_applied_rules (applied_rules + selected_extra_picks_applied_rules).uniq end |
#total_price ⇒ Object
49 50 51 |
# File 'lib/quick_travel/product_configuration.rb', line 49 def total_price price + selected_extra_picks_price end |
#total_price_for_rack_rate ⇒ Object
57 58 59 |
# File 'lib/quick_travel/product_configuration.rb', line 57 def total_price_for_rack_rate price_for_rack_rate + selected_extra_picks_price_for_rack_rate end |
#total_price_without_rules ⇒ Object
53 54 55 |
# File 'lib/quick_travel/product_configuration.rb', line 53 def total_price_without_rules price_without_rules + selected_extra_picks_price_without_rules end |