elibri_onix 0.4.4 → 0.5.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 (50) hide show
  1. checksums.yaml +4 -4
  2. data/FIELDS.rdoc +2 -2
  3. data/lib/elibri_onix.rb +0 -1
  4. data/lib/elibri_onix/external_id.rb +0 -10
  5. data/lib/elibri_onix/onix_3_0/audience_range.rb +3 -12
  6. data/lib/elibri_onix/onix_3_0/collection.rb +0 -0
  7. data/lib/elibri_onix/onix_3_0/contributor.rb +11 -11
  8. data/lib/elibri_onix/onix_3_0/excerpt_info.rb +29 -10
  9. data/lib/elibri_onix/onix_3_0/extent.rb +3 -12
  10. data/lib/elibri_onix/onix_3_0/file_info.rb +0 -5
  11. data/lib/elibri_onix/onix_3_0/header.rb +2 -2
  12. data/lib/elibri_onix/onix_3_0/imprint.rb +1 -1
  13. data/lib/elibri_onix/onix_3_0/language.rb +2 -13
  14. data/lib/elibri_onix/onix_3_0/measure.rb +3 -12
  15. data/lib/elibri_onix/onix_3_0/onix_message.rb +4 -16
  16. data/lib/elibri_onix/onix_3_0/price.rb +11 -11
  17. data/lib/elibri_onix/onix_3_0/product.rb +137 -69
  18. data/lib/elibri_onix/onix_3_0/product_identifier.rb +3 -3
  19. data/lib/elibri_onix/onix_3_0/publisher.rb +4 -11
  20. data/lib/elibri_onix/onix_3_0/publishing_date.rb +3 -3
  21. data/lib/elibri_onix/onix_3_0/related_product.rb +2 -2
  22. data/lib/elibri_onix/onix_3_0/sales_restriction.rb +4 -4
  23. data/lib/elibri_onix/onix_3_0/sender.rb +3 -3
  24. data/lib/elibri_onix/onix_3_0/stock_quantity_coded.rb +2 -2
  25. data/lib/elibri_onix/onix_3_0/supplier.rb +7 -7
  26. data/lib/elibri_onix/onix_3_0/supplier_identifier.rb +3 -3
  27. data/lib/elibri_onix/onix_3_0/supply_detail.rb +15 -10
  28. data/lib/elibri_onix/onix_3_0/supporting_resource.rb +6 -5
  29. data/lib/elibri_onix/onix_3_0/text_content.rb +6 -6
  30. data/lib/elibri_onix/onix_3_0/thema_subject.rb +33 -0
  31. data/lib/elibri_onix/onix_3_0/title_detail.rb +2 -11
  32. data/lib/elibri_onix/onix_3_0/title_element.rb +4 -4
  33. data/lib/elibri_onix/releases.rb +2 -2
  34. data/lib/elibri_onix/version.rb +1 -1
  35. data/test/cover_test.rb +18 -0
  36. data/test/elibri_audiobook_test.rb +33 -0
  37. data/test/elibri_extensions_test.rb +9 -0
  38. data/test/elibri_onix_release_3_0_onix_message_test.rb +4 -18
  39. data/test/elibri_subjects_test.rb +30 -0
  40. data/test/elibri_supporting_resources_test.rb +4 -2
  41. data/test/fixtures/all_possible_tags.xml +1 -1
  42. data/test/fixtures/onix_audiobook_example.xml +261 -0
  43. data/test/fixtures/onix_removed_elibri_extensions.xml +81 -0
  44. data/test/fixtures/onix_subjects_example.xml +110 -0
  45. data/test/fixtures/onix_supporting_resources_example.xml +15 -5
  46. metadata +9 -6
  47. data/lib/elibri_onix/nokogiri_patch.rb +0 -17
  48. data/lib/elibri_onix/onix_3_0/subject.rb +0 -50
  49. data/test/elibri_categories_test.rb +0 -18
  50. data/test/fixtures/onix_categories_example.xml +0 -59
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d69912737892405619e73b9ddeac017b128bac8b1919a437c3105b5287b3e49e
4
- data.tar.gz: f3f5d46f1409ca1f0383b0aa177a729ee8019b9a1baf7bd1067cf2b5d0458cf7
3
+ metadata.gz: 2cdd498f6472afd58950a7d29d6e105b8ebda1c30d4cb79459c1ef398a6b6cd4
4
+ data.tar.gz: a371442b7450ded0b5b174fa78a34395cad1ac40f30e9f94675949be90aecabd
5
5
  SHA512:
6
- metadata.gz: 01119d48727fbbaee300efe03479dd8a9fd30998916d9d3c0ad042ca7438c99ffbfc9e6eee3772d90b584c3ed32411b8eda35e9ba8853b6ea0ef1e194ad11e8a
7
- data.tar.gz: 6280ee4543ed1c16b8b9a716bb3db38a75c6457d78b96e505affcb175e89140d0f0a9212cf0ac975b4f87b14f579518a42faea3a81703c7d1902e2467b9d5c39
6
+ metadata.gz: b27daea722145431c90f22c88c42c084846563889159e57b6b28bd2441f2f09bb4eb9e4910eb98c1ff7b366957023c1a85f7bb97bc1fd72eda15b850594e9be1
7
+ data.tar.gz: a0b0e1900efaba5ab42637c9a073ce4d7b0e5187b6d56f774b7f53440a0fabac82a6edeaf085dca225d6319a2d6746b14b1526ff40f714809bbfb0f24a8527ad
@@ -59,7 +59,7 @@ inspect_include_fields
59
59
 
60
60
  == ONIXMessage
61
61
  === Attributes
