Sha256: 380c686710226d7b85ba5b5f0e3f2d61ef107ac9f57bbfed9c9d0fcee372d5e6
Contents?: true
Size: 1.02 KB
Versions: 36
Compression:
Stored size: 1.02 KB
Contents
module QuickTravel module PriceChanges class PriceChangeTree < PriceChange attr_reader :root, :children def initialize(attrs = {}) super(attrs) @root = PriceChange.new(attrs['root']) @children = attrs.fetch('children', []).map do |child_attrs| PriceChangeTree.new(child_attrs) end end 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 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 def roots [@root] + @children.flat_map(&:roots) end private def find_and_return_on_children(&block) @children.each do |child| result = block.call(child) return result unless result.nil? end nil end end end end
Version data entries
36 entries across 36 versions & 1 rubygems