Class: Elibri::ONIX::Release_3_0::Price

Inherits:
Object
  • Object
show all
Includes:
HashId
Defined in:
lib/elibri_onix/onix_3_0/price.rb

Constant Summary collapse

ATTRIBUTES =
[
  :type, :minimum_order_quantity, :amount, :currency_code, :printed_on_product,
  :position_on_product, :tax_type, :tax_rate_percent, :vat
]
RELATIONS =
[]

Constants included from HashId

HashId::SKIPPED_2, HashId::SKIPPED_ATTRIBS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HashId

#calculate_hash, #eid

Constructor Details

#initialize(data) ⇒ Price

Returns a new instance of Price.



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/elibri_onix/onix_3_0/price.rb', line 26

def initialize(data)
  @to_xml = data.to_s
  @type = data.at_css('PriceType').try(:text)
  @minimum_order_quantity = data.at_css('MinimumOrderQuantity').try(:text).try(:to_i)
  @amount = BigDecimal(data.at_css('PriceAmount').try(:text))
  @currency_code = data.at_css('CurrencyCode').try(:text)
  @printed_on_product = data.at_css('PrintedOnProduct').try(:text)
  @position_on_product = data.at_css('PositionOnProduct').try(:text)
  if data.at_css('Tax')
    @tax_type = data.at_css('Tax').at_css('TaxType').try(:text)
    @tax_rate_percent = data.at_css('Tax').at_css('TaxRatePercent').text.to_i if data.at_css('Tax').at_css('TaxRatePercent')
  end
end

Instance Attribute Details

#amountObject

Returns the value of attribute amount.



23
24
25
# File 'lib/elibri_onix/onix_3_0/price.rb', line 23

def amount
  @amount
end

#currency_codeObject

Returns the value of attribute currency_code.



23
24
25
# File 'lib/elibri_onix/onix_3_0/price.rb', line 23

def currency_code
  @currency_code
end

#minimum_order_quantityObject

Returns the value of attribute minimum_order_quantity.



23
24
25
# File 'lib/elibri_onix/onix_3_0/price.rb', line 23

def minimum_order_quantity
  @minimum_order_quantity
end

#position_on_productObject

Returns the value of attribute position_on_product.



23
24
25
# File 'lib/elibri_onix/onix_3_0/price.rb', line 23

def position_on_product
  @position_on_product
end

#printed_on_productObject

Returns the value of attribute printed_on_product.



23
24
25
# File 'lib/elibri_onix/onix_3_0/price.rb', line 23

def printed_on_product
  @printed_on_product
end

#tax_rate_percentObject

Returns the value of attribute tax_rate_percent.



23
24
25
# File 'lib/elibri_onix/onix_3_0/price.rb', line 23

def tax_rate_percent
  @tax_rate_percent
end

#tax_typeObject

Returns the value of attribute tax_type.



23
24
25
# File 'lib/elibri_onix/onix_3_0/price.rb', line 23

def tax_type
  @tax_type
end

#to_xmlObject

Returns the value of attribute to_xml.



23
24
25
# File 'lib/elibri_onix/onix_3_0/price.rb', line 23

def to_xml
  @to_xml
end

#typeObject

Returns the value of attribute type.



23
24
25
# File 'lib/elibri_onix/onix_3_0/price.rb', line 23

def type
  @type
end

Instance Method Details

#printed_on_product?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/elibri_onix/onix_3_0/price.rb', line 40

def printed_on_product?
  @printed_on_product == "02"
end

#vatObject



45
46
47
# File 'lib/elibri_onix/onix_3_0/price.rb', line 45

def vat
  @tax_type == Elibri::ONIX::Dict::Release_3_0::TaxType::VAT ? @tax_rate_percent : nil
end