elibri_onix 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. data/Gemfile +2 -1
  2. data/Gemfile.lock +3 -1
  3. data/elibri_onix.gemspec +48 -5
  4. data/lib/elibri_onix.rb +3 -0
  5. data/lib/elibri_onix/inspector.rb +25 -0
  6. data/lib/elibri_onix/onix_3_0/audience_range.rb +4 -3
  7. data/lib/elibri_onix/onix_3_0/collection.rb +10 -1
  8. data/lib/elibri_onix/onix_3_0/contributor.rb +9 -0
  9. data/lib/elibri_onix/onix_3_0/extent.rb +17 -3
  10. data/lib/elibri_onix/onix_3_0/header.rb +1 -0
  11. data/lib/elibri_onix/onix_3_0/imprint.rb +1 -0
  12. data/lib/elibri_onix/onix_3_0/language.rb +14 -2
  13. data/lib/elibri_onix/onix_3_0/measure.rb +12 -2
  14. data/lib/elibri_onix/onix_3_0/onix_message.rb +2 -1
  15. data/lib/elibri_onix/onix_3_0/price.rb +1 -0
  16. data/lib/elibri_onix/onix_3_0/product.rb +97 -67
  17. data/lib/elibri_onix/onix_3_0/product_identifier.rb +10 -1
  18. data/lib/elibri_onix/onix_3_0/publisher.rb +3 -1
  19. data/lib/elibri_onix/onix_3_0/publishing_date.rb +11 -2
  20. data/lib/elibri_onix/onix_3_0/related_product.rb +1 -0
  21. data/lib/elibri_onix/onix_3_0/sales_restriction.rb +1 -0
  22. data/lib/elibri_onix/onix_3_0/sender.rb +2 -0
  23. data/lib/elibri_onix/onix_3_0/stock_quantity_coded.rb +1 -0
  24. data/lib/elibri_onix/onix_3_0/subject.rb +1 -0
  25. data/lib/elibri_onix/onix_3_0/supplier.rb +1 -0
  26. data/lib/elibri_onix/onix_3_0/supplier_identifier.rb +1 -0
  27. data/lib/elibri_onix/onix_3_0/supply_detail.rb +1 -0
  28. data/lib/elibri_onix/onix_3_0/supporting_resource.rb +24 -5
  29. data/lib/elibri_onix/onix_3_0/text_content.rb +15 -2
  30. data/lib/elibri_onix/onix_3_0/title_detail.rb +21 -9
  31. data/lib/elibri_onix/onix_3_0/title_element.rb +15 -4
  32. data/lib/elibri_onix/version.rb +1 -1
  33. data/test/elibri_audience_range_test.rb +14 -0
  34. data/test/elibri_contributors_test.rb +37 -0
  35. data/test/elibri_edition_test.rb +10 -0
  36. data/test/elibri_extensions_test.rb +14 -0
  37. data/test/elibri_extent_test.rb +15 -0
  38. data/test/elibri_languages_test.rb +14 -0
  39. data/test/elibri_measurement_test.rb +16 -0
  40. data/test/elibri_onix_release_3_0_onix_message_test.rb +19 -28
  41. data/test/elibri_product_form_test.rb +12 -0
  42. data/test/elibri_publisher_info_test.rb +12 -0
  43. data/test/elibri_publishing_status_test.rb +41 -0
  44. data/test/elibri_record_identifiers_test.rb +16 -0
  45. data/test/elibri_sale_restrictions_test.rb +11 -0
  46. data/test/elibri_series_memberships_test.rb +16 -0
  47. data/test/elibri_supporting_resources_test.rb +12 -0
  48. data/test/elibri_texts_test.rb +16 -0
  49. data/test/elibri_titles_test.rb +24 -0
  50. data/test/fixtures/old_dialect.xml +10 -0
  51. data/test/fixtures/onix_announced_product_example.xml +54 -0
  52. data/test/fixtures/onix_audience_range_example.xml +44 -0
  53. data/test/fixtures/onix_audiobook_extent_example.xml +39 -0
  54. data/test/fixtures/onix_collective_work_example.xml +38 -0
  55. data/test/fixtures/onix_contributors_example.xml +53 -0
  56. data/test/fixtures/onix_ebook_extent_example.xml +45 -0
  57. data/test/fixtures/onix_edition_example.xml +35 -0
  58. data/test/fixtures/onix_elibri_extensions_example.xml +38 -0
  59. data/test/fixtures/onix_languages_example.xml +42 -0
  60. data/test/fixtures/onix_measurement_example.xml +55 -0
  61. data/test/fixtures/onix_no_contributors_example.xml +35 -0
  62. data/test/fixtures/onix_out_of_print_product_example.xml +34 -0
  63. data/test/fixtures/onix_preorder_product_example.xml +39 -0
  64. data/test/fixtures/onix_product_form_example.xml +35 -0
  65. data/test/fixtures/onix_published_product_example.xml +39 -0
  66. data/test/fixtures/onix_publisher_info_example.xml +41 -0
  67. data/test/fixtures/onix_record_identifiers_example.xml +74 -0
  68. data/test/fixtures/onix_sale_restrictions_example.xml +46 -0
  69. data/test/fixtures/onix_series_memberships_example.xml +56 -0
  70. data/test/fixtures/onix_supporting_resources_example.xml +54 -0
  71. data/test/fixtures/onix_texts_example.xml +65 -0
  72. data/test/fixtures/onix_title_with_collection_example.xml +53 -0
  73. data/test/fixtures/onix_titles_example.xml +49 -0
  74. data/test/helper.rb +6 -0
  75. metadata +73 -17