62
- release, elibri_dialect, header
62
+ release, header
63
63
  === Relations
64
64
  products
65
65
 
@@ -70,7 +70,7 @@ type, minimum_order_quantity, amount, currency_code, printed_on_product, positio
70
70
 
71
71
  == Product
72
72
  === Attributes
73
- elibri_dialect, height, width, thickness, weight, ean, isbn13, number_of_pages, duration, file_size, publisher_name, publisher_id, imprint_name, current_state, reading_age_from, reading_age_to, table_of_contents, description, reviews, excerpts, series, title, subtitle, collection_title, collection_part, full_title, original_title, trade_title, parsed_publishing_date, record_reference, deletion_text, cover_type, cover_price, vat, pkwiu, additional_info, product_composition, publisher, product_form, no_contributor, edition_statement, number_of_illustrations, publishing_status, publishing_date, premiere, front_cover, series_names, city_of_publication, elibri_product_category1_id, elibri_product_category2_id, preview_exists, short_description, sale_restricted_to_poland, technical_protection_onix_code, unlimited_licence, hyphenated_isbn, preorder_embargo_date
73
+ height, width, thickness, weight, ean, isbn13, number_of_pages, duration, file_size, publisher_name, publisher_id, imprint_name, current_state, reading_age_from, reading_age_to, table_of_contents, description, reviews, excerpts, series, title, subtitle, collection_title, collection_part, full_title, original_title, trade_title, parsed_publishing_date, record_reference, deletion_text, cover_type, cover_price, vat, pkwiu, additional_info, product_composition, publisher, product_form, no_contributor, edition_statement, number_of_illustrations, publishing_status, publishing_date, premiere, front_cover, series_names, city_of_publication, preview_exists, short_description, sale_restricted_to_poland, technical_protection_onix_code, unlimited_licence, hyphenated_isbn, preorder_embargo_date
74
74
  === Relations
75
75
  contributors, related_products, languages, measures, supply_details, measures, title_details, collections, extents, subjects, audience_ranges, text_contents, supporting_resources, sales_restrictions, authors, ghostwriters, scenarists, originators, illustrators, photographers, author_of_prefaces, drawers, cover_designers, inked_or_colored_bys, editors, revisors, translators, editor_in_chiefs, read_bys
76
76
 
@@ -12,7 +12,6 @@ require 'elibri_onix/external_id'
12
12
  require 'elibri_onix/hash_id'
13
13
  require 'elibri_onix/external_timestamp'
14
14
  require 'elibri_onix/releases'
15
- require 'elibri_onix/nokogiri_patch'
16
15
  require 'elibri_onix_dict'
17
16
 
18
17
 
@@ -1,9 +1,5 @@
1
1
  module ExternalId
2
2
 
3
- # def self.included(base)
4
- # base.xml_accessor :id_before_type_cast, :from => "@sourcename"
5
- # end
6
-
7
3
  def self.included(base)
8
4
  base.send(:attr_accessor, :id_before_type_cast)
9
5
  end
@@ -19,10 +15,4 @@ module ExternalId
19
15
  nil
20
16
  end
21
17
  end
22
-
23
- def id
24
- Kernel.warn "[DEPRECATION] `id` is deprecated. Please use `eid` instead."
25
- eid
26
- end
27
-
28
18
  end
@@ -21,18 +21,9 @@ module Elibri
21
21
 
22
22
  def initialize(data)
23
23
  @old_xml = data.to_s
24
- @qualifier = data.at_xpath('xmlns:AudienceRangeQualifier').try(:text)
25
- @precision = data.at_xpath('xmlns:AudienceRangePrecision').try(:text)
26
- @value = data.at_xpath('xmlns:AudienceRangeValue').try(:text).try(:to_i)
27
- end
28
-
29
- def eid
30
- "#{@qualifier}-#{@precision}-#{@value}"
31
- end
32
-
33
- def id
34
- Kernel.warn "[DEPRECATION] `id` is deprecated. Please use `eid` instead."
35
- eid
24
+ @qualifier = data.at_css('AudienceRangeQualifier').try(:text)
25
+ @precision = data.at_css('AudienceRangePrecision').try(:text)
26
+ @value = data.at_css('AudienceRangeValue').try(:text).try(:to_i)
36
27
  end
37
28
 
38
29
  end
@@ -72,17 +72,17 @@ module Elibri
72
72
 
73
73
  def initialize(data)
74
74
  @to_xml = data.to_s
75
- @number = data.at_xpath('xmlns:SequenceNumber').try(:text).try(:to_i)
76
- @role = data.at_xpath('xmlns:ContributorRole').try(:text)
77
- @person_name = data.at_xpath('xmlns:PersonName').try(:text)
78
- @from_language = data.at_xpath('xmlns:FromLanguage').try(:text)
79
- @titles_before_names = data.at_xpath('xmlns:TitlesBeforeNames').try(:text)
80
- @names_before_key = data.at_xpath('xmlns:NamesBeforeKey').try(:text)
81
- @prefix_to_key = data.at_xpath('xmlns:PrefixToKey').try(:text)
82
- @key_names = data.at_xpath('xmlns:KeyNames').try(:text)
83
- @names_after_key = data.at_xpath('xmlns:NamesAfterKey').try(:text)
84
- @biographical_note = data.at_xpath('xmlns:BiographicalNote').try(:text)
85
- @unnamed_persons = data.at_xpath('xmlns:UnnamedPersons').try(:text)
75
+ @number = data.at_css('SequenceNumber').try(:text).try(:to_i)
76
+ @role = data.at_css('ContributorRole').try(:text)
77
+ @person_name = data.at_css('PersonName').try(:text)
78
+ @from_language = data.at_css('FromLanguage').try(:text)
79
+ @titles_before_names = data.at_css('TitlesBeforeNames').try(:text)
80
+ @names_before_key = data.at_css('NamesBeforeKey').try(:text)
81
+ @prefix_to_key = data.at_css('PrefixToKey').try(:text)
82
+ @key_names = data.at_css('KeyNames').try(:text)
83
+ @names_after_key = data.at_css('NamesAfterKey').try(:text)
84
+ @biographical_note = data.at_css('BiographicalNote').try(:text)
85
+ @unnamed_persons = data.at_css('UnnamedPersons').try(:text)
86
86
  set_eid(data)
