Class: QuickTravel::PriceChanges::PriceChangeTree
- Inherits:
-
PriceChange
- Object
- PriceChange
- QuickTravel::PriceChanges::PriceChangeTree
- Defined in:
- lib/quick_travel/price_changes/price_change_tree.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Attributes inherited from PriceChange
#changed_price, #original_price, #price_change, #reason, #reasons, #target
Instance Method Summary collapse
-
#initialize(attrs = {}) ⇒ PriceChangeTree
constructor
A new instance of PriceChangeTree.
- #price_change_on(id, type = 'Reservation') ⇒ Object
- #roots ⇒ Object
- #total_price_change_on(id, type = 'Reservation') ⇒ Object
Methods inherited from PriceChange
Constructor Details
#initialize(attrs = {}) ⇒ PriceChangeTree
Returns a new instance of PriceChangeTree.
6 7 8 9 10 11 12 |
# File 'lib/quick_travel/price_changes/price_change_tree.rb', line 6 def initialize(attrs = {}) super(attrs) @root = PriceChange.new(attrs['root']) @children = attrs.fetch('children', []).map do |child_attrs| PriceChangeTree.new(child_attrs) end end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
4 5 6 |
# File 'lib/quick_travel/price_changes/price_change_tree.rb', line 4 def children @children end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
4 5 6 |
# File 'lib/quick_travel/price_changes/price_change_tree.rb', line 4 def root @root end |
Instance Method Details
#price_change_on(id, type = 'Reservation') ⇒ Object
14 15 16 17 |
# File 'lib/quick_travel/price_changes/price_change_tree.rb', line 14 def price_change_on(id, type = 'Reservation') return @root if applied_on?(id, type) find_and_return_on_children { |child| child.price_change_on(id, type) } end |
#roots ⇒ Object
24 25 26 |
# File 'lib/quick_travel/price_changes/price_change_tree.rb', line 24 def roots [@root] + @children.flat_map(&:roots) end |
#total_price_change_on(id, type = 'Reservation') ⇒ Object
19 20 21 22 |
# File 'lib/quick_travel/price_changes/price_change_tree.rb', line 19 def total_price_change_on(id, type = 'Reservation') return self if applied_on?(id, type) find_and_return_on_children { |child| child.total_price_change_on(id, type) } end |