Class: Elibri::ONIX::Release_3_0::ONIXMessage

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

Overview

class representing whole ONIX response from eLibri server

Constant Summary collapse

ATTRIBUTES =

:nodoc:

[
  :release, :header
]
RELATIONS =

:nodoc:

[
  :products
]

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

Methods included from Inspector

#attribute_for_inspect, #inspect

Constructor Details

#initialize(xml, *initialization_args) ⇒ ONIXMessage

Returns a new instance of ONIXMessage.



41
42
43
44
45
46
47
48
49
# File 'lib/elibri_onix/onix_3_0/onix_message.rb', line 41

def initialize(xml, *initialization_args)
  @to_xml = xml.to_s
  xml = Nokogiri::XML(xml) unless xml.is_a?(Nokogiri::XML::Document)
  onix_message = xml.children.first
  @attributes = extract_attributes(onix_message.attribute_nodes)
  @release = onix_message['release']
  @header = Header.new(onix_message.at_css('Header')) if onix_message.at_css('Header')
  @products = onix_message.css('Product').map { |product_node| Product.new(product_node) }
end

Instance Attribute Details

#attributesObject (readonly)

attributes of root ONIXMessage node



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

def attributes
  @attributes
end

#headerObject

returned message header - Elibri::ONIX::Release_3_0::Header



20
21
22
# File 'lib/elibri_onix/onix_3_0/onix_message.rb', line 20

def header
  @header
end

#productsObject

list of all products returned in this mnessage



11
12
13
# File 'lib/elibri_onix/onix_3_0/onix_message.rb', line 11

def products
  @products
end

#releaseObject

ONIX version number



17
18
19
# File 'lib/elibri_onix/onix_3_0/onix_message.rb', line 17

def release
  @release
end

#to_xmlObject

xml representation of this message



14
15
16
# File 'lib/elibri_onix/onix_3_0/onix_message.rb', line 14

def to_xml
  @to_xml
end

Instance Method Details

#inspect_include_fieldsObject



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

def inspect_include_fields
  [:header, :release, :products]
end