Class: Elibri::ONIX::Release_3_0::Supplier

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

Constant Summary collapse

ATTRIBUTES =

from ONIX documentation: A group of data elements which together define a supplier. Mandatory in each occurrence of the <SupplyDetail> composite, and not repeatable.

[
  :role, :name, :telephone_number, :email_address, :website, :nip
]
RELATIONS =
[
  :identifiers
]

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) ⇒ Supplier

Returns a new instance of Supplier.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/elibri_onix/onix_3_0/supplier.rb', line 25

def initialize(data)
  @to_xml = data.to_s
  @role = data.at_xpath('xmlns:SupplierRole').try(:text).try(:to_i)
  @identifiers = data.xpath('xmlns:SupplierIdentifier').map { |identifier_data| SupplierIdentifier.new(identifier_data) }
  @name = data.at_xpath('xmlns:SupplierName').try(:text)
  @telephone_number = data.at_xpath('xmlns:TelephoneNumber').try(:text)
  @email_address = data.at_xpath('xmlns:EmailAddress').try(:text)
  if data.at_xpath('xmlns:Website')
    @website = data.at_xpath('xmlns:Website').at_xpath('xmlns:WebsiteLink').try(:text) 
  end
end

Instance Attribute Details

#email_addressObject

Returns the value of attribute email_address.



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

def email_address
  @email_address
end

#identifiersObject

Returns the value of attribute identifiers.



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

def identifiers
  @identifiers
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#roleObject

Returns the value of attribute role.



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

def role
  @role
end

#telephone_numberObject

Returns the value of attribute telephone_number.



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

def telephone_number
  @telephone_number
end

#to_xmlObject

Returns the value of attribute to_xml.



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

def to_xml
  @to_xml
end

#websiteObject

Returns the value of attribute website.



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

def website
  @website
end

Instance Method Details

#nipObject



37
38
39
# File 'lib/elibri_onix/onix_3_0/supplier.rb', line 37

def nip
  @identifiers.find {|identifier| (identifier.type == '02') && (identifier.type_name == 'NIP')}.try(:value)
end