Class: Mws::Apis::Feeds::PriceListing

Inherits:
Object
  • Object
show all
Defined in:
lib/mws/apis/feeds/price_listing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sku, base, options = {}) ⇒ PriceListing

Returns a new instance of PriceListing.



9
10
11
12
13
14
15
16
# File 'lib/mws/apis/feeds/price_listing.rb', line 9

def initialize(sku, base, options={})
  @sku = sku
  @base = Money.new(base, options[:currency])
  @currency =  @base.currency
  @min = Money.new(options[:min], @currency) if options.include? :min
  on_sale(options[:sale][:amount], options[:sale][:from], options[:sale][:to]) if options.include? :sale
  validate
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



7
8
9
# File 'lib/mws/apis/feeds/price_listing.rb', line 7

def base
  @base
end

#currencyObject (readonly)

Returns the value of attribute currency.



7
8
9
# File 'lib/mws/apis/feeds/price_listing.rb', line 7

def currency
  @currency
end

#minObject (readonly)

Returns the value of attribute min.



7
8
9
# File 'lib/mws/apis/feeds/price_listing.rb', line 7

def min
  @min
end

#saleObject (readonly)

Returns the value of attribute sale.



7
8
9
# File 'lib/mws/apis/feeds/price_listing.rb', line 7

def sale
  @sale
end

#skuObject (readonly)

Returns the value of attribute sku.



7
8
9
# File 'lib/mws/apis/feeds/price_listing.rb', line 7

def sku
  @sku
end

Instance Method Details

#on_sale(amount, from, to) ⇒ Object



18
19
20
21
22
# File 'lib/mws/apis/feeds/price_listing.rb', line 18

def on_sale(amount, from, to)
  @sale = SalePrice.new Money.new(amount, @currency), from, to
  validate
  self
end

#to_xml(name = 'Price', parent = nil) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/mws/apis/feeds/price_listing.rb', line 24

def to_xml(name='Price', parent=nil)
  Mws::Serializer.tree name, parent do |xml| 
    xml.SKU @sku
    @base.to_xml 'StandardPrice', xml
    @min.to_xml 'MAP', xml if @min
    @sale.to_xml 'Sale', xml if @sale
  end
end