Class: A2z::Responses::OfferSummary

Inherits:
Object
  • Object
show all
Defined in:
lib/a2z/responses/offer_summary.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOfferSummary

Returns a new instance of OfferSummary.



9
10
11
12
13
14
15
16
# File 'lib/a2z/responses/offer_summary.rb', line 9

def initialize
  @lowest_new_price = Money.new(0, 'USD')
  @lowest_used_price = Money.new(0, 'USD')
  @total_new = 0
  @total_used = 0
  @total_collectible = 0
  @total_refurbished = 0
end

Instance Attribute Details

#lowest_new_priceObject

Returns the value of attribute lowest_new_price.



6
7
8
# File 'lib/a2z/responses/offer_summary.rb', line 6

def lowest_new_price
  @lowest_new_price
end

#lowest_used_priceObject

Returns the value of attribute lowest_used_price.



6
7
8
# File 'lib/a2z/responses/offer_summary.rb', line 6

def lowest_used_price
  @lowest_used_price
end

#total_collectibleObject

Returns the value of attribute total_collectible.



6
7
8
# File 'lib/a2z/responses/offer_summary.rb', line 6

def total_collectible
  @total_collectible
end

#total_newObject

Returns the value of attribute total_new.



6
7
8
# File 'lib/a2z/responses/offer_summary.rb', line 6

def total_new
  @total_new
end

#total_refurbishedObject

Returns the value of attribute total_refurbished.



6
7
8
# File 'lib/a2z/responses/offer_summary.rb', line 6

def total_refurbished
  @total_refurbished
end

#total_usedObject

Returns the value of attribute total_used.



6
7
8
# File 'lib/a2z/responses/offer_summary.rb', line 6

def total_used
  @total_used
end

Class Method Details

.from_response(data) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/a2z/responses/offer_summary.rb', line 44

def self.from_response(data)
  new.tap do |offer_summary|
    if data['LowestNewPrice']
      offer_summary.lowest_new_price = Money.new(data['LowestNewPrice']['Amount'].to_i, data['LowestNewPrice']['CurrencyCode'])
    end
    
    if data['LowestUsedPrice']
      offer_summary.lowest_used_price = Money.new(data['LowestUsedPrice']['Amount'].to_i, data['LowestUsedPrice']['CurrencyCode'])
    end
    
    offer_summary.total_new = data['TotalNew']
    offer_summary.total_used = data['TotalUsed']
    offer_summary.total_collectible = data['TotalCollectible']
    offer_summary.total_refurbished = data['TotalRefurbished']
    
    offer_summary.freeze
  end
end