Class: QuickTravel::PriceChanges::PriceChange

Inherits:
Object
  • Object
show all
Defined in:
lib/quick_travel/price_changes/price_change.rb

Direct Known Subclasses

PriceChangeTree

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ PriceChange

Returns a new instance of PriceChange.



9
10
11
12
13
14
15
16
17
# File 'lib/quick_travel/price_changes/price_change.rb', line 9

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

Instance Attribute Details

#changed_priceObject (readonly)

Returns the value of attribute changed_price.



5
6
7
# File 'lib/quick_travel/price_changes/price_change.rb', line 5

def changed_price
  @changed_price
end

#original_priceObject (readonly)

Returns the value of attribute original_price.



5
6
7
# File 'lib/quick_travel/price_changes/price_change.rb', line 5

def original_price
  @original_price
end

#price_changeObject (readonly)

Returns the value of attribute price_change.



5
6
7
# File 'lib/quick_travel/price_changes/price_change.rb', line 5

def price_change
  @price_change
end

#reasonObject (readonly)

Returns the value of attribute reason.



5
6
7
# File 'lib/quick_travel/price_changes/price_change.rb', line 5

def reason
  @reason
end

#reasonsObject (readonly)

Returns the value of attribute reasons.



5
6
7
# File 'lib/quick_travel/price_changes/price_change.rb', line 5

def reasons
  @reasons
end

#targetObject (readonly)

Returns the value of attribute target.



4
5
6
# File 'lib/quick_travel/price_changes/price_change.rb', line 4

def target
  @target
end

Instance Method Details

#applied_on?(id, type = 'Reservation') ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/quick_travel/price_changes/price_change.rb', line 19

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