Sha256: c06b709b412220e78e62f095d631e6b48f4509a1a5f8abf384492664b6761712

Contents?: true

Size: 811 Bytes

Versions: 19

Compression:

Stored size: 811 Bytes

Contents

module QuickTravel
  module PriceChanges
    class PriceChange
      attr_reader :target
      attr_reader :original_price, :changed_price, :price_change, :reason, :reasons

      delegate :positive?, :negative?, to: :price_change

      def initialize(attrs = {})
        @target = OpenStruct.new(attrs.fetch('target').slice('id', 'type'))

        @original_price = Money.new(attrs.fetch('original_price_in_cents'))
        @changed_price  = Money.new(attrs.fetch('changed_price_in_cents'))
        @price_change   = Money.new(attrs.fetch('price_change_in_cents'))
        @reason         = attrs.fetch('reason')
        @reasons        = attrs.fetch('reasons', [@reason])
      end

      def applied_on?(id, type = 'Reservation')
        @target.type == type && @target.id == id
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
quicktravel_client-4.7.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-4.6.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-4.5.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-4.4.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-4.3.2 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-4.3.1 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-4.3.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-4.2.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-4.1.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-4.0.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-3.9.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-3.8.1 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-3.8.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-3.7.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-3.6.1 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-3.6.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-3.5.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-3.4.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-3.3.0 lib/quick_travel/price_changes/price_change.rb