@@ -5,11 +5,20 @@ module Elibri
5
5
 
6
6
  class ProductIdentifier
7
7
  include ROXML
8
+ include Inspector
8
9
 
9
10
  xml_name 'ProductIdentifier'
10
- xml_accessor :type, :as => Fixnum, :from => 'ProductIDType'
11
+ xml_accessor :type, :from => 'ProductIDType'
11
12
  xml_accessor :type_name, :from => 'IDTypeName'
12
13
  xml_accessor :value, :from => 'IDValue'
14
+
15
+ def identifier_type
16
+ Elibri::ONIX::Dict::Release_3_0::ProductIDType.find_by_onix_code(type).const_name.downcase
17
+ end
18
+
19
+ def inspect_include_fields
20
+ [:identifier_type]
21
+ end
13
22
  end
14
23
 
15
24
  end
@@ -7,10 +7,12 @@ module Elibri
7
7
 
8
8
  class Publisher
9
9
  include ROXML
10
+ include Inspector
10
11
 
11
12
  xml_name 'Publisher'
12
13
 
13
- xml_accessor :role, :from => 'PublishingRole', :as => Fixnum
14
+ #występuje w tej chwili tylko 01 - główny wydawca
15
+ xml_accessor :role, :from => 'PublishingRole'
14
16
  xml_accessor :name, :from => 'PublisherName'
15
17
 
16
18
  end
@@ -7,13 +7,22 @@ module Elibri
7
7
 
8
8
  class PublishingDate
9
9
  include ROXML
10
+ include Inspector
10
11
 
11
12
  xml_name 'PublishingDate'
12
13
 
13
- xml_accessor :role, :from => 'PublishingDateRole', :as => Fixnum
14
- xml_accessor :format, :from => 'DateFormat', :as => Fixnum
14
+ xml_accessor :role, :from => 'PublishingDateRole'
15
+ xml_accessor :format, :from => 'DateFormat'
15
16
  xml_accessor :date, :from => 'Date'
16
17
 
18
+ def parsed
19
+ case format
20
+ when '00' then [date[0...4].to_i, date[4...6].to_i, date[6...8].to_i]
21
+ when '01' then [date[0...4].to_i, date[4...6].to_i]
22
+ when '05' then [date[0...4].to_i]
23
+ end
24
+ end
25
+
17
26
  end
18
27
 
19
28
  end
@@ -8,6 +8,7 @@ module Elibri
8
8
 
9
9
  class RelatedProduct
10
10
  include ROXML
11
+ include Inspector
11
12
 
12
13
  xml_name 'RelatedProduct'
13
14
 
@@ -7,6 +7,7 @@ module Elibri
7
7
 
8
8
  class SalesRestriction
9
9
  include ROXML
10
+ include Inspector
10
11
 
11
12
  xml_name 'SalesRestriction'
12
13
 
@@ -5,6 +5,8 @@ module Elibri
5
5
 
6
6
  class Sender
7
7
  include ROXML
8
+ include Inspector
9
+
8
10
  xml_name 'Sender'
9
11
 
