elibri_onix 0.1.23 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. data/Gemfile +1 -0
  2. data/Gemfile.lock +3 -5
  3. data/elibri_onix.gemspec +2 -1
  4. data/lib/elibri_onix.rb +3 -2
  5. data/lib/elibri_onix/external_id.rb +15 -2
  6. data/lib/elibri_onix/external_timestamp.rb +5 -1
  7. data/lib/elibri_onix/nokogiri_patch.rb +17 -0
  8. data/lib/elibri_onix/onix_3_0/audience_range.rb +14 -8
  9. data/lib/elibri_onix/onix_3_0/collection.rb +10 -9
  10. data/lib/elibri_onix/onix_3_0/contributor.rb +21 -18
  11. data/lib/elibri_onix/onix_3_0/extent.rb +18 -11
  12. data/lib/elibri_onix/onix_3_0/header.rb +7 -6
  13. data/lib/elibri_onix/onix_3_0/imprint.rb +6 -5
  14. data/lib/elibri_onix/onix_3_0/language.rb +16 -9
  15. data/lib/elibri_onix/onix_3_0/measure.rb +17 -9
  16. data/lib/elibri_onix/onix_3_0/onix_message.rb +14 -30
  17. data/lib/elibri_onix/onix_3_0/price.rb +19 -17
  18. data/lib/elibri_onix/onix_3_0/product.rb +118 -77
  19. data/lib/elibri_onix/onix_3_0/product_identifier.rb +9 -7
  20. data/lib/elibri_onix/onix_3_0/publisher.rb +19 -9
  21. data/lib/elibri_onix/onix_3_0/publishing_date.rb +10 -9
  22. data/lib/elibri_onix/onix_3_0/related_product.rb +10 -15
  23. data/lib/elibri_onix/onix_3_0/sales_restriction.rb +11 -8
  24. data/lib/elibri_onix/onix_3_0/sender.rb +9 -8
  25. data/lib/elibri_onix/onix_3_0/stock_quantity_coded.rb +8 -11
  26. data/lib/elibri_onix/onix_3_0/subject.rb +19 -13
  27. data/lib/elibri_onix/onix_3_0/supplier.rb +15 -12
  28. data/lib/elibri_onix/onix_3_0/supplier_identifier.rb +9 -8
  29. data/lib/elibri_onix/onix_3_0/supply_detail.rb +16 -15
  30. data/lib/elibri_onix/onix_3_0/supporting_resource.rb +15 -15
  31. data/lib/elibri_onix/onix_3_0/text_content.rb +18 -15
  32. data/lib/elibri_onix/onix_3_0/title_detail.rb +17 -11
  33. data/lib/elibri_onix/onix_3_0/title_element.rb +10 -9
  34. data/lib/elibri_onix/version.rb +1 -1
  35. data/test/elibri_contributors_test.rb +1 -1
  36. data/test/elibri_onix_release_3_0_onix_message_test.rb +2 -2
  37. data/test/elibri_supporting_resources_test.rb +1 -1
  38. data/test/elibri_texts_test.rb +4 -4
  39. data/test/helper.rb +2 -1
  40. metadata +252 -295
@@ -6,23 +6,24 @@ module Elibri
6
6
  module Release_3_0
7
7
 
8
8
  class PublishingDate
9
- include ROXML
10
- include Inspector
11
-
12
- xml_name 'PublishingDate'
13
-
14
- xml_accessor :role, :from => 'PublishingDateRole'
15
- xml_accessor :format, :from => 'DateFormat'
16
- xml_accessor :date, :from => 'Date'
17
9
 
18
10
  ATTRIBUTES = [
19
11
  :role, :format, :date, :parsed
20
12
  ]
21
13
 
22
14
  RELATIONS = []