87
87
  set_datestamp(data)
88
88
  end
@@ -20,17 +20,36 @@ module Elibri
20
20
 
21
21
  def initialize(data)
22
22
  @to_xml = data.to_s
23
- @file_type = data.attributes['file_type'].value
24
- @file_size = data.attributes['file_size'].value.to_i
25
- @md5 = data.attributes['md5'].value
26
- @updated_at = Time.parse(data.attributes['updated_at'].value)
27
- @link = data.text
28
- @eid = data.attributes['id'].value.to_i
29
- end
23
+ if data.name == "excerpt"
24
+ @file_type = data.attributes['file_type'].value
25
+ @file_size = data.attributes['file_size'].value.to_i
26
+ @md5 = data.attributes['md5'].value
27
+ @updated_at = Time.parse(data.attributes['updated_at'].value)
28
+ @link = data.text
29
+ @eid = data.attributes['id'].value.to_i
30
+ elsif data.name == "ResourceVersion"
31
+
32
+ last_updated_node = data.css("ContentDate").find { |date|
33
+ date.css("ContentDateRole").first.inner_text == Elibri::ONIX::Dict::Release_3_0::ContentDateRole::LAST_UPDATED }
30
34
 
31
- def id
32
- Kernel.warn "[DEPRECATION] `id` is deprecated. Please use `eid` instead."
33
- eid
35
+ if last_updated_node
36
+ @updated_at = Time.parse(last_updated_node.css("Date").first.inner_text)
37
+ end
38
+ @link = data.css("ResourceLink").first.text
39
+ @eid = @link.split("/")[4].to_i
40
+ @file_type = @link.split(".").last + "_excerpt"
41
+ data.css("ResourceVersionFeature").each do |feature|
42
+ feature_type = feature.css("ResourceVersionFeatureType").first.inner_text
43
+ feature_value = feature.css("FeatureValue").first.inner_text
44
+ if feature_type == Elibri::ONIX::Dict::Release_3_0::ResourceVersionFeatureType::MD5_HASH_VALUE
45
+ @md5 = feature_value
46
+ elsif feature_type == Elibri::ONIX::Dict::Release_3_0::ResourceVersionFeatureType::SIZE_IN_BYTES
47
+ @file_size = feature_value.to_i
48
+ end
49
+ end
50
+ else
51
+ raise ArgumentError, "Unknow element for ExcerptInfo: #{data.name}"
52
+ end
34
53
  end
35
54
 
36
55
  def inspect_include_fields
@@ -22,18 +22,9 @@ module Elibri
22
22
 
23
23
  def initialize(data)
24
24
  @to_xml = data.to_s
25
- @type = data.xpath('xmlns:ExtentType').try(:text)
26
- @value = data.xpath('xmlns:ExtentValue').try(:text).try(:to_i)
27
- @unit = data.xpath('xmlns:ExtentUnit').try(:text)
28
- end
29
-
30
- def eid
31
- @type.to_i
32
- end
33
-
34
- def id
35
- Kernel.warn "[DEPRECATION] `id` is deprecated. Please use `eid` instead."
36
- eid
25
+ @type = data.css('ExtentType').try(:text)
26
+ @value = data.css('ExtentValue').try(:text).try(:to_i)
27
+ @unit = data.css('ExtentUnit').try(:text)
37
28
  end
38
29
 
39
30
  def type_name
@@ -27,11 +27,6 @@ module Elibri
27
27
  @eid = data.attributes['id'].value.to_i
28
28
  end
29
29
 
30
- def id
31
- Kernel.warn "[DEPRECATION] `id` is deprecated. Please use `eid` instead."
32
- eid
33
- end
34
-
35
30
  def inspect_include_fields
36
31
  [:file_type]
37
32
  end
@@ -32,8 +32,8 @@ module Elibri
32
32
 
33
33
  def initialize(data)
34
34
  @to_xml = data.to_s
35
- @sent_date_time = Date.parse(data.xpath('xmlns:SentDateTime').try(:text)) if data.xpath('xmlns:SentDateTime')
36
- @sender = Sender.new(data.at_xpath('xmlns:Sender')) if data.at_xpath('xmlns:Sender')
35
+ @sent_date_time = Date.parse(data.css('SentDateTime').try(:text)) if data.css('SentDateTime')
36
+ @sender = Sender.new(data.at_css('Sender')) if data.at_css('Sender')
37
37
  end
38
38
 
39
39
  end
@@ -22,7 +22,7 @@ module Elibri
22
22
 
23
23
  def initialize(data)
24
24
  @to_xml = data.to_s
25
- @name = data.at_xpath('xmlns:ImprintName').try(:text)
25
+ @name = data.at_css('ImprintName').try(:text)
26
26
  end
27
27
 
28
28
  end
@@ -36,8 +36,8 @@ module Elibri
36
36
 
37
37
  def initialize(data)
38
38
  @to_xml = data.to_s
