Class: Elibri::ONIX::Release_3_0::RelatedProduct

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

Constant Summary collapse

ATTRIBUTES =

:nodoc:

[
  :relation_code, :proprietary_identifiers, :record_reference
]
RELATIONS =

:nodoc:

[
  :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) ⇒ RelatedProduct

Returns a new instance of RelatedProduct.



28
29
30
31
32
# File 'lib/elibri_onix/onix_3_0/related_product.rb', line 28

def initialize(data)
  @to_xml = data.to_s
  @relation_code = data.at_xpath('xmlns:ProductRelationCode').try(:text)
  @identifiers = data.xpath('xmlns:ProductIdentifier').map { |identifier_data| ProductIdentifier.new(identifier_data) }
end

Instance Attribute Details

#identifiersObject (readonly)

Returns the value of attribute identifiers.



25
26
27
# File 'lib/elibri_onix/onix_3_0/related_product.rb', line 25

def identifiers
  @identifiers
end

#relation_codeObject (readonly)

Returns the value of attribute relation_code.



24
25
26
# File 'lib/elibri_onix/onix_3_0/related_product.rb', line 24

def relation_code
  @relation_code
end

#to_xmlObject (readonly)

Returns the value of attribute to_xml.



26
27
28
# File 'lib/elibri_onix/onix_3_0/related_product.rb', line 26

def to_xml
  @to_xml
end

Instance Method Details

#proprietary_identifiersObject



40
41
42
43
44
45
46
# File 'lib/elibri_onix/onix_3_0/related_product.rb', line 40

def proprietary_identifiers
  Hash.new.tap do |hash|
    @identifiers.each do |identifier|
      hash[identifier.type_name] = identifier.value if identifier.type == '01'
    end
  end
end

#record_referenceObject



35
36
37
# File 'lib/elibri_onix/onix_3_0/related_product.rb', line 35

def record_reference
  @identifiers.find {|identifier| identifier.type == '01' && identifier.type_name == 'elibri' }.try(:value)          
end