15
+
16
+ attr_accessor :role, :format, :date, :to_xml
17
+
18
+ def initialize(data)
19
+ @to_xml = data.to_s
20
+ @role = data.at_xpath('xmlns:PublishingDateRole').try(:text)
21
+ @format = data.at_xpath('xmlns:DateFormat').try(:text)
22
+ @date = data.at_xpath('xmlns:Date').try(:text)
23
+ end
23
24
 
24
25
  def parsed
25
- case format
26
+ case @format
26
27
  when '00' then [date[0...4].to_i, date[4...6].to_i, date[6...8].to_i]
27
28
  when '01' then [date[0...4].to_i, date[4...6].to_i]
28
29
  when '05' then [date[0...4].to_i]
@@ -7,38 +7,33 @@ module Elibri
7
7
  module Release_3_0
8
8
 
9
9
  class RelatedProduct
10
- include ROXML
11
- include Inspector
12
-
13
- xml_name 'RelatedProduct'
14
-
15
- xml_accessor :relation_code, :from => 'ProductRelationCode'
16
- xml_accessor :identifiers, :as => [ProductIdentifier]
17
10
 
18
11
  ATTRIBUTES = [
19
- :relation_code, :isbn13, :proprietary_identifiers, :record_reference
12
+ :relation_code, :proprietary_identifiers, :record_reference
20
13
  ]
21
14
 
22
15
  RELATIONS = [
23
16
  :identifiers
24
17
  ]
25
18
 
26
-
27
-
28
- def isbn13
29
- identifiers.find {|identifier| identifier.type == 15}.try(:value)
19
+ attr_accessor :relation_code, :identifiers, :to_xml
20
+
21
+ def initialize(data)
22
+ @to_xml = data.to_s
23
+ @relation_code = data.at_xpath('xmlns:ProductRelationCode').try(:text)
24
+ @identifiers = data.xpath('xmlns:ProductIdentifier').map { |identifier_data| ProductIdentifier.new(identifier_data) }
30
25
  end
31
26
 
32
27
 
33
28
  def record_reference
34
- identifiers.find {|identifier| identifier.type.to_s == '01' && identifier.type_name == 'elibri' }.try(:value)
29
+ @identifiers.find {|identifier| identifier.type == '01' && identifier.type_name == 'elibri' }.try(:value)
35
30
  end
36
31
 
37
32
 
38
33
  def proprietary_identifiers
39
34
  Hash.new.tap do |hash|
40
- identifiers.each do |identifier|
41
- hash[identifier.type_name] = identifier.value if identifier.type == 1
35
+ @identifiers.each do |identifier|
36
+ hash[identifier.type_name] = identifier.value if identifier.type == '01'
42
37
  end
43
38
  end
44
39
  end
@@ -6,20 +6,23 @@ module Elibri
6
6
  module Release_3_0
7
7
 
8
8
  class SalesRestriction
9
- include ROXML
10
- include Inspector
11
-
12
- xml_name 'SalesRestriction'
13
-
14
- xml_accessor :type, :from => 'SalesRestrictionType', :as => Fixnum
15
- xml_accessor :outlet_name, :from => 'SalesOutletName', :in => 'SalesOutlet'
16
- xml_accessor :end_date, :from => 'EndDate', :as => Date
17
9
 
18
10
  ATTRIBUTES = [
19
11
  :type, :outlet_name, :end_date
20
12
  ]
21
13
 
22
14
  RELATIONS = []
15
+
16
+ attr_accessor :type, :outlet_name, :end_date, :to_xml
17
+
18
+ def initialize(data)
19
+ @to_xml = data.to_s
20
+ @type = data.at_xpath('xmlns:SalesRestrictionType').try(:text).try(:to_i)
21
+ if data.at_xpath('xmlns:SalesOutlet')
22
+ @outlet_name = data.at_xpath('xmlns:SalesOutlet').at_xpath('xmlns:SalesOutletName').try(:text)
23
+ end
24
+ @end_date = Date.parse(data.at_xpath('xmlns:EndDate').try(:text)) if data.at_xpath('xmlns:EndDate')
25
+ end
23
26
 
