Sha256: d40a2e373f327d8298fbb1c53d5c0c50c0250d4672e8831979379aa6d2a18a70

Contents?: true

Size: 741 Bytes

Versions: 17

Compression:

Stored size: 741 Bytes

Contents

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

      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')
      end

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

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
quicktravel_client-3.2.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-3.1.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-3.0.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-2.9.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-2.8.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-2.7.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-2.6.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-2.5.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-2.4.1 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-2.4.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-2.3.1 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-2.3.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-2.2.2 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-2.2.1 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-2.2.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-2.1.0 lib/quick_travel/price_changes/price_change.rb
quicktravel_client-2.0.0 lib/quick_travel/price_changes/price_change.rb