elibri_onix 0.1.5 → 0.1.6

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 (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
data/Gemfile CHANGED
@@ -3,12 +3,13 @@ source "http://rubygems.org"
3
3
  gem 'activesupport', '>= 2.3.5'
4
4
  gem 'roxml', '= 3.1.3'
5
5
  gem 'i18n'
6
+ gem 'elibri_onix_dict', '0.0.3'
6
7
 
7
8
  group :development do
8
9
  gem "pry"
9
10
  gem "mocha"
10
11
  gem "minitest", ">= 0"
11
- gem "bundler", "~> 1.0.0"
12
+ gem "bundler", ">= 1.0.0"
12
13
  gem "jeweler", "~> 1.6.2"
13
14
  gem "rcov", ">= 0"
14
15
  end
data/Gemfile.lock CHANGED
@@ -3,6 +3,7 @@ GEM
3
3
  specs:
4
4
  activesupport (2.3.5)
5
5
  coderay (0.9.8)
6
+ elibri_onix_dict (0.0.3)
6
7
  git (1.2.5)
7
8
  i18n (0.6.0)
8
9
  jeweler (1.6.4)
@@ -36,7 +37,8 @@ PLATFORMS
36
37
 
37
38
  DEPENDENCIES
38
39
  activesupport (>= 2.3.5)
39
- bundler (~> 1.0.0)
40
+ bundler (>= 1.0.0)
41
+ elibri_onix_dict (= 0.0.3)
40
42
  i18n
41
43
  jeweler (~> 1.6.2)
42
44
  minitest
data/elibri_onix.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{elibri_onix}
8
- s.version = "0.1.5"
8
+ s.version = "0.1.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Marcin Urbanski"]
12
- s.date = %q{2011-10-18}
12
+ s.date = %q{2011-11-14}
13
13
  s.description = %q{EDItEUR ONIX format subset implementation used in Elibri publication system}
14
14
  s.email = %q{marcin@urbanski.vdl.pl}
15
15
  s.extra_rdoc_files = [
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  "VERSION",
27
27
  "elibri_onix.gemspec",
28
28
  "lib/elibri_onix.rb",
29
+ "lib/elibri_onix/inspector.rb",
29
30
  "lib/elibri_onix/onix_3_0/audience_range.rb",
30
31
  "lib/elibri_onix/onix_3_0/collection.rb",
31
32
  "lib/elibri_onix/onix_3_0/contributor.rb",
@@ -54,10 +55,49 @@ Gem::Specification.new do |s|
54
55
  "lib/elibri_onix/onix_3_0/title_element.rb",
55
56
  "lib/elibri_onix/releases.rb",
56
57
  "lib/elibri_onix/version.rb",
58
+ "test/elibri_audience_range_test.rb",
59
+ "test/elibri_contributors_test.rb",
60
+ "test/elibri_edition_test.rb",
61
+ "test/elibri_extensions_test.rb",
62
+ "test/elibri_extent_test.rb",
63
+ "test/elibri_languages_test.rb",
64
+ "test/elibri_measurement_test.rb",
57
65
  "test/elibri_onix_release_3_0_onix_message_test.rb",
58
66
  "test/elibri_onix_test.rb",
67
+ "test/elibri_product_form_test.rb",
68
+ "test/elibri_publisher_info_test.rb",
69
+ "test/elibri_publishing_status_test.rb",
70
+ "test/elibri_record_identifiers_test.rb",
71
+ "test/elibri_sale_restrictions_test.rb",
72
+ "test/elibri_series_memberships_test.rb",
73
+ "test/elibri_supporting_resources_test.rb",
74
+ "test/elibri_texts_test.rb",
75
+ "test/elibri_titles_test.rb",
59
76
  "test/fixtures/all_possible_tags.xml",
60
77
  "test/fixtures/old_dialect.xml",
78
+ "test/fixtures/onix_announced_product_example.xml",
79
+ "test/fixtures/onix_audience_range_example.xml",
80
+ "test/fixtures/onix_audiobook_extent_example.xml",
81
+ "test/fixtures/onix_collective_work_example.xml",
82
+ "test/fixtures/onix_contributors_example.xml",
83
+ "test/fixtures/onix_ebook_extent_example.xml",
84
+ "test/fixtures/onix_edition_example.xml",
85
+ "test/fixtures/onix_elibri_extensions_example.xml",
86
+ "test/fixtures/onix_languages_example.xml",
87
+ "test/fixtures/onix_measurement_example.xml",
88
+ "test/fixtures/onix_no_contributors_example.xml",
89
+ "test/fixtures/onix_out_of_print_product_example.xml",
90
+ "test/fixtures/onix_preorder_product_example.xml",
91
+ "test/fixtures/onix_product_form_example.xml",
92
+ "test/fixtures/onix_published_product_example.xml",
93
+ "test/fixtures/onix_publisher_info_example.xml",
94
+ "test/fixtures/onix_record_identifiers_example.xml",
95
+ "test/fixtures/onix_sale_restrictions_example.xml",
96
+ "test/fixtures/onix_series_memberships_example.xml",
97
+ "test/fixtures/onix_supporting_resources_example.xml",
98
+ "test/fixtures/onix_texts_example.xml",
99
+ "test/fixtures/onix_title_with_collection_example.xml",
100
+ "test/fixtures/onix_titles_example.xml",
61
101
  "test/helper.rb"
62
102
  ]
