/
onix_message.rb
39 lines (29 loc) · 1.16 KB
/
onix_message.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
module Elibri
module ONIX
module Release_3_0
class ONIXMessage
attr_accessor :release, :elibri_dialect, :products, :header, :to_xml
#class representing whole ONIX response from eLibri server
ATTRIBUTES = [
:release, :elibri_dialect, :header
]
RELATIONS = [
:products
]
def self.from_xml(data, *initialization_args)
Kernel.warn "[DEPRECATION] `from_xml` is deprecated. Please use `new` instead."
self.new(data, *initialization_args)
end
def initialize(data, *initialization_args)
@to_xml = data.to_s
xml = Nokogiri::XML(data) unless xml.is_a?(Nokogiri::XML::Document)
onix_message = xml.children.first
@release = onix_message['release']
@elibri_dialect = onix_message.at_xpath('elibri:Dialect').try(:text)
@header = Header.new(onix_message.at_xpath('xmlns:Header')) if onix_message.at_xpath('xmlns:Header')
@products = onix_message.xpath('xmlns:Product').map { |product_node| Product.new(product_node) }
end
end
end
end
end