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.
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -5
- data/elibri_onix.gemspec +2 -1
- data/lib/elibri_onix.rb +3 -2
- data/lib/elibri_onix/external_id.rb +15 -2
- data/lib/elibri_onix/external_timestamp.rb +5 -1
- data/lib/elibri_onix/nokogiri_patch.rb +17 -0
- data/lib/elibri_onix/onix_3_0/audience_range.rb +14 -8
- data/lib/elibri_onix/onix_3_0/collection.rb +10 -9
- data/lib/elibri_onix/onix_3_0/contributor.rb +21 -18
- data/lib/elibri_onix/onix_3_0/extent.rb +18 -11
- data/lib/elibri_onix/onix_3_0/header.rb +7 -6
- data/lib/elibri_onix/onix_3_0/imprint.rb +6 -5
- data/lib/elibri_onix/onix_3_0/language.rb +16 -9
- data/lib/elibri_onix/onix_3_0/measure.rb +17 -9
- data/lib/elibri_onix/onix_3_0/onix_message.rb +14 -30
- data/lib/elibri_onix/onix_3_0/price.rb +19 -17
- data/lib/elibri_onix/onix_3_0/product.rb +118 -77
- data/lib/elibri_onix/onix_3_0/product_identifier.rb +9 -7
- data/lib/elibri_onix/onix_3_0/publisher.rb +19 -9
- data/lib/elibri_onix/onix_3_0/publishing_date.rb +10 -9
- data/lib/elibri_onix/onix_3_0/related_product.rb +10 -15
- data/lib/elibri_onix/onix_3_0/sales_restriction.rb +11 -8
- data/lib/elibri_onix/onix_3_0/sender.rb +9 -8
- data/lib/elibri_onix/onix_3_0/stock_quantity_coded.rb +8 -11
- data/lib/elibri_onix/onix_3_0/subject.rb +19 -13
- data/lib/elibri_onix/onix_3_0/supplier.rb +15 -12
- data/lib/elibri_onix/onix_3_0/supplier_identifier.rb +9 -8
- data/lib/elibri_onix/onix_3_0/supply_detail.rb +16 -15
- data/lib/elibri_onix/onix_3_0/supporting_resource.rb +15 -15
- data/lib/elibri_onix/onix_3_0/text_content.rb +18 -15
- data/lib/elibri_onix/onix_3_0/title_detail.rb +17 -11
- data/lib/elibri_onix/onix_3_0/title_element.rb +10 -9
- data/lib/elibri_onix/version.rb +1 -1
- data/test/elibri_contributors_test.rb +1 -1
- data/test/elibri_onix_release_3_0_onix_message_test.rb +2 -2
- data/test/elibri_supporting_resources_test.rb +1 -1
- data/test/elibri_texts_test.rb +4 -4
- data/test/helper.rb +2 -1
- metadata +252 -295
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
elibri_onix (0.
|
4
|
+
elibri_onix (0.2.0)
|
5
5
|
activesupport (>= 2.3.5)
|
6
6
|
elibri_onix_dict (>= 0.0.5)
|
7
7
|
i18n
|
8
|
-
|
8
|
+
nokogiri
|
9
9
|
|
10
10
|
GEM
|
11
11
|
remote: https://rubygems.org/
|
@@ -23,6 +23,7 @@ GEM
|
|
23
23
|
metaclass (~> 0.0.1)
|
24
24
|
multi_json (1.3.5)
|
25
25
|
nokogiri (1.5.2)
|
26
|
+
nokogiri (1.5.2-java)
|
26
27
|
pry (0.9.9.6)
|
27
28
|
coderay (~> 1.0.5)
|
28
29
|
method_source (~> 0.7.1)
|
@@ -33,9 +34,6 @@ GEM
|
|
33
34
|
slop (>= 2.4.4, < 3)
|
34
35
|
spoon (~> 0.0)
|
35
36
|
rake (0.9.2.2)
|
36
|
-
roxml (3.1.3)
|
37
|
-
activesupport (>= 2.1.0)
|
38
|
-
nokogiri (>= 1.3.3)
|
39
37
|
slop (2.4.4)
|
40
38
|
spoon (0.0.1)
|
41
39
|
|
data/elibri_onix.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |gem|
|
|
24
24
|
]
|
25
25
|
|
26
26
|
gem.add_runtime_dependency 'activesupport', '>= 2.3.5'
|
27
|
-
gem.add_runtime_dependency '
|
27
|
+
gem.add_runtime_dependency 'nokogiri'
|
28
28
|
gem.add_runtime_dependency 'i18n'
|
29
29
|
gem.add_runtime_dependency 'elibri_onix_dict', '>= 0.0.5'
|
30
30
|
|
@@ -33,6 +33,7 @@ Gem::Specification.new do |gem|
|
|
33
33
|
gem.add_development_dependency "minitest", ">= 0"
|
34
34
|
gem.add_development_dependency "bundler", ">= 1.0.0"
|
35
35
|
gem.add_development_dependency "rake"
|
36
|
+
# gem.add_development_dependency "ruby-debug"
|
36
37
|
#gem.add_development_dependency "rcov", ">= 0"
|
37
38
|
|
38
39
|
end
|
data/lib/elibri_onix.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
|
2
2
|
require 'bigdecimal'
|
3
|
+
require 'date'
|
3
4
|
# Old ActiveSupport needs 'thread' to see Mutex:
|
4
5
|
require 'thread'
|
5
6
|
require 'active_support'
|
6
7
|
require 'active_support/core_ext'
|
7
|
-
require '
|
8
|
+
require 'nokogiri'
|
8
9
|
require 'elibri_onix/version'
|
9
10
|
require 'elibri_onix/inspector'
|
10
11
|
require 'elibri_onix/external_id'
|
11
12
|
require 'elibri_onix/external_timestamp'
|
12
13
|
require 'elibri_onix/releases'
|
13
|
-
|
14
|
+
require 'elibri_onix/nokogiri_patch'
|
14
15
|
require 'elibri_onix_dict'
|
15
16
|
|
16
17
|
$KCODE = "UTF-8"
|
@@ -1,11 +1,24 @@
|
|
1
1
|
module ExternalId
|
2
2
|
|
3
|
+
# def self.included(base)
|
4
|
+
# base.xml_accessor :id_before_type_cast, :from => "@sourcename"
|
5
|
+
# end
|
6
|
+
|
3
7
|
def self.included(base)
|
4
|
-
base.
|
8
|
+
base.send(:attr_accessor, :id_before_type_cast)
|
9
|
+
end
|
10
|
+
|
11
|
+
def set_eid(data)
|
12
|
+
@id_before_type_cast = data.attr('sourcename')
|
5
13
|
end
|
6
14
|
|
15
|
+
def eid
|
16
|
+
@id_before_type_cast.split(":")[1].to_i
|
17
|
+
end
|
18
|
+
|
7
19
|
def id
|
8
|
-
|
20
|
+
Kernel.warn "[DEPRECATION] `id` is deprecated. Please use `eid` instead."
|
21
|
+
eid
|
9
22
|
end
|
10
23
|
|
11
24
|
end
|
@@ -1,7 +1,11 @@
|
|
1
1
|
module ExternalTimestamp
|
2
2
|
|
3
3
|
def self.included(base)
|
4
|
-
base.
|
4
|
+
base.send(:attr_accessor, :datestamp_before_type_cast) #, :from => "@datestamp"
|
5
|
+
end
|
6
|
+
|
7
|
+
def set_datestamp(data)
|
8
|
+
@datestamp_before_type_cast = data.attr('datestamp')
|
5
9
|
end
|
6
10
|
|
7
11
|
def datestamp
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Nokogiri
|
2
|
+
module XML
|
3
|
+
class Node
|
4
|
+
alias_method :orig_xpath, :xpath
|
5
|
+
|
6
|
+
def xpath *paths
|
7
|
+
unless Nokogiri.uses_libxml?
|
8
|
+
paths.each do |path|
|
9
|
+
path.gsub!(/xmlns:/, ' :') if path.is_a?(String)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
orig_xpath *paths
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -4,23 +4,29 @@ module Elibri
|
|
4
4
|
module Release_3_0
|
5
5
|
|
6
6
|
class AudienceRange
|
7
|
-
include ROXML
|
8
|
-
include Inspector
|
9
|
-
|
10
|
-
xml_name 'AudienceRange'
|
11
7
|
|
12
8
|
ATTRIBUTES = [
|
13
9
|
:qualifier, :precision, :value
|
14
10
|
]
|
15
11
|
|
16
12
|
RELATIONS = []
|
13
|
+
|
14
|
+
attr_accessor :qualifier, :precision, :value, :to_xml
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
def initialize(data)
|
17
|
+
@old_xml = data.to_s
|
18
|
+
@qualifier = data.at_xpath('xmlns:AudienceRangeQualifier').try(:text)
|
19
|
+
@precision = data.at_xpath('xmlns:AudienceRangePrecision').try(:text)
|
20
|
+
@value = data.at_xpath('xmlns:AudienceRangeValue').try(:text).try(:to_i)
|
21
|
+
end
|
21
22
|
|
23
|
+
def eid
|
24
|
+
"#{@qualifier}-#{@precision}-#{@value}"
|
25
|
+
end
|
26
|
+
|
22
27
|
def id
|
23
|
-
"
|
28
|
+
Kernel.warn "[DEPRECATION] `id` is deprecated. Please use `eid` instead."
|
29
|
+
eid
|
24
30
|
end
|
25
31
|
|
26
32
|
end
|
@@ -4,10 +4,6 @@ module Elibri
|
|
4
4
|
module Release_3_0
|
5
5
|
|
6
6
|
class Collection
|
7
|
-
include ROXML
|
8
|
-
include Inspector
|
9
|
-
|
10
|
-
xml_name 'Collection'
|
11
7
|
|
12
8
|
ATTRIBUTES = [
|
13
9
|
:type, :title_detail, :full_title, :type_name
|
@@ -16,17 +12,22 @@ module Elibri
|
|
16
12
|
RELATIONS = [
|
17
13
|
:elements, :inspect_include_fields
|
18
14
|
]
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
|
16
|
+
attr_accessor :type, :elements, :title_detail, :to_xml
|
17
|
+
|
18
|
+
def initialize(data)
|
19
|
+
@to_xml = data.to_s
|
20
|
+
@type = data.at_xpath('xmlns:CollectionType').try(:text)
|
21
|
+
@elements = data.xpath('xmlns:TitleElement').map { |element_data| TitleElement.new(element_data) }
|
22
|
+
@title_detail = TitleDetail.new(data.at_xpath('xmlns:TitleDetail')) if data.at_xpath('xmlns:TitleDetail')
|
23
|
+
end
|
23
24
|
|
24
25
|
def full_title
|
25
26
|
title_detail.try(:full_title)
|
26
27
|
end
|
27
28
|
|
28
29
|
def type_name
|
29
|
-
Elibri::ONIX::Dict::Release_3_0::CollectionType.find_by_onix_code(type).const_name.downcase
|
30
|
+
Elibri::ONIX::Dict::Release_3_0::CollectionType.find_by_onix_code(@type).const_name.downcase
|
30
31
|
end
|
31
32
|
|
32
33
|
def inspect_include_fields
|
@@ -4,8 +4,6 @@ module Elibri
|
|
4
4
|
module Release_3_0
|
5
5
|
|
6
6
|
class Contributor
|
7
|
-
include ROXML
|
8
|
-
include Inspector
|
9
7
|
include ExternalId
|
10
8
|
include ExternalTimestamp
|
11
9
|
|
@@ -19,24 +17,29 @@ module Elibri
|
|
19
17
|
[
|
20
18
|
:inspect_include_fields
|
21
19
|
]
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
20
|
+
|
21
|
+
attr_accessor :number, :role, :person_name, :from_language, :titles_before_names, :names_before_key, :prefix_to_key,
|
22
|
+
:key_names, :names_after_key, :biographical_note, :unnamed_persons, :to_xml
|
23
|
+
|
24
|
+
def initialize(data)
|
25
|
+
@to_xml = data.to_s
|
26
|
+
@number = data.at_xpath('xmlns:SequenceNumber').try(:text).try(:to_i)
|
27
|
+
@role = data.at_xpath('xmlns:ContributorRole').try(:text)
|
28
|
+
@person_name = data.at_xpath('xmlns:PersonName').try(:text)
|
29
|
+
@from_language = data.at_xpath('xmlns:FromLanguage').try(:text)
|
30
|
+
@titles_before_names = data.at_xpath('xmlns:TitlesBeforeNames').try(:text)
|
31
|
+
@names_before_key = data.at_xpath('xmlns:NamesBeforeKey').try(:text)
|
32
|
+
@prefix_to_key = data.at_xpath('xmlns:PrefixToKey').try(:text)
|
33
|
+
@key_names = data.at_xpath('xmlns:KeyNames').try(:text)
|
34
|
+
@names_after_key = data.at_xpath('xmlns:NamesAfterKey').try(:text)
|
35
|
+
@biographical_note = data.at_xpath('xmlns:BiographicalNote').try(:text)
|
36
|
+
@unnamed_persons = data.at_xpath('xmlns:UnnamedPersons').try(:text)
|
37
|
+
set_eid(data)
|
38
|
+
set_datestamp(data)
|
39
|
+
end
|
37
40
|
|
38
41
|
def role_name
|
39
|
-
Elibri::ONIX::Dict::Release_3_0::ContributorRole.find_by_onix_code(
|
42
|
+
Elibri::ONIX::Dict::Release_3_0::ContributorRole.find_by_onix_code(@role).const_name.downcase
|
40
43
|
end
|
41
44
|
|
42
45
|
def inspect_include_fields
|
@@ -5,14 +5,7 @@ module Elibri
|
|
5
5
|
module Release_3_0
|
6
6
|
|
7
7
|
class Extent
|
8
|
-
|
9
|
-
include Inspector
|
10
|
-
|
11
|
-
xml_name 'Extent'
|
12
|
-
xml_accessor :type, :from => 'ExtentType'
|
13
|
-
xml_accessor :value, :from => 'ExtentValue', :as => Fixnum
|
14
|
-
xml_accessor :unit, :from => 'ExtentUnit'
|
15
|
-
|
8
|
+
|
16
9
|
ATTRIBUTES = [
|
17
10
|
:type, :value, :unit, :type_name, :unit_name
|
18
11
|
]
|
@@ -20,17 +13,31 @@ module Elibri
|
|
20
13
|
RELATIONS = [
|
21
14
|
:inspect_include_fields
|
22
15
|
]
|
16
|
+
|
17
|
+
attr_accessor :type, :value, :unit, :to_xml
|
18
|
+
|
19
|
+
def initialize(data)
|
20
|
+
@to_xml = data.to_s
|
21
|
+
@type = data.xpath('xmlns:ExtentType').try(:text)
|
22
|
+
@value = data.xpath('xmlns:ExtentValue').try(:text).try(:to_i)
|
23
|
+
@unit = data.xpath('xmlns:ExtentUnit').try(:text)
|
24
|
+
end
|
23
25
|
|
26
|
+
def eid
|
27
|
+
@type.to_i
|
28
|
+
end
|
29
|
+
|
24
30
|
def id
|
25
|
-
|
31
|
+
Kernel.warn "[DEPRECATION] `id` is deprecated. Please use `eid` instead."
|
32
|
+
eid
|
26
33
|
end
|
27
34
|
|
28
35
|
def type_name
|
29
|
-
Elibri::ONIX::Dict::Release_3_0::ExtentType.find_by_onix_code(type).const_name.downcase
|
36
|
+
Elibri::ONIX::Dict::Release_3_0::ExtentType.find_by_onix_code(@type).const_name.downcase
|
30
37
|
end
|
31
38
|
|
32
39
|
def unit_name
|
33
|
-
Elibri::ONIX::Dict::Release_3_0::ExtentUnit.find_by_onix_code(unit).const_name.downcase
|
40
|
+
Elibri::ONIX::Dict::Release_3_0::ExtentUnit.find_by_onix_code(@unit).const_name.downcase
|
34
41
|
end
|
35
42
|
|
36
43
|
def inspect_include_fields
|
@@ -5,13 +5,8 @@ module Elibri
|
|
5
5
|
module Release_3_0
|
6
6
|
|
7
7
|
class Header
|
8
|
-
include ROXML
|
9
|
-
include Inspector
|
10
8
|
|
11
|
-
|
12
|
-
xml_accessor :sent_date_time, :as => Date, :from => 'SentDateTime'
|
13
|
-
|
14
|
-
xml_accessor :sender, :as => Sender
|
9
|
+
attr_accessor :sent_date_time, :sender, :to_xml
|
15
10
|
|
16
11
|
ATTRIBUTES = [
|
17
12
|
:sent_date_time, :sender
|
@@ -19,6 +14,12 @@ module Elibri
|
|
19
14
|
|
20
15
|
RELATIONS = []
|
21
16
|
|
17
|
+
def initialize(data)
|
18
|
+
@to_xml = data.to_s
|
19
|
+
@sent_date_time = Date.parse(data.xpath('xmlns:SentDateTime').try(:text)) if data.xpath('xmlns:SentDateTime')
|
20
|
+
@sender = Sender.new(data.at_xpath('xmlns:Sender')) if data.at_xpath('xmlns:Sender')
|
21
|
+
end
|
22
|
+
|
22
23
|
end
|
23
24
|
|
24
25
|
end
|
@@ -5,10 +5,6 @@ module Elibri
|
|
5
5
|
module Release_3_0
|
6
6
|
|
7
7
|
class Imprint
|
8
|
-
include ROXML
|
9
|
-
include Inspector
|
10
|
-
|
11
|
-
xml_name 'Imprint'
|
12
8
|
|
13
9
|
ATTRIBUTES = [
|
14
10
|
:name
|
@@ -16,7 +12,12 @@ module Elibri
|
|
16
12
|
|
17
13
|
RELATIONS = []
|
18
14
|
|
19
|
-
|
15
|
+
attr_accessor :name, :to_xml
|
16
|
+
|
17
|
+
def initialize(data)
|
18
|
+
@to_xml = data.to_s
|
19
|
+
@name = data.at_xpath('xmlns:ImprintName').try(:text)
|
20
|
+
end
|
20
21
|
|
21
22
|
end
|
22
23
|
|
@@ -5,12 +5,6 @@ module Elibri
|
|
5
5
|
module Release_3_0
|
6
6
|
|
7
7
|
class Language
|
8
|
-
include ROXML
|
9
|
-
include Inspector
|
10
|
-
xml_name 'Language'
|
11
|
-
|
12
|
-
xml_accessor :role, :from => 'LanguageRole'
|
13
|
-
xml_accessor :code, :from => 'LanguageCode'
|
14
8
|
|
15
9
|
ATTRIBUTES = [
|
16
10
|
:role, :code, :role_name, :language
|
@@ -19,21 +13,34 @@ module Elibri
|
|
19
13
|
RELATIONS = [
|
20
14
|
:inspect_include_fields
|
21
15
|
]
|
16
|
+
|
17
|
+
attr_accessor :role, :code, :to_xml
|
18
|
+
|
19
|
+
def initialize(data)
|
20
|
+
@to_xml = data.to_s
|
21
|
+
@role = data.at_xpath('xmlns:LanguageRole').try(:text)
|
22
|
+
@code = data.at_xpath('xmlns:LanguageCode').try(:text)
|
23
|
+
end
|
22
24
|
|
23
25
|
def role_name
|
24
|
-
Elibri::ONIX::Dict::Release_3_0::LanguageRole.find_by_onix_code(
|
26
|
+
Elibri::ONIX::Dict::Release_3_0::LanguageRole.find_by_onix_code(@role).const_name.downcase
|
25
27
|
end
|
26
28
|
|
27
29
|
def language
|
28
|
-
Elibri::ONIX::Dict::Release_3_0::LanguageCode.find_by_onix_code(
|
30
|
+
Elibri::ONIX::Dict::Release_3_0::LanguageCode.find_by_onix_code(@code).name(:pl).downcase
|
29
31
|
end
|
30
32
|
|
31
33
|
def inspect_include_fields
|
32
34
|
[:role_name, :language]
|
33
35
|
end
|
34
36
|
|
37
|
+
def eid
|
38
|
+
"#{@role}-#{@code}"
|
39
|
+
end
|
40
|
+
|
35
41
|
def id
|
36
|
-
"
|
42
|
+
Kernel.warn "[DEPRECATION] `id` is deprecated. Please use `eid` instead."
|
43
|
+
eid
|
37
44
|
end
|
38
45
|
|
39
46
|
end
|
@@ -5,13 +5,6 @@ module Elibri
|
|
5
5
|
module Release_3_0
|
6
6
|
|
7
7
|
class Measure
|
8
|
-
include ROXML
|
9
|
-
include Inspector
|
10
|
-
|
11
|
-
xml_name 'Measure'
|
12
|
-
xml_accessor :type, :from => 'MeasureType'
|
13
|
-
xml_accessor :measurement, :from => 'Measurement', :as => Fixnum
|
14
|
-
xml_accessor :unit, :from => 'MeasureUnitCode'
|
15
8
|
|
16
9
|
ATTRIBUTES = [
|
17
10
|
:type, :measurement, :unit, :type_name
|
@@ -20,17 +13,32 @@ module Elibri
|
|
20
13
|
RELATIONS = [
|
21
14
|
:inspect_include_fields
|
22
15
|
]
|
16
|
+
|
17
|
+
attr_accessor :type, :measurement, :unit, :type_name, :to_xml
|
18
|
+
|
19
|
+
def initialize(data)
|
20
|
+
@to_xml = data.to_s
|
21
|
+
@type = data.at_xpath('xmlns:MeasureType').try(:text)
|
22
|
+
@measurement = data.at_xpath('xmlns:Measurement').try(:text).try(:to_i)
|
23
|
+
@unit = data.at_xpath('xmlns:MeasureUnitCode').try(:text)
|
24
|
+
|
25
|
+
end
|
23
26
|
|
24
27
|
def type_name
|
25
|
-
Elibri::ONIX::Dict::Release_3_0::MeasureType.find_by_onix_code(type).const_name.downcase
|
28
|
+
Elibri::ONIX::Dict::Release_3_0::MeasureType.find_by_onix_code(@type).const_name.downcase
|
26
29
|
end
|
27
30
|
|
28
31
|
def inspect_include_fields
|
29
32
|
[:type_name]
|
30
33
|
end
|
31
34
|
|
35
|
+
def eid
|
36
|
+
@type.to_i
|
37
|
+
end
|
38
|
+
|
32
39
|
def id
|
33
|
-
|
40
|
+
Kernel.warn "[DEPRECATION] `id` is deprecated. Please use `eid` instead."
|
41
|
+
eid
|
34
42
|
end
|
35
43
|
|
36
44
|
end
|