63
103
  s.homepage = %q{http://github.com/elibri/elibri_onix}
@@ -73,20 +113,22 @@ Gem::Specification.new do |s|
73
113
  s.add_runtime_dependency(%q<activesupport>, [">= 2.3.5"])
74
114
  s.add_runtime_dependency(%q<roxml>, ["= 3.1.3"])
75
115
  s.add_runtime_dependency(%q<i18n>, [">= 0"])
116
+ s.add_runtime_dependency(%q<elibri_onix_dict>, ["= 0.0.3"])
76
117
  s.add_development_dependency(%q<pry>, [">= 0"])
77
118
  s.add_development_dependency(%q<mocha>, [">= 0"])
78
119
  s.add_development_dependency(%q<minitest>, [">= 0"])
79
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
120
+ s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
80
121
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.2"])
81
122
  s.add_development_dependency(%q<rcov>, [">= 0"])
82
123
  else
83
124
  s.add_dependency(%q<activesupport>, [">= 2.3.5"])
84
125
  s.add_dependency(%q<roxml>, ["= 3.1.3"])
85
126
  s.add_dependency(%q<i18n>, [">= 0"])
127
+ s.add_dependency(%q<elibri_onix_dict>, ["= 0.0.3"])
86
128
  s.add_dependency(%q<pry>, [">= 0"])
87
129
  s.add_dependency(%q<mocha>, [">= 0"])
88
130
  s.add_dependency(%q<minitest>, [">= 0"])
89
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
131
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
90
132
  s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
91
133
  s.add_dependency(%q<rcov>, [">= 0"])
92
134
  end
@@ -94,10 +136,11 @@ Gem::Specification.new do |s|
94
136
  s.add_dependency(%q<activesupport>, [">= 2.3.5"])
95
137
  s.add_dependency(%q<roxml>, ["= 3.1.3"])
96
138
  s.add_dependency(%q<i18n>, [">= 0"])
139
+ s.add_dependency(%q<elibri_onix_dict>, ["= 0.0.3"])
97
140
  s.add_dependency(%q<pry>, [">= 0"])
98
141
  s.add_dependency(%q<mocha>, [">= 0"])
99
142
  s.add_dependency(%q<minitest>, [">= 0"])
100
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
143
+ s.add_dependency(%q<bundler>, [">= 1.0.0"])
101
144
  s.add_dependency(%q<jeweler>, ["~> 1.6.2"])
102
145
  s.add_dependency(%q<rcov>, [">= 0"])
103
146
  end
data/lib/elibri_onix.rb CHANGED
@@ -6,7 +6,9 @@ require 'active_support'
6
6
  require 'active_support/core_ext'
7
7
  require 'roxml'
8
8
  require 'elibri_onix/version'
9
+ require 'elibri_onix/inspector'
9
10
  require 'elibri_onix/releases'
11
+ require 'elibri_onix_dict'
10
12
 
11
13
  $KCODE = "UTF-8"
12
14
 
@@ -17,3 +19,4 @@ module Elibri
17
19
 
18
20
  end
19
21
  end
22
+
@@ -0,0 +1,25 @@
1
+ module Inspector
2
+
3
+ def attribute_for_inspect(attr_name)
4
+ value = self.send(attr_name)
5
+
6
+ if value.is_a?(String) && value.length > 50
7
+ "#{value[0..50]}...".inspect
8
+ elsif value.is_a?(Date) || value.is_a?(Time)
9
+ %("#{value.to_s(:db)}")
10
+ #elsif value.is_a?(Array)
11
+ # "\n [" + value.map(&:inspect).join(",\n ") + "]"
12
+ else
13
+ value.inspect
14
+ end
15
+ end
16
+
17
+ def inspect
18
+ include_fields = self.respond_to?(:inspect_include_fields) ? self.inspect_include_fields : []
19
+ attributes_as_nice_string = (include_fields + self.roxml_references.map { |rr| rr.opts.attr_name }).collect { |name|
20
+ "#{name}: #{attribute_for_inspect(name)}"
21
+ }.compact.join(", ")
22
+ "#<#{self.class} #{attributes_as_nice_string}>"
23
+ end
24
+ end
25
+
@@ -5,12 +5,13 @@ module Elibri
5
5
 
6
6
  class AudienceRange
7
7
  include ROXML
8
+ include Inspector
8
9
 
9
10
  xml_name 'AudienceRange'
10
11
 
11
- xml_accessor :qualifier, :from => 'AudienceRangeQualifier', :as => Fixnum
12
- xml_accessor :precision, :from => 'AudienceRangePrecision', :as => Fixnum
13
- xml_accessor :value, :from => 'AudienceRangeValue'
12
+ xml_accessor :qualifier, :from => 'AudienceRangeQualifier'
13
+ xml_accessor :precision, :from => 'AudienceRangePrecision'
14
+ xml_accessor :value, :from => 'AudienceRangeValue', :as => Fixnum
14
15
 
15
16
 
16
17
  end
@@ -5,10 +5,11 @@ module Elibri
5
5
 
6
6
  class Collection
7
7
  include ROXML
8
+ include Inspector
8
9
 
9
10
  xml_name 'Collection'
10
11
 
11
- xml_accessor :type, :from => 'CollectionType', :as => Fixnum
12
+ xml_accessor :type, :from => 'CollectionType'
12
13
  xml_accessor :elements, :as => [TitleElement]
13
14
  xml_accessor :title_detail, :as => TitleDetail
14
15
 
@@ -16,6 +17,14 @@ module Elibri
16
17
  title_detail.try(:full_title)
17
18
  end
18
19
 
20
+ def type_name
21
+ Elibri::ONIX::Dict::Release_3_0::CollectionType.find_by_onix_code(type).const_name.downcase
22
+ end
23
+
24
+ def inspect_include_fields
25
+ [:type_name]
26
+ end
27
+
19
28
  end
20
29
 
21
30
  end
@@ -5,6 +5,7 @@ module Elibri
5
5
 
6
6
  class Contributor
7
7
  include ROXML
8
+ include Inspector
8
9
 
9
10
  xml_name 'Contributor'
10
11
 
@@ -20,6 +21,14 @@ module Elibri
20
21
  xml_accessor :biographical_note, :from => 'BiographicalNote'
21
22
 
22
23
  xml_accessor :unnamed_persons, :from => 'UnnamedPersons'
24
+
25
+ def role_name
26
+ Elibri::ONIX::Dict::Release_3_0::ContributorRole.find_by_onix_code(self.role).const_name.downcase
27
+ end
28
+
29
+ def inspect_include_fields
30
+ [:role_name]
31
+ end
23
32
  end
24
33
 
25
34
  end
@@ -6,11 +6,25 @@ module Elibri
6
6
 
7
7
  class Extent
8
8
  include ROXML
9
+ include Inspector
9
10
 
10
11
  xml_name 'Extent'
11
- xml_accessor :type, :from => 'ExtentType', :as => Fixnum
12
- xml_accessor :value, :from => 'ExtentValue', :as => BigDecimal
13
- xml_accessor :unit, :from => 'ExtentUnit', :as => Fixnum
12
+ xml_accessor :type, :from => 'ExtentType'
13
+ xml_accessor :value, :from => 'ExtentValue', :as => Fixnum
14
+ xml_accessor :unit, :from => 'ExtentUnit'
15
+
16
+ def type_name
17
+ Elibri::ONIX::Dict::Release_3_0::ExtentType.find_by_onix_code(type).const_name.downcase
18
+ end
19
+
20
+ def unit_name
21
+ Elibri::ONIX::Dict::Release_3_0::ExtentUnit.find_by_onix_code(unit).const_name.downcase
22
+ end
23
+
24
+ def inspect_include_fields
25
+ [:type_name, :unit_name]
26
+ end
27
+
14
28
  end
15
29
 
16
30
  end
@@ -6,6 +6,7 @@ module Elibri
6
6
 
7
7
  class Header
8
8
  include ROXML
9
+ include Inspector
9
10
 
10
11
  xml_name 'Header'
11
12
  xml_accessor :sent_date_time, :as => Date, :from => 'SentDateTime'
@@ -6,6 +6,7 @@ module Elibri
6
6
 
7
7
  class Imprint
8
8
  include ROXML
9
+ include Inspector
9
10
 
10
11
  xml_name 'Imprint'
11
12
 
@@ -6,12 +6,24 @@ module Elibri
6
6
 
7
7
  class Language
8
8
  include ROXML
9
-
9
+ include Inspector
10
10
  xml_name 'Language'
11
11
 
12
- xml_accessor :role, :from => 'LanguageRole', :as => Fixnum
12
+ xml_accessor :role, :from => 'LanguageRole'
13
13
  xml_accessor :code, :from => 'LanguageCode'
14
14
 
15
+ def role_name
16
+ Elibri::ONIX::Dict::Release_3_0::LanguageRole.find_by_onix_code(self.role).const_name.downcase
17
+ end
18
+
19
+ def language
20
+ Elibri::ONIX::Dict::Release_3_0::LanguageCode.find_by_onix_code(self.code).name(:pl).downcase
21
+ end
22
+
23
+ def inspect_include_fields
24
+ [:role_name, :language]
25
+ end
26
+
15
27
  end
16
28
 
17
29
  end
@@ -6,11 +6,21 @@ module Elibri
6
6
 
7
7
  class Measure
8
8
  include ROXML
9
+ include Inspector
9
10
 
10
11
  xml_name 'Measure'
11
- xml_accessor :type, :from => 'MeasureType', :as => Fixnum
12
- xml_accessor :measurement, :from => 'Measurement', :as => BigDecimal
12
+ xml_accessor :type, :from => 'MeasureType'
13
+ xml_accessor :measurement, :from => 'Measurement', :as => Fixnum
13
14
  xml_accessor :unit, :from => 'MeasureUnitCode'
15
+
16
+ def type_name
17
+ Elibri::ONIX::Dict::Release_3_0::MeasureType.find_by_onix_code(type).const_name.downcase
18
+ end
19
+
20
+ def inspect_include_fields
21
+ [:type_name]
22
+ end
23
+
14
24
  end
15
25
 
16
26
  end
@@ -5,7 +5,8 @@ module Elibri
5
5
 
6
6
  class ONIXMessage
7
7
  include ROXML
8
-
8
+ #include Inspector
9
+
9
10
  xml_name 'ONIXMessage'
10
11
  xml_accessor :release, :from => "@release"
11
12
  xml_accessor :elibri_dialect, :from => "elibri:Dialect"
@@ -8,6 +8,7 @@ module Elibri
8
8
 
9
9
  class Price
10
10
  include ROXML
11
+ include Inspector
11
12
 
12
13
  xml_name 'Price'
13
14
 
@@ -5,11 +5,16 @@ module Elibri
5
5
 
6
6
  class Product
7
7
  include ROXML
8
- attr_accessor :elibri_dialect
8
+
9
+ attr_accessor :elibri_dialect, :height, :width, :thickness, :weight, :ean, :isbn13, :number_of_pages, :duration,
10
+ :file_size, :publisher_name, :imprint_name, :current_state, :reading_age_from, :reading_age_to,
11
+ :table_of_contents, :description, :reviews, :excerpts, :series, :title, :subtitle, :collection_title,
12
+ :collection_part, :full_title, :original_title, :trade_title, :parsed_publishing_date
13
+
9
14
 
10
15
  xml_name 'Product'
11
16
  xml_accessor :record_reference, :from => 'RecordReference'
12
- xml_accessor :notification_type, :from => 'NotificationType', :as => Fixnum
17
+ xml_accessor :notification_type, :from => 'NotificationType'
13
18
  xml_accessor :deletion_text, :from => 'DeletionText'
14
19
 
15
20
  # Load attributes specific for dialect 3.0.1
@@ -37,12 +42,13 @@ module Elibri
37
42
  xml_accessor :related_products, :as => [RelatedProduct], :in => 'RelatedMaterial'
38
43
  xml_accessor :supply_details, :as => [SupplyDetail], :in => 'ProductSupply'
39
44
 
40
- xml_accessor :product_composition, :in => 'DescriptiveDetail', :from => 'ProductComposition', :as => Fixnum
45
+ xml_accessor :product_composition, :in => 'DescriptiveDetail', :from => 'ProductComposition'
41
46
  xml_accessor :product_form, :in => 'DescriptiveDetail', :from => 'ProductForm'
42
47
  xml_accessor :measures, :in => 'DescriptiveDetail', :as => [Measure]
43
48
  xml_accessor :title_details, :in => 'DescriptiveDetail', :as => [TitleDetail]
44
49
  xml_accessor :collections, :in => 'DescriptiveDetail', :as => [Collection]
45
50
  xml_accessor :contributors, :in => 'DescriptiveDetail', :as => [Contributor]
51
+ xml_accessor :no_contributor, :in => 'DescriptiveDetail', :from => 'NoContributor'
46
52
  xml_accessor :languages, :in => 'DescriptiveDetail', :as => [Language]
47
53
  xml_accessor :extents, :in => 'DescriptiveDetail', :as => [Extent]
48
54
  xml_accessor :subjects, :in => 'DescriptiveDetail', :as => [Subject]
@@ -55,99 +61,123 @@ module Elibri
55
61
 
56
62
  xml_accessor :imprint, :in => 'PublishingDetail', :as => Imprint
57
63
  xml_accessor :publisher, :in => 'PublishingDetail', :as => Publisher
58
- xml_accessor :publishing_status, :in => 'PublishingDetail', :from => 'PublishingStatus', :as => Fixnum
64
+ xml_accessor :publishing_status, :in => 'PublishingDetail', :from => 'PublishingStatus'
59
65
  xml_accessor :publishing_date, :in => 'PublishingDetail', :as => PublishingDate
60
66
  xml_accessor :sales_restrictions, :in => 'PublishingDetail', :as => [SalesRestriction]
61
67
 
62
-
63
- def isbn13
64
- identifiers.find {|identifier| identifier.type == 15}.try(:value)
68
+ def sales_restrictions?
69
+ sales_restrictions.size > 0
65
70
  end
66
71
 
67
-
68
- def ean13
69
- identifiers.find {|identifier| identifier.type == 3}.try(:value)
72
+ def no_contributor?
73
+ no_contributor == ""
70
74
  end
71
75
 
72
-
73
- %w{height width thickness weight}.each do |method_name|
74
- define_method(method_name) do
75
- send(method_name + '_measure').try(:measurement)
76
- end
77
-
78
- define_method(method_name + '_unit') do
79
- send(method_name + '_measure').try(:unit)
80
- end
81
- end
82
-
83
-
84
- def proprietary_identifiers
85
- Hash.new.tap do |hash|
86
- identifiers.each do |identifier|
87
- hash[identifier.type_name] = identifier.value if identifier.type == 1
88
- end
89
- end
76
+ def unnamed_persons?
77
+ contributors.size == 1 && contributors[0].unnamed_persons.present?
90
78
  end
91
79
 
92
-
93
- def full_title
94
- title_details.find {|title_detail| title_detail.type == 1}.try(:full_title)
80
+ def front_cover
81
+ supporting_resources.find { |resource| resource.content_type_name == "front_cover" }.try(:link)
95
82
  end
96
83
 
97
-
98
- def original_title
99
- title_details.find {|title_detail| title_detail.type == 3}.try(:full_title)
84
+ def series_names
85
+ series.map { |series| series[0] }
100
86
  end
101
-
102
-
103
- def trade_title
104
- title_details.find {|title_detail| title_detail.type == 10}.try(:full_title)
87
+
88
+ def proprietary_identifiers
89
+ identifiers.find_all { |i| i.identifier_type == "proprietary" }.inject({}) { |res, ident| res[ident.type_name] = ident.value; res }
105
90
  end
106
91
 
107
-
108
- def number_of_pages
109
- extents.find {|extent| extent.type == 0}.try(:value)
110
- end
111
-
112
-
113
- def reading_age_from
114
- age_from = audience_ranges.find {|audience_range| (audience_range.qualifier == 18) && (audience_range.precision == 3)}.try(:value)
115
- age_from.present? ? age_from.to_i : nil
92
+ #I don't want to see roxml_references in output - it's faar to big output
93
+ def pretty_print_instance_variables
94
+ (instance_variables - ["@roxml_references", "@measures", "@identifiers", "@notification_type", "@publishing_status",
95
+ "@elibri_dialect", "@product_composition", "@extents", "@publisher", "@imprint",
96
+ "@audience_ranges", "@text_contents", "@collections", "@title_details", "@publishing_date"]).find_all { |varname|
97
+ instance_variable_get(varname).present?
98
+ }.sort
116
99
  end
117
100
 
118
101
 
119
- def reading_age_to
120
- age_to = audience_ranges.find {|audience_range| (audience_range.qualifier == 18) && (audience_range.precision == 4)}.try(:value)
121
- age_to.present? ? age_to.to_i : nil
102
+ def pretty_print(pp)
103
+ pp.object_address_group(self) {
104
+ pp.seplist(self.pretty_print_instance_variables, lambda { pp.text ',' }) {|v|
105
+ pp.breakable
106
+ v = v.to_s if Symbol === v
107
+ pp.text v
108
+ pp.text '='
109
+ pp.group(1) {
110
+ pp.breakable ''
111
+ pp.pp(self.instance_eval(v))
112
+ }
113
+ }
114
+ }
122
115
  end
123
116
 
124
-
125
- def imprint_name
126
- imprint.try(:name)
127
- end
128
-
129
-
130
117
  private
131
118
 
132
- def height_measure
133
- measures.find {|measure| measure.type == 1}
134
- end
135
-
119
+ def find_title(code)
120
+ title_details.find {|title_detail| title_detail.type == code}
121
+ end
136
122
 
137
- def width_measure
138
- measures.find {|measure| measure.type == 2}
123
+ def parse_publishing_date!
124
+ if sales_restrictions?
125
+ date = sales_restrictions[0].end_date
126
+ @parsed_publishing_date = [date.year, date.month, date.day]
127
+ elsif publishing_date
128
+ @parsed_publishing_date = publishing_date.parsed
129
+ else
130
+ @parsed_publishing_date = []
139
131
  end
132
+ end
140
133
 
141
134
 
142
- def thickness_measure
143
- measures.find {|measure| measure.type == 3}
135
+ def after_parse
136
+ %w{height width thickness weight}.each do |mn|
137
+ instance_variable_set("@#{mn}", measures.find { |m| m.type_name == mn }.try(:measurement))
144
138
  end
145
139
 
140
+ @ean = identifiers.find { |identifier| identifier.identifier_type == "ean" }.try(:value)
141
+ @isbn13 = identifiers.find { |identifier| identifier.identifier_type == "isbn13" }.try(:value)
142
+ @number_of_pages = extents.find {|extent| extent.type_name == "page_count" }.try(:value)
143
+ @duration = extents.find {|extent| extent.type_name == "duration" }.try(:value)
144
+ @file_size = extents.find {|extent| extent.type_name == "file_size" }.try(:value)
145
+ @publisher_name = publisher.name if publisher
146
+ @imprint_name = imprint.name if imprint
147
+
148
+ @reading_age_from = audience_ranges.find {|ar| (ar.qualifier == "18") && (ar.precision == "03")}.try(:value)
149
+ @reading_age_to = audience_ranges.find {|ar| (ar.qualifier == "18") && (ar.precision == "04")}.try(:value)
150
+ @table_of_contents = text_contents.find { |t| t.type_name == "table_of_contents" }.try(:text)
151
+ @description = text_contents.find { |t| t.type_name == "main_description" }.try(:text)
152
+ @reviews = text_contents.find_all { |t| t.type_name == "review" }.map { |t| [t.text, t.author] }
153
+ @excerpts = text_contents.find_all { |t| t.type_name == "excerpt" }.map { |t| t.text }
154
+ @series = collections.map { |c| [c.title_detail.elements[0].title, c.title_detail.elements[0].part_number] }
155
+ @title = find_title(Elibri::ONIX::Dict::Release_3_0::TitleType::DISTINCTIVE_TITLE).product_level.try(:title)
156
+ @subtitle = find_title(Elibri::ONIX::Dict::Release_3_0::TitleType::DISTINCTIVE_TITLE).product_level.try(:subtitle)
157
+ @collection_title = find_title(Elibri::ONIX::Dict::Release_3_0::TitleType::DISTINCTIVE_TITLE).collection_level.try(:title)
158
+ @collection_part = find_title(Elibri::ONIX::Dict::Release_3_0::TitleType::DISTINCTIVE_TITLE).collection_level.try(:part_number)
159
+ @full_title = find_title(Elibri::ONIX::Dict::Release_3_0::TitleType::DISTINCTIVE_TITLE).try(:full_title)
160
+ @original_title = find_title(Elibri::ONIX::Dict::Release_3_0::TitleType::ORIGINAL_TITLE).try(:full_title)
161
+ @trade_title = find_title(Elibri::ONIX::Dict::Release_3_0::TitleType::DISTRIBUTORS_TITLE).try(:full_title)
162
+ compute_state!
163
+ parse_publishing_date!
164
+ end
146
165
 
147
- def weight_measure
148
- measures.find {|measure| measure.type == 8}
166
+ def compute_state!
167
+ if notification_type == "01"
168
+ @current_state = :announced
169
+ elsif notification_type == "02"
170
+ @current_state = :preorder
171
+ else
172
+ if publishing_status == "04"
173
+ @current_state = :published
174
+ elsif publishing_status == "07"
175
+ @current_state = :out_of_print
176
+ else
177
+ raise "cannot determine the state of the product"
178
+ end
149
179
  end
150
-
180
+ end
151
181
  end
152
182
 
153
183
  end