39
- @role = data.at_xpath('xmlns:LanguageRole').try(:text)
40
- @code = data.at_xpath('xmlns:LanguageCode').try(:text)
39
+ @role = data.at_css('LanguageRole').try(:text)
40
+ @code = data.at_css('LanguageCode').try(:text)
41
41
  end
42
42
 
43
43
  #określenie roli jako string, np. language_of_text
@@ -53,18 +53,7 @@ module Elibri
53
53
  def inspect_include_fields
54
54
  [:role_name, :language]
55
55
  end
56
-
57
- def eid
58
- "#{@role}-#{@code}"
59
- end
60
-
61
- def id
62
- Kernel.warn "[DEPRECATION] `id` is deprecated. Please use `eid` instead."
63
- eid
64
- end
65
-
66
56
  end
67
-
68
57
  end
69
58
  end
70
59
  end
@@ -20,9 +20,9 @@ module Elibri
20
20
 
21
21
  def initialize(data)
22
22
  @to_xml = data.to_s
23
- @type = data.at_xpath('xmlns:MeasureType').try(:text)
24
- @measurement = data.at_xpath('xmlns:Measurement').try(:text).try(:to_i)
25
- @unit = data.at_xpath('xmlns:MeasureUnitCode').try(:text)
23
+ @type = data.at_css('MeasureType').try(:text)
24
+ @measurement = data.at_css('Measurement').try(:text).try(:to_i)
25
+ @unit = data.at_css('MeasureUnitCode').try(:text)
26
26
 
27
27
  end
28
28
 
@@ -34,15 +34,6 @@ module Elibri
34
34
  [:type_name]
35
35
  end
36
36
 
37
- # def eid
38
- # @type.to_i
39
- # end
40
-
41
- def id
42
- Kernel.warn "[DEPRECATION] `id` is deprecated. Please use `eid` instead."
43
- eid
44
- end
45
-
46
37
  end
47
38
 
48
39
  end
@@ -16,9 +16,6 @@ module Elibri
16
16
  #ONIX version number
17
17
  attr_accessor :release
18
18
 
19
- #:nodoc:
20
- attr_accessor :elibri_dialect
21
-
22
19
  #returned message header - Elibri::ONIX::Release_3_0::Header
23
20
  attr_accessor :header
24
21
 
@@ -26,7 +23,7 @@ module Elibri
26
23
 
27
24
  #:nodoc:
28
25
  ATTRIBUTES = [
29
- :release, :elibri_dialect, :header
26
+ :release, :header
30
27
  ]
31
28
 
32
29
  #:nodoc:
@@ -35,26 +32,17 @@ module Elibri
35
32
  ]
36
33
 
37
34
  def inspect_include_fields
38
- [:header, :elibri_dialect, :release, :products]
35
+ [:header, :release, :products]
39
36
  end
40
37
 
41
-
42
- def self.from_xml(data, *initialization_args)
43
- Kernel.warn "[DEPRECATION] `from_xml` is deprecated. Please use `new` instead."
44
- self.new(data, *initialization_args)
45
- end
46
-
47
38
  def initialize(xml, *initialization_args)
48
39
  @to_xml = xml.to_s
49
40
  xml = Nokogiri::XML(xml) unless xml.is_a?(Nokogiri::XML::Document)
50
41
  onix_message = xml.children.first
51
42
  @release = onix_message['release']
52
- @elibri_dialect = onix_message.at_xpath('elibri:Dialect').try(:text)
53
- @header = Header.new(onix_message.at_xpath('xmlns:Header')) if onix_message.at_xpath('xmlns:Header')
54
- @products = onix_message.xpath('xmlns:Product').map { |product_node| Product.new(product_node) }
43
+ @header = Header.new(onix_message.at_css('Header')) if onix_message.at_css('Header')
44
+ @products = onix_message.css('Product').map { |product_node| Product.new(product_node) }
55
45
  end
56
-
57
-
58
46
  end
59
47
 
60
48
  end
@@ -25,25 +25,25 @@ module Elibri
25
25
 
26
26
  def initialize(data)
27
27
  @to_xml = data.to_s
28
- @type = data.at_xpath('xmlns:PriceType').try(:text).try(:to_i)
29
- @minimum_order_quantity = data.at_xpath('xmlns:MinimumOrderQuantity').try(:text).try(:to_i)
30
- @amount = BigDecimal(data.at_xpath('xmlns:PriceAmount').try(:text))
31
- @currency_code = data.at_xpath('xmlns:CurrencyCode').try(:text)
32
- @printed_on_product = data.at_xpath('xmlns:PrintedOnProduct').try(:text).try(:to_i)
33
- @position_on_product = data.at_xpath('xmlns:PositionOnProduct').try(:text).try(:to_i)
34
- if data.at_xpath('xmlns:Tax')
35
- @tax_type = data.at_xpath('xmlns:Tax').at_xpath('xmlns:TaxType').try(:text).try(:to_i)
36
- @tax_rate_percent = BigDecimal(data.at_xpath('xmlns:Tax').at_xpath('xmlns:TaxRatePercent').try(:text)) if data.at_xpath('xmlns:Tax').at_xpath('xmlns:TaxRatePercent')
28
+ @type = data.at_css('PriceType').try(:text)
29
+ @minimum_order_quantity = data.at_css('MinimumOrderQuantity').try(:text).try(:to_i)
30
+ @amount = BigDecimal(data.at_css('PriceAmount').try(:text))
31
+ @currency_code = data.at_css('CurrencyCode').try(:text)
32
+ @printed_on_product = data.at_css('PrintedOnProduct').try(:text)
33
+ @position_on_product = data.at_css('PositionOnProduct').try(:text)
34
+ if data.at_css('Tax')
35
+ @tax_type = data.at_css('Tax').at_css('TaxType').try(:text)
36
+ @tax_rate_percent = data.at_css('Tax').at_css('TaxRatePercent').text.to_i if data.at_css('Tax').at_css('TaxRatePercent')
37
37
  end
38
38
  end
39
39
 
40
40
  def printed_on_product?
41
- @printed_on_product == 2
41
+ @printed_on_product == "02"
42
42
  end
43
43
 
44
44
 
45
45
  def vat
46
- @tax_type == 1 ? @tax_rate_percent : nil
46
+ @tax_type == Elibri::ONIX::Dict::Release_3_0::TaxType::VAT ? @tax_rate_percent : nil
47
47
  end
48
48
 
49
49
  end
@@ -11,15 +11,15 @@ module Elibri
11
11
  #:nodoc:
12
12
  ATTRIBUTES =
13
13
  [
14
- :elibri_dialect, :height, :width, :thickness, :weight, :ean, :isbn13, :number_of_pages, :duration,
14
+ :height, :width, :thickness, :weight, :ean, :isbn13, :number_of_pages, :duration,
15
15
  :file_size, :publisher_name, :publisher_id, :imprint_name, :current_state, :reading_age_from, :reading_age_to,
16
16
  :table_of_contents, :description, :reviews, :excerpts, :series, :title, :subtitle, :collection_title,
17
17
  :collection_part, :full_title, :original_title, :trade_title, :parsed_publishing_date, :record_reference,
18
18
  :deletion_text, :cover_type, :cover_price, :vat, :pkwiu, :additional_info, :product_composition,
19
19
  :publisher, :product_form, :no_contributor, :edition_statement, :number_of_illustrations, :publishing_status,
20
20
  :publishing_date, :premiere, :front_cover, :series_names, :city_of_publication,
21
- :elibri_product_category1_id, :elibri_product_category2_id, :preview_exists, :short_description, :sale_restricted_to_poland,
22
- :technical_protection_onix_code, :unlimited_licence, :hyphenated_isbn, :preorder_embargo_date
21
+ :preview_exists, :short_description, :sale_restricted_to_poland,
22
+ :technical_protection_onix_code, :unlimited_licence, :hyphenated_isbn, :preorder_embargo_date, :additional_trade_information
23
23
  ]
24
24
 
25
25
  #:nodoc:
@@ -27,7 +27,7 @@ module Elibri
27
27
  [
28
28
  :contributors, #IMPORTANT
29
29
  :related_products, :languages, :measures, :supply_details, :measures, :title_details,
30
- :collections, :extents, :subjects, :audience_ranges,
30
+ :collections, :extents, :thema_subjects, :audience_ranges,
31
31
  :text_contents, #IMPORTANT
32
32
  :supporting_resources, #for example: cover
33
33
  :sales_restrictions, :authors,
@@ -115,12 +115,6 @@ module Elibri
115
115
  #krótki opis, jeśli wydawca takowy zamieści, instancja TextContent
116
116
  attr_reader :short_description
117
117
 
118
- #id kategorii elibri (1)
119
- attr_reader :elibri_product_category1_id
120
-
121
- #id kategorii elibri (2)
122
- attr_reader :elibri_product_category2_id
123
-
124
118
  #data końca licencji, jeśli licencja nie jest bezterminowa, w formacie YYYYMMDD
125
119
  attr_reader :licence_limited_to_before_type_cast
126
120
 
@@ -190,10 +184,12 @@ module Elibri
190
184
  #isbn z kreskami
191
185
  attr_reader :hyphenated_isbn
192
186
 
187
+ #dodatkowa informacja handlowa
188
+ attr_reader :additional_trade_information
189
+
193
190
  #:nodoc:
194
191
  attr_reader :text_contents
195
192
  attr_reader :file_size
196
- attr_reader :elibri_dialect
197
193
  attr_reader :reviews
198
194
  attr_reader :excerpts
199
195
  attr_reader :trade_title
@@ -207,7 +203,7 @@ module Elibri
207
203
  attr_reader :title_details
208
204
  attr_reader :collections
209
205
  attr_reader :extents
210
- attr_reader :subjects
206
+ attr_reader :thema_subjects
211
207
  attr_reader :audience_ranges
212
208
  attr_reader :supply_details
213
209
  attr_reader :identifiers
@@ -234,45 +230,70 @@ module Elibri
234
230
  @contributors = []
235
231
  @languages = []
236
232
  @extents = []
237
- @subjects = []
233
+ @thema_subjects = []
238
234
  @audience_ranges = []
239
235
  ##publishing_details
240
236
  @sales_restrictions = []
241
-
237
+ @excerpt_infos = []
238
+ @cover_type = nil
242
239
  #moving to parsing attributes
243
240
 
244
- @elibri_dialect = data.at_xpath('//elibri:Dialect').try(:text)
245
- @record_reference = data.at_xpath('xmlns:RecordReference').try(:text)
246
- @notification_type = data.at_xpath('xmlns:NotificationType').try(:text)
247
- @deletion_text = data.at_xpath('xmlns:DeletionText').try(:text)
248
- @cover_type = data.at_xpath('elibri:CoverType').try(:text)
249
- @cover_price = BigDecimal(data.at_xpath('elibri:CoverPrice').try(:text)) if data.at_xpath('elibri:CoverPrice')
250
- @vat = data.at_xpath('elibri:Vat').try(:text).try(:to_i)
251
- @pkwiu = data.at_xpath('elibri:PKWiU').try(:text)
252
- @hyphenated_isbn = data.at_xpath('elibri:HyphenatedISBN').try(:text)
253
- @pdw_exclusiveness = data.at_xpath('elibri:PDWExclusiveness').try(:text)
254
- @additional_info = data.at_xpath('elibri:AdditionalInfo').try(:text)
255
-
256
- @preview_exists = (data.at_xpath('elibri:preview_exists').try(:text) == "true")
257
- @identifiers = data.xpath('xmlns:ProductIdentifier').map { |ident_data| ProductIdentifier.new(ident_data) }
241
+ @record_reference = data.at_css('RecordReference').try(:text)
242
+ @notification_type = data.at_css('NotificationType').try(:text)
243
+ @deletion_text = data.at_css('DeletionText').try(:text)
244
+
245
+ if data.namespaces.values.any? { |uri| uri =~ /elibri/ }
246
+ @cover_type = data.at_xpath('elibri:CoverType').try(:text)
247
+ @pkwiu = data.at_xpath('elibri:PKWiU').try(:text)
248
+ @hyphenated_isbn = data.at_xpath('elibri:HyphenatedISBN').try(:text)
249
+ @pdw_exclusiveness = data.at_xpath('elibri:PDWExclusiveness').try(:text)
250
+ @additional_info = data.at_xpath('elibri:AdditionalInfo').try(:text)
251
+ end
252
+
253
+ @identifiers = data.children.find_all { |node| node.name == 'ProductIdentifier' }.map { |ident_data| ProductIdentifier.new(ident_data) }
258
254
  begin
259
- @related_products = data.at_xpath('xmlns:RelatedMaterial').xpath('xmlns:RelatedProduct').map { |related_data| RelatedProduct.new(related_data) }
255
+ @related_products = data.at_css('RelatedMaterial').css('RelatedProduct').map { |related_data| RelatedProduct.new(related_data) }
260
256
  rescue
261
257
  @related_products = []
262
258
  end
263
259
  begin
264
- @supply_details = data.at_xpath('xmlns:ProductSupply').xpath('xmlns:SupplyDetail').map { |supply_data| SupplyDetail.new(supply_data) }
260
+ @supply_details = data.at_css('ProductSupply').css('SupplyDetail').map { |supply_data| SupplyDetail.new(supply_data) }
265
261
  rescue
266
262
  @supply_details = []
267
263
  end
268
- descriptive_details_setup(data.at_xpath('xmlns:DescriptiveDetail')) if data.at_xpath('xmlns:DescriptiveDetail')
269
- collateral_details_setup(data.at_xpath('xmlns:CollateralDetail')) if data.at_xpath('xmlns:CollateralDetail')
270
- publishing_details_setup(data.at_xpath('xmlns:PublishingDetail')) if data.at_xpath('xmlns:PublishingDetail')
264
+
265
+ if data.namespaces.values.any? { |uri| uri =~ /elibri/ } && (data.at_xpath('elibri:Vat') || data.at_xpath('elibri:CoverPrice'))
266
+ @cover_price = BigDecimal(data.at_xpath('elibri:CoverPrice').try(:text)) if data.at_xpath('elibri:CoverPrice')
267
+ @vat = data.at_xpath('elibri:Vat').try(:text).try(:to_i)
268
+ else
269
+ price_sd = @supply_details.find { |sd| sd.supplier.role == Elibri::ONIX::Dict::Release_3_0::SupplierRole::PUB_TO_RET }
270
+ if price_sd && price_sd.price && price_sd.price && price_sd.price.type == Elibri::ONIX::Dict::Release_3_0::PriceTypeCode::RRP_WITH_TAX
271
+ @vat = price_sd.price.tax_rate_percent.to_i
272
+ @cover_price = price_sd.price.amount
273
+ @additional_trade_information = price_sd.additional_trade_information
274
+ end
275
+ end
276
+
277
+ descriptive_details_setup(data.at_css('DescriptiveDetail')) if data.at_css('DescriptiveDetail')
278
+ collateral_details_setup(data.at_css('CollateralDetail')) if data.at_css('CollateralDetail')
279
+
280
+ if data.namespaces.values.any? { |uri| uri =~ /elibri/ } && data.at_xpath('elibri:preview_exists')
281
+ @preview_exists = (data.at_xpath('elibri:preview_exists').text == "true")
282
+ else
283
+ @preview_exists = @supporting_resources.find { |sr| sr.content_type_name == "widget" && sr.link =~ /p.elibri.com.pl/ }.present?
284
+ end
285
+
286
+
287
+ publishing_details_setup(data.at_css('PublishingDetail')) if data.at_css('PublishingDetail')
271
288
  licence_information_setup(data)
272
289
  begin
273
290
  @excerpt_infos = data.at_xpath("elibri:excerpts").xpath("elibri:excerpt").map { |node| ExcerptInfo.new(node) }
274
291
  rescue
275
- @excerpt_infos = []
292
+ demo = @supporting_resources.find { |sr| sr.content_type_name == "sample_content" }
293
+ if demo
294
+ @excerpt_infos = demo.data.css("ResourceVersion").map { |node| ExcerptInfo.new(node) }
295
+ end
296
+
276
297
  end
277
298
  begin
278
299
  @file_infos = data.at_xpath("elibri:masters").xpath("elibri:master").map { |node| FileInfo.new(node) }
@@ -282,69 +303,118 @@ module Elibri
282
303
  after_parse
283
304
  end
284
305
 
306
+ def self.determine_cover_type(product_form, product_form_detail)
307
+ if product_form == "BG"
308
+ "skórzana"
309
+ elsif product_form == "BF"
310
+ "gąbka"
311
+ elsif product_form == "BC"
312
+ if product_form_detail == "B504"
313
+ "miękka ze skrzydełkami"
314
+ elsif product_form_detail == "B412"
315
+ "zintegrowana"
316
+ else
317
+ "miękka"
318
+ end
319
+ elsif product_form == "BB"
320
+ if product_form_detail == "B501"
321
+ "twarda z obwolutą"
322
+ elsif product_form_detail == "B415"
323
+ "twarda lakierowana"
324
+ elsif product_form_detail == "B413"
325
+ "plastikowa"
326
+ else
327
+ "twarda"
328
+ end
329
+ end
330
+ end
331
+
285
332
  def licence_information_setup(data)
286
- if data.at_xpath("elibri:SaleNotRestricted")
287
- @unlimited_licence = true
288
- elsif date = data.at_xpath("elibri:SaleRestrictedTo").try(:text)
289
- @unlimited_licence = false
290
- @licence_limited_to_before_type_cast = date
291
- @licence_limited_to = Date.new(date[0...4].to_i, date[4...6].to_i, date[6...8].to_i)
333
+ if data.namespaces.values.any? { |uri| uri =~ /elibri/ } && (data.at_xpath("elibri:SaleNotRestricted") || data.at_xpath("elibri:SaleRestrictedTo"))
334
+ if data.at_xpath("elibri:SaleNotRestricted")
335
+ @unlimited_licence = true
336
+ elsif date = data.at_xpath("elibri:SaleRestrictedTo").try(:text)
337
+ @unlimited_licence = false
338
+ @licence_limited_to_before_type_cast = date
339
+ @licence_limited_to = Date.new(date[0...4].to_i, date[4...6].to_i, date[6...8].to_i)
340
+ end
341
+ else
342
+ daten = data.css('PublishingDate').find { |d| d.at_css("PublishingDateRole").text == Elibri::ONIX::Dict::Release_3_0::PublishingDateRole::OUT_OF_PRINT_DATE }
343
+ if daten
344
+
345
+ date = daten.at_css('Date').text
346
+ @licence_limited_to_before_type_cast = date
347
+ @licence_limited_to = Date.new(date[0...4].to_i, date[4...6].to_i, date[6...8].to_i)
348
+ @unlimited_licence = false
349
+ else
350
+ @unlimited_licence = true
351
+ end
352
+
292
353
  end
293
354
  end
294
355
 
295
356
  def descriptive_details_setup(data)
296
- @product_composition = data.at_xpath('xmlns:ProductComposition').try(:text)
297
- @product_form = data.at_xpath('xmlns:ProductForm').try(:text)
357
+ @product_composition = data.at_css('ProductComposition').try(:text)
358
+ @product_form = data.at_css('ProductForm').text
359
+ if @product_form.starts_with?("B") && !@cover_type
360
+ @cover_type = self.class.determine_cover_type(@product_form, data.at_css('ProductFormDetail').try(:text))
361
+ end
298
362
  if Elibri::ONIX::Dict::Release_3_0::ProductFormCode::find_by_onix_code(@product_form)
299
363
  @product_form_name = Elibri::ONIX::Dict::Release_3_0::ProductFormCode::find_by_onix_code(@product_form).name(:en).downcase
300
364
  end
301
- @measures = data.xpath('xmlns:Measure').map { |measure_data| Measure.new(measure_data) }
302
- @title_details = data.xpath('xmlns:TitleDetail').map { |title_data| TitleDetail.new(title_data) }
303
- @collections = data.xpath('xmlns:Collection').map { |collection_data| Collection.new(collection_data) }
304
- @contributors = data.xpath('xmlns:Contributor').map { |contributor_data| Contributor.new(contributor_data) }
305
- @no_contributor = !!data.at_xpath('xmlns:NoContributor')
306
- @languages = data.xpath('xmlns:Language').map { |language_data| Language.new(language_data) }
307
- @extents = data.xpath('xmlns:Extent').map { |extent_data| Extent.new(extent_data) }
308
- @subjects = data.xpath('xmlns:Subject').map { |subject_data| Subject.new(subject_data) }
309
- @audience_ranges = data.xpath('xmlns:AudienceRange').map { |audience_data| AudienceRange.new(audience_data) }
310
-
311
- if data.xpath("xmlns:ProductFormDetail").size > 0
365
+ if classification = data.css('ProductClassification').find { |cl|
366
+ cl.at_css('ProductClassificationType').text == Elibri::ONIX::Dict::Release_3_0::ProductClassificationType::PKWIU }
367
+ @pkwiu = classification.at_css('ProductClassificationCode').text
368
+ end
369
+ @measures = data.css('Measure').map { |measure_data| Measure.new(measure_data) }
370
+ @title_details = data.children.find_all { |node| node.name == 'TitleDetail' }.map { |title_data| TitleDetail.new(title_data) }
371
+ @collections = data.css('Collection').map { |collection_data| Collection.new(collection_data) }
372
+ @contributors = data.css('Contributor').map { |contributor_data| Contributor.new(contributor_data) }
373
+ @no_contributor = !!data.at_css('NoContributor')
374
+ @languages = data.css('Language').map { |language_data| Language.new(language_data) }
375
+ @extents = data.css('Extent').map { |extent_data| Extent.new(extent_data) }
376
+ @thema_subjects = data.css('Subject').find_all { |sd|
377
+ %w{93 94 95 96 97 98 99}.include?(sd.at_css('SubjectSchemeIdentifier').try(:text)) }.map { |sd| ThemaSubject.new(sd) }
378
+ @audience_ranges = data.css('AudienceRange').map { |audience_data| AudienceRange.new(audience_data) }
379
+
380
+ simplified_product_form = @product_form.starts_with?("B") ? "BA" : @product_form
381
+ if Elibri::ONIX::Dict::Release_3_0::ProductFormCode::find_by_onix_code(simplified_product_form).digital?
312
382
  @digital_formats = []
313
- data.xpath("xmlns:ProductFormDetail").each do |format|
383
+ data.css("ProductFormDetail").each do |format|
314
384
  @digital_formats << Elibri::ONIX::Dict::Release_3_0::ProductFormDetail::find_by_onix_code(format.text).name.upcase.gsub("MOBIPOCKET", "MOBI")
315
385
  end
316
386
  end
317
387
 
318
388
  #zabezpiecznie pliku
319
- if protection = data.at_xpath("xmlns:EpubTechnicalProtection").try(:text)
389
+ if protection = data.at_css("EpubTechnicalProtection").try(:text)
320
390
  @technical_protection = Elibri::ONIX::Dict::Release_3_0::EpubTechnicalProtection::find_by_onix_code(protection).name
321
391
  @technical_protection_onix_code = protection
322
392
  end
323
393
 
324
- @edition_statement = data.at_xpath('xmlns:EditionStatement').try(:text)
325
- @number_of_illustrations = data.at_xpath('xmlns:NumberOfIllustrations').try(:text).try(:to_i)
394
+ @edition_statement = data.at_css('EditionStatement').try(:text)
395
+ @number_of_illustrations = data.at_css('NumberOfIllustrations').try(:text).try(:to_i)
326
396
  end
327
397
 
328
398
  def collateral_details_setup(data)
329
- @text_contents = data.xpath('xmlns:TextContent').map { |text_detail| TextContent.new(text_detail) }
330
- @supporting_resources = data.xpath('xmlns:SupportingResource').map { |supporting_data| SupportingResource.new(supporting_data) }
399
+ @text_contents = data.css('TextContent').map { |text_detail| TextContent.new(text_detail) }
400
+ @supporting_resources = data.css('SupportingResource').map { |supporting_data| SupportingResource.new(supporting_data) }
331
401
  end
332
402
 
333
403
  def publishing_details_setup(data)
334
- @imprint = Imprint.new(data.at_xpath('xmlns:Imprint')) if data.at_xpath('xmlns:Imprint')
335
- @publisher = Publisher.new(data.at_xpath('xmlns:Publisher')) if data.at_xpath('xmlns:Publisher')
336
- @publishing_status = data.at_xpath('xmlns:PublishingStatus').try(:text)
337
- @city_of_publication = data.at_xpath("xmlns:CityOfPublication").try(:text)
338
- publication_dates = data.xpath('xmlns:PublishingDate').map do |node|
404
+ @imprint = Imprint.new(data.at_css('Imprint')) if data.at_css('Imprint')
405
+ @publisher = Publisher.new(data.at_css('Publisher')) if data.at_css('Publisher')
406
+ @publishing_status = data.at_css('PublishingStatus').try(:text)
407
+ @city_of_publication = data.at_css("CityOfPublication").try(:text)
408
+ publication_dates = data.css('PublishingDate').map do |node|
339
409
  PublishingDate.new(node)
340
410
  end
341
411
  @publishing_date = publication_dates.find { |date| date.role == Elibri::ONIX::Dict::Release_3_0::PublishingDateRole::PUBLICATION_DATE }
342
412
  preorder_embargo_date_as_object = publication_dates.find { |date| date.role == Elibri::ONIX::Dict::Release_3_0::PublishingDateRole::PREORDER_EMBARGO_DATE }
343
413
  @preorder_embargo_date = Date.new(*preorder_embargo_date_as_object.parsed) if preorder_embargo_date_as_object
344
414
 
345
- @sales_restrictions = data.xpath('xmlns:SalesRestriction').map { |restriction_data| SalesRestriction.new(restriction_data) }
415
+ @sales_restrictions = data.css('SalesRestriction').map { |restriction_data| SalesRestriction.new(restriction_data) }
346
416
  #ograniczenia terytorialne
347
- if data.at_xpath(".//xmlns:CountriesIncluded").try(:text) == "PL"
417
+ if data.at_css("CountriesIncluded").try(:text) == "PL"
348
418
  @sale_restricted_to_poland = true
349
419
  else
350
420
  @sale_restricted_to_poland = false
@@ -456,6 +526,7 @@ module Elibri
456
526
  @publisher_id = @publisher.eid if publisher
457
527
  @imprint_name = @imprint.name if imprint
458
528
  @isbn13 = @identifiers.find { |identifier| identifier.identifier_type == "isbn13" }.try(:value)
529
+ @hyphenated_isbn ||= @isbn13
459
530
  @reading_age_from = @audience_ranges.find {|ar| (ar.qualifier == "18") && (ar.precision == "03")}.try(:value).try(:to_i)
460
531
  @reading_age_to = @audience_ranges.find {|ar| (ar.qualifier == "18") && (ar.precision == "04")}.try(:value).try(:to_i)
461
532
  @table_of_contents = @text_contents.find { |t| t.type_name == "table_of_contents" }
@@ -475,9 +546,6 @@ module Elibri
475
546
  @original_title = find_title(Elibri::ONIX::Dict::Release_3_0::TitleType::ORIGINAL_TITLE).try(:full_title)
476
547
  @trade_title = find_title(Elibri::ONIX::Dict::Release_3_0::TitleType::DISTRIBUTORS_TITLE).try(:full_title)
477
548
 
478
- @elibri_product_category1_id = subjects[0].code if subjects[0]
479
- @elibri_product_category2_id = subjects[1].code if subjects[1]
480
-
481
549
  compute_state!
482
550
  end
483
551