24
27
  end
25
28
 
@@ -4,14 +4,8 @@ module Elibri
4
4
  module Release_3_0
5
5
 
6
6
  class Sender
7
- include ROXML
8
- include Inspector
9
-
10
- xml_name 'Sender'
11
-
12
- xml_accessor :sender_name, :from => 'SenderName'
13
- xml_accessor :contact_name, :from => 'ContactName'
14
- xml_accessor :email_address, :from => 'EmailAddress'
7
+
8
+ attr_accessor :sender_name, :contact_name, :email_address, :to_xml
15
9
 
16
10
  ATTRIBUTES = [
17
11
  :sender_name, :contact_name, :email_address
@@ -19,6 +13,13 @@ module Elibri
19
13
 
20
14
  RELATIONS = []
21
15
 
16
+ def initialize(data)
17
+ @to_xml = data.to_s
18
+ @sender_name = data.at_xpath('xmlns:SenderName').text
19
+ @contact_name = data.at_xpath('xmlns:ContactName').text
20
+ @email_address = data.at_xpath('xmlns:EmailAddress').text
21
+ end
22
+
22
23
  end
23
24
 
24
25
  end
@@ -1,26 +1,23 @@
1
-
2
-
3
-
4
-
5
1
  module Elibri
6
2
  module ONIX
7
3
  module Release_3_0
8
4
 
9
5
  class StockQuantityCoded
10
- include ROXML
11
- include Inspector
12
6
 
13
- xml_name 'StockQuantityCoded'
14
-
15
- xml_accessor :code_type, :from => 'StockQuantityCodeType', :as => Fixnum
16
- xml_accessor :code, :from => 'StockQuantityCode'
17
-
18
7
  ATTRIBUTES = [
19
8
  :code_type, :code
20
9
  ]
21
10
 
22
11
  RELATIONS = []
23
12
 
13
+ attr_accessor :code_type, :code, :to_xml
14
+
15
+ def initialize(data)
16
+ @to_xml = data.to_s
17
+ @code_type = data.at_xpath('xmlns:StockQuantityCodeType').try(:text).try(:to_i)
18
+ @code = data.at_xpath('xmlns:StockQuantityCode').try(:text)
19
+ end
20
+
24
21
  end
25
22
 
26
23
  end
@@ -5,30 +5,36 @@ module Elibri
5
5
  module Release_3_0
6
6
 
7
7
  class Subject
8
- include ROXML
9
- include Inspector
10
-
11
- xml_name 'Subject'
12
- xml_accessor :scheme_identifier, :from => 'SubjectSchemeIdentifier', :as => Fixnum
13
- xml_accessor :scheme_name, :from => 'SubjectSchemeName'
14
- xml_accessor :scheme_version, :from => 'SubjectSchemeVersion'
15
- xml_accessor :code, :from => 'SubjectCode'
16
- xml_accessor :heading_text, :from => 'SubjectHeadingText'
17
-
18
- xml_accessor :main_subject, :from => 'MainSubject'
19
8
 
20
9
  ATTRIBUTES = [
21
10
  :scheme_identifier, :scheme_name, :scheme_version, :code, :heading_text, :main_subject
22
11
  ]
23
12
 
13
+ attr_accessor :scheme_identifier, :scheme_name, :scheme_version, :code, :heading_text, :main_subject, :to_xml
14
+
24
15
  RELATIONS = []
16
+
17
+ def initialize(data)
18
+ @to_xml = data.to_s
19
+ @scheme_identifier = data.xpath('xmlns:SubjectSchemeIdentifier').try(:text).try(:to_i)
20
+ @scheme_name = data.xpath('xmlns:SubjectSchemeName').try(:text)
21
+ @scheme_version = data.xpath('xmlns:SubjectSchemeVersion').try(:text)
22
+ @code = data.xpath('xmlns:SubjectCode').try(:text)
23
+ @heading_text = data.xpath('xmlns:SubjectHeadingText').try(:text)
24
+ @main_subject = data.xpath('xmlns:MainSubject').blank? ? nil : ''
25
+ end
25
26
 
26
27
  def main_subject?
27
- main_subject == ''
28
+ @main_subject == ''
28
29
  end
29
30
 
31
+ def eid
32
+ @code
33
+ end
34
+
30
35
  def id
31
- code
36
+ Kernel.warn "[DEPRECATION] `id` is deprecated. Please use `eid` instead."
37
+ eid
32
38
  end
33
39
 
34
40
  end
@@ -6,17 +6,6 @@ module Elibri
6
6
  module Release_3_0
7
7
 
8
8
  class Supplier
9
- include ROXML
10
- include Inspector
11
-
12
- xml_name 'Supplier'
13
-
14
- xml_accessor :role, :from => 'SupplierRole', :as => Fixnum
15
- xml_accessor :identifiers, :as => [SupplierIdentifier]
16
- xml_accessor :name, :from => 'SupplierName'
17
- xml_accessor :telephone_number, :from => 'TelephoneNumber'
18
- xml_accessor :email_address, :from => 'EmailAddress'
19
- xml_accessor :website, :from => 'WebsiteLink', :in => 'Website'
20
9
 
21
10
  ATTRIBUTES = [
22
11
  :role, :name, :telephone_number, :email_address, :website, :nip
@@ -25,9 +14,23 @@ module Elibri
25
14
  RELATIONS = [
26
15
  :identifiers
27
16
  ]
17
+
18
+ attr_accessor :role, :identifiers, :name, :telephone_number, :email_address, :website, :to_xml
19
+
20
+ def initialize(data)
21
+ @to_xml = data.to_s
22
+ @role = data.at_xpath('xmlns:SupplierRole').try(:text).try(:to_i)
23
+ @identifiers = data.xpath('xmlns:SupplierIdentifier').map { |identifier_data| SupplierIdentifier.new(identifier_data) }
24
+ @name = data.at_xpath('xmlns:SupplierName').try(:text)
25
+ @telephone_number = data.at_xpath('xmlns:TelephoneNumber').try(:text)
26
+ @email_address = data.at_xpath('xmlns:EmailAddress').try(:text)
27
+ if data.at_xpath('xmlns:Website')
28
+ @website = data.at_xpath('xmlns:Website').at_xpath('xmlns:WebsiteLink').try(:text)
29
+ end
30
+ end
28
31
 
29
32
  def nip
30
- identifiers.find {|identifier| (identifier.type == 2) && (identifier.type_name == 'NIP')}.try(:value)
33
+ @identifiers.find {|identifier| (identifier.type == '02') && (identifier.type_name == 'NIP')}.try(:value)
31
34
  end
32
35
 
33
36
  end
@@ -7,20 +7,21 @@ module Elibri
7
7
  module Release_3_0
8
8
 
9
9
  class SupplierIdentifier
10
- include ROXML
11
- include Inspector
12
-
13
- xml_name 'SupplierIdentifier'
14
-
15
- xml_accessor :type, :from => 'SupplierIDType', :as => Fixnum
16
- xml_accessor :type_name, :from => 'IDTypeName'
17
- xml_accessor :value, :from => 'IDValue'
18
10
 
19
11
  ATTRIBUTES = [
20
12
  :type, :type_name, :value
21
13
  ]
22
14
 
23
15
  RELATIONS = []
16
+
17
+ attr_accessor :type, :type_name, :value, :to_xml
18
+
19
+ def initialize(data)
20
+ @to_xml = data.to_s
21
+ @type = data.at_xpath('xmlns:SupplierIDType').try(:text)
22
+ @type_name = data.at_xpath('xmlns:IDTypeName').try(:text)
23
+ @value = data.at_xpath('xmlns:IDValue').try(:text)
24
+ end
24
25
 
25
26
  end
26
27
  end
@@ -6,29 +6,30 @@ module Elibri
6
6
  module Release_3_0
7
7
 
8
8
  class SupplyDetail
9
- include ROXML
10
- include Inspector
11
-
12
- xml_name 'SupplyDetail'
13
-
14
- xml_accessor :relation_code, :from => 'ProductRelationCode', :as => Fixnum
15
- xml_accessor :supplier, :as => Supplier
16
- xml_accessor :product_availability, :from => 'ProductAvailability', :as => Fixnum
17
- xml_accessor :pack_quantity, :from => 'PackQuantity', :as => Fixnum
18
- xml_accessor :price, :as => Price
19
-
20
-
21
- xml_accessor :on_hand, :in => 'Stock', :from => 'OnHand', :as => Fixnum
22
- xml_accessor :quantity_coded, :in => 'Stock', :as => StockQuantityCoded
23
9
 
24
10
  ATTRIBUTES = [
25
11
  :relation_code, :supplier, :product_availability, :pack_quantity, :price, :on_hand, :quantity_coded, :quantity_code
26
12
  ]
13
+
14
+ attr_accessor :relation_code, :supplier, :product_availability, :pack_quantity, :price, :on_hand, :quantity_coded, :to_xml
27
15
 
28
16
  RELATIONS = []
17
+
18
+ def initialize(data)
19
+ @to_xml = data.to_s
20
+ @relation_code = data.at_xpath('xmlns:ProductRelationCode').try(:text).try(:to_i)
21
+ @supplier = Supplier.new(data.at_xpath('xmlns:Supplier')) if data.at_xpath('xmlns:Supplier')
22
+ @product_availability = data.at_xpath('xmlns:ProductAvailability').try(:text).try(:to_i)
23
+ @pack_quantity = data.at_xpath('xmlns:PackQuantity').try(:text).try(:to_i)
24
+ @price = Price.new(data.at_xpath('xmlns:Price')) if data.at_xpath('xmlns:Price')
25
+ if data.at_xpath('xmlns:Stock')
26
+ @on_hand = data.at_xpath('xmlns:Stock').at_xpath('xmlns:OnHand').try(:text).try(:to_i)
27
+ @quantity_coded = StockQuantityCoded.new(data.at_xpath('xmlns:Stock').at_xpath('xmlns:StockQuantityCoded')) if data.at_xpath('xmlns:Stock').at_xpath('xmlns:StockQuantityCoded')
28
+ end
29
+ end
29
30
 
30
31
  def quantity_code
31
- quantity_coded.try(:code)
32
+ @quantity_coded.try(:code)
32
33
  end
33
34
 
34
35
  end
@@ -5,20 +5,8 @@ module Elibri
5
5
  module Release_3_0
6
6
 
7
7
  class SupportingResource
8
- include ROXML
9
- include Inspector
10
8
  include ExternalId
11
9
  include ExternalTimestamp
12
-
13
-
14
- xml_name 'SupportingResource'
15
-
16
- xml_accessor :content_type, :from => 'ResourceContentType'
17
- #xml_accessor :audience, :from => 'ContentAudience' - always unrestricted
18
- xml_accessor :mode, :from => 'ResourceMode'
19
-
20
- xml_accessor :form, :in => 'ResourceVersion', :from => 'ResourceForm'
21
- xml_accessor :link, :in => 'ResourceVersion', :from => 'ResourceLink'
22
10
 
23
11
  ATTRIBUTES = [
24
12
  :content_type, :mode, :form, :link, :content_type_name, :mode_name, :form_name
@@ -27,9 +15,21 @@ module Elibri
27
15
  RELATIONS = [
28
16
  :inspect_include_fields
29
17
  ]
18
+
19
+ attr_accessor :content_type, :mode, :form, :link, :to_xml
20
+
21
+ def initialize(data)
22
+ @to_xml = data.to_s
23
+ @content_type = data.at_xpath('xmlns:ResourceContentType').try(:text)
24
+ @mode = data.at_xpath('xmlns:ResourceMode').try(:text)
25
+ @form = data.at_xpath('xmlns:ResourceVersion').at_xpath('xmlns:ResourceForm').try(:text)
26
+ @link = data.at_xpath('xmlns:ResourceVersion').at_xpath('xmlns:ResourceLink').try(:text)
27
+ set_eid(data)
28
+ set_datestamp(data)
29
+ end
30
30
 
31
31
  def content_type_name
32
- Elibri::ONIX::Dict::Release_3_0::ResourceContentType.find_by_onix_code(content_type).const_name.downcase
32
+ Elibri::ONIX::Dict::Release_3_0::ResourceContentType.find_by_onix_code(@content_type).const_name.downcase
33
33
  end
34
34
 
35
35
  #def audience_name
@@ -37,11 +37,11 @@ module Elibri
37
37
  #end
38
38
 
39
39
  def mode_name
40
- Elibri::ONIX::Dict::Release_3_0::ResourceMode.find_by_onix_code(mode).const_name.downcase
40
+ Elibri::ONIX::Dict::Release_3_0::ResourceMode.find_by_onix_code(@mode).const_name.downcase
41
41
  end
42
42
 
43
43
  def form_name
44
- Elibri::ONIX::Dict::Release_3_0::ResourceForm.find_by_onix_code(form).const_name.downcase
44
+ Elibri::ONIX::Dict::Release_3_0::ResourceForm.find_by_onix_code(@form).const_name.downcase
45
45
  end
46
46
 
47
47
  def inspect_include_fields
@@ -4,20 +4,8 @@ module Elibri
4
4
  module Release_3_0
5
5
 
6
6
  class TextContent
7
- include ROXML
8
- include Inspector
9
- include ExternalId
10
- include ExternalTimestamp
11
-
12
- xml_name 'TextContent'
13
-
14
- xml_accessor :type, :from => 'TextType'
15
- #xml_accessor :audience, :from => 'ContentAudience' - always unrestricted
16
- xml_accessor :author, :from => 'TextAuthor'
17
- xml_accessor :source_title, :from => 'SourceTitle'
18
-
19
- xml_accessor :text, :from => 'Text', :cdata => true
20
- xml_accessor :source_url, :from => '@sourcename', :in => 'Text'
7
+ include ExternalId
8
+ include ExternalTimestamp
21
9
 
22
10
  ATTRIBUTES = [
23
11
  :type, :author, :source_title, :text, :source_url, :type_name
@@ -26,9 +14,24 @@ module Elibri
26
14
  RELATIONS = [
27
15
  :inspect_include_fields
28
16
  ]
17
+
18
+ attr_accessor :type, :author, :source_title, :text, :source_url, :to_xml
19
+
20
+ def initialize(data)
21
+ @to_xml = data.to_s
22
+ @type = data.at_xpath('xmlns:TextType').try(:text)
23
+ @author = data.at_xpath('xmlns:TextAuthor').try(:text)
24
+ @source_title = data.at_xpath('xmlns:SourceTitle').try(:text)
25
+ if data.at_xpath('xmlns:Text')
26
+ @text = data.at_xpath('xmlns:Text').children.find { |x| x.cdata? }.try(:text) #cdata => true ?
27
+ @source_url = data.at_xpath('xmlns:Text').attribute('sourcename').try(:text)
28
+ end
29
+ set_eid(data)
30
+ set_datestamp(data)
31
+ end
29
32
 
30
33
  def type_name
31
- Elibri::ONIX::Dict::Release_3_0::OtherTextType.find_by_onix_code(type).const_name.downcase
34
+ Elibri::ONIX::Dict::Release_3_0::OtherTextType.find_by_onix_code(@type).const_name.downcase
32
35
  end
33
36
 
34
37