10
12
  xml_accessor :sender_name, :from => 'SenderName'
@@ -8,6 +8,7 @@ module Elibri
8
8
 
9
9
  class StockQuantityCoded
10
10
  include ROXML
11
+ include Inspector
11
12
 
12
13
  xml_name 'StockQuantityCoded'
13
14
 
@@ -6,6 +6,7 @@ module Elibri
6
6
 
7
7
  class Subject
8
8
  include ROXML
9
+ include Inspector
9
10
 
10
11
  xml_name 'Subject'
11
12
  xml_accessor :scheme_identifier, :from => 'SubjectSchemeIdentifier', :as => Fixnum
@@ -7,6 +7,7 @@ module Elibri
7
7
 
8
8
  class Supplier
9
9
  include ROXML
10
+ include Inspector
10
11
 
11
12
  xml_name 'Supplier'
12
13
 
@@ -8,6 +8,7 @@ module Elibri
8
8
 
9
9
  class SupplierIdentifier
10
10
  include ROXML
11
+ include Inspector
11
12
 
12
13
  xml_name 'SupplierIdentifier'
13
14
 
@@ -7,6 +7,7 @@ module Elibri
7
7
 
8
8
  class SupplyDetail
9
9
  include ROXML
10
+ include Inspector
10
11
 
11
12
  xml_name 'SupplyDetail'
12
13
 
@@ -6,18 +6,37 @@ module Elibri
6
6
 
7
7
  class SupportingResource
8
8
  include ROXML
9
+ include Inspector
9
10
 
10
11
  xml_name 'SupportingResource'
11
12
 
12
- xml_accessor :content_type, :from => 'ResourceContentType', :as => Fixnum
13
- xml_accessor :audience, :from => 'ContentAudience', :as => Fixnum
14
- xml_accessor :mode, :from => 'ResourceMode', :as => Fixnum
13
+ xml_accessor :content_type, :from => 'ResourceContentType'
14
+ #xml_accessor :audience, :from => 'ContentAudience' - always unrestricted
15
+ xml_accessor :mode, :from => 'ResourceMode'
15
16
 
16
- xml_accessor :form, :in => 'ResourceVersion', :from => 'ResourceForm', :as => Fixnum
17
+ xml_accessor :form, :in => 'ResourceVersion', :from => 'ResourceForm'
17
18
  xml_accessor :link, :in => 'ResourceVersion', :from => 'ResourceLink'
18
19
 
20
+ def content_type_name
21
+ Elibri::ONIX::Dict::Release_3_0::ResourceContentType.find_by_onix_code(content_type).const_name.downcase
22
+ end
23
+
24
+ #def audience_name
25
+ # Elibri::ONIX::Dict::Release_3_0::ContentAudience.find_by_onix_code(audience).const_name.downcase
26
+ #end
27
+
28
+ def mode_name
29
+ Elibri::ONIX::Dict::Release_3_0::ResourceMode.find_by_onix_code(mode).const_name.downcase
30
+ end
31
+
32
+ def form_name
33
+ Elibri::ONIX::Dict::Release_3_0::ResourceForm.find_by_onix_code(form).const_name.downcase
34
+ end
35
+
36
+ def inspect_include_fields
37
+ [:content_type_name, :mode_name, :form_name]
38
+ end
19
39
  end
20
-
21
40
  end
22
41
  end
23
42
  end
@@ -5,15 +5,28 @@ module Elibri
5
5
 
6
6
  class TextContent
7
7
  include ROXML
8
+ include Inspector
8
9
 
9
10
  xml_name 'TextContent'
10
11
 
11
- xml_accessor :type, :from => 'TextType', :as => Fixnum
12
- xml_accessor :audience, :from => 'ContentAudience', :as => Fixnum
12
+ xml_accessor :type, :from => 'TextType'
13
+ #xml_accessor :audience, :from => 'ContentAudience' - always unrestricted
13
14
  xml_accessor :author, :from => 'TextAuthor'
14
15
 
15
16
  xml_accessor :text, :from => 'Text', :cdata => true
16
17
 
18
+ def type_name
19
+ Elibri::ONIX::Dict::Release_3_0::OtherTextType.find_by_onix_code(type).const_name.downcase
20
+ end
21
+
22
+ def inspect_include_fields
23
+ [:type_name]
24
+ end
25
+
26
+ private
27
+ def after_parse
28
+ @text = @text.strip if @text
29
+ end
17
30
  end
18
31
 
19
32
  end
@@ -6,12 +6,20 @@ module Elibri
6
6
 
7
7
  class TitleDetail
8
8
  include ROXML
9
+ include Inspector
9
10
 
10
11
  xml_name 'TitleDetail'
11
12
 
12
- xml_accessor :type, :from => 'TitleType', :as => Fixnum
13
+ xml_accessor :type, :from => 'TitleType'
13
14
  xml_accessor :elements, :as => [TitleElement]
14
15
 
16
+ def type_name
17
+ Elibri::ONIX::Dict::Release_3_0::TitleType.find_by_onix_code(self.type).const_name.downcase
18
+ end
19
+
20
+ def inspect_include_fields
21
+ [:type_name]
22
+ end
15
23
 
16
24
  def full_title
17
25
  String.new.tap do |_full_title|
@@ -23,17 +31,21 @@ module Elibri
23
31
  end
24
32
  end
25
33
 
34
+ def product_level_title
35
+ product_level.try(:full_title)
36
+ end
26
37
 
27
- private
28
-
29
- def product_level_title
30
- elements.find {|element| element.level == 1}.try(:full_title)
31
- end
38
+ def product_level
39
+ elements.find {|element| element.level == "01"}
40
+ end
32
41
 
42
+ def collection_level_title
43
+ collection_level.try(:full_title)
44
+ end
33
45
 
34
- def collection_level_title
35
- elements.find {|element| element.level == 2}.try(:full_title)
36
- end
46
+ def collection_level
47
+ elements.find {|element| element.level == "02"}
48
+ end
37
49
 
38
50
  end
39
51
 
@@ -5,19 +5,30 @@ module Elibri
5
5
 
6
6
  class TitleElement
7
7
  include ROXML
8
+ include Inspector
8
9
 
9
10
  xml_name 'TitleElement'
10
11
 
11
- xml_accessor :level, :from => 'TitleElementLevel', :as => Fixnum
12
+ xml_accessor :level, :from => 'TitleElementLevel'
12
13
  xml_accessor :part_number, :from => 'PartNumber'
13
14
  xml_accessor :title, :from => 'TitleText'
14
15
  xml_accessor :subtitle, :from => 'Subtitle'
15
16
 
16
17
 
17
18
  def full_title
18
- String.new(self.title.to_s).tap do |_full_title|
19
- _full_title << ". " + self.subtitle if self.subtitle.present?
20
- _full_title << " (#{self.part_number})" if self.part_number.present?
19
+ String.new(self.title.to_s.strip).tap do |_full_title|
20
+ if _full_title =~ /[\.!\?]$/ #czy kończy się ?!.
21
+ _full_title << " " + self.subtitle if self.subtitle.present?
22
+ else
23
+ _full_title << ". " + self.subtitle if self.subtitle.present?
24
+ end
25
+ if self.part_number.present?
26
+ if self.part_number.to_i.to_s == self.part_number
27
+ _full_title << " (##{self.part_number})"
28
+ else
29
+ _full_title << " (#{self.part_number})"
30
+ end
31
+ end
21
32
  end
22
33
  end
23
34
 
@@ -4,7 +4,7 @@ module Elibri
4
4
  module Version
5
5
  MAJOR = 0
6
6
  MINOR = 1
7
- PATCH = 5
7
+ PATCH = 6
8
8
 
9
9
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
10
10
  end
@@ -0,0 +1,14 @@
1
+ require 'helper'
2
+
3
+ describe Elibri::ONIX::Release_3_0::ONIXMessage do
4
+
5
+ it "should be able to parse measurement attributes supported in Elibri" do
6
+ product = load_fixture("onix_audience_range_example.xml")
7
+
8
+ assert_equal 7, product.reading_age_from
9
+ assert_equal 10, product.reading_age_to
10
+
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,37 @@
1
+ require 'helper'
2
+
3
+ describe Elibri::ONIX::Release_3_0::ONIXMessage do
4
+
5
+ it "should be able to parse measurement attributes supported in Elibri" do
6
+ product = load_fixture("onix_contributors_example.xml")
7
+
8
+ assert !product.no_contributor?
9
+ assert !product.unnamed_persons?
10
+
11
+ cont1 = product.contributors[0]
12
+ cont2 = product.contributors[1]
13
+
14
+ assert_equal "author", cont1.role_name
15
+ assert_equal "Św. Tomasz z Akwinu", cont1.person_name
16
+ assert cont1.biographical_note.present?
17
+
18
+ assert_equal "translator", cont2.role_name
19
+ assert_equal "prof. ks. Henryk von Hausswolff OP", cont2.person_name
20
+
21
+ #<Elibri::ONIX::Release_3_0::Contributor role_name: "author", number: 1, role: "A01", person_name: "Św. Tomasz z Akwinu", from_language: nil, titles_before_names: nil, names_before_key: "Św.", prefix_to_key: nil, key_names: "Tomasz z Akwinu", names_after_key: nil, biographical_note: "Tomasz z Akwinu, Akwinata, łac. Thoma de Aquino (u...", unnamed_persons: nil>,
22
+ # #<Elibri::ONIX::Release_3_0::Contributor role_name: "translator", number: 2, role: "B06", person_name: "prof. ks. Henryk von Hausswolff OP", from_language: "lat", titles_before_names: "prof. ks.", names_before_key: "Henryk", prefix_to_key: "von", key_names: "Hausswolff", names_after_key: "OP", biographical_note: nil, unnamed_persons: nil>]
23
+ #
24
+
25
+ product = load_fixture("onix_no_contributors_example.xml")
26
+ assert product.no_contributor?
27
+ assert !product.unnamed_persons?
28
+
29
+
30
+ product = load_fixture("onix_collective_work_example.xml")
31
+ assert !product.no_contributor?
32
+ assert product.unnamed_persons?
33
+
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,10 @@
1
+ require 'helper'
2
+
3
+ describe Elibri::ONIX::Release_3_0::ONIXMessage do
4
+
5
+ it "should be able to parse measurement attributes supported in Elibri" do
6
+ product = load_fixture("onix_edition_example.xml")
7
+ assert_equal "wyd. 3, poprawione", product.edition_statement
8
+ end
9
+
10
+ end
@@ -0,0 +1,14 @@
1
+ require 'helper'
2
+
3
+ describe Elibri::ONIX::Release_3_0::ONIXMessage do
4
+
5
+ it "should be able to parse measurement attributes supported in Elibri" do
6
+ product = load_fixture("onix_elibri_extensions_example.xml")
7
+
8
+ assert_equal "miękka", product.cover_type
9
+ assert_equal 12.99, product.cover_price
10
+ assert_equal 5, product.vat
11
+ assert_equal "58.11.1", product.pkwiu
12
+ end
13
+
14
+ end
@@ -0,0 +1,15 @@
1
+ require 'helper'
2
+
3
+ describe Elibri::ONIX::Release_3_0::ONIXMessage do
4
+
5
+ it "should be able to parse measurement attributes supported in Elibri" do
6
+ product = load_fixture("onix_ebook_extent_example.xml")
7
+ assert_equal 150, product.number_of_pages
8
+ assert_equal 12, product.number_of_illustrations
9
+ assert_equal 1, product.file_size
10
+
11
+ product = load_fixture("onix_audiobook_extent_example.xml")
12
+ assert_equal 340, product.duration
13
+ end
14
+
15
+ end
@@ -0,0 +1,14 @@
1
+ require 'helper'
2
+
3
+ describe Elibri::ONIX::Release_3_0::ONIXMessage do
4
+
5
+ it "should be able to parse measurement attributes supported in Elibri" do
6
+ product = load_fixture("onix_languages_example.xml")
7
+ assert_equal "polski", product.languages[0].language
8
+ assert_equal "language_of_text", product.languages[0].role_name
9
+
10
+ assert_equal "angielski", product.languages[1].language
11
+ assert_equal "language_of_abstracts", product.languages[1].role_name
12
+ end
13
+
14
+ end
@@ -0,0 +1,16 @@
1
+ require 'helper'
2
+
3
+ describe Elibri::ONIX::Release_3_0::ONIXMessage do
4
+
5
+ it "should be able to parse measurement attributes supported in Elibri" do
6
+ product = load_fixture("onix_measurement_example.xml")
7
+
8
+ assert_equal 4, product.measures.size
9
+
10
+ assert_equal 195, product.height
11
+ assert_equal 125, product.width
12
+ assert_equal 20, product.thickness
13
+ assert_equal 90, product.weight
14
+ end
15
+
16
+ end