elibri_xml_versions 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +0 -1
- data/Gemfile +1 -1
- data/README.md +21 -1
- data/lib/elibri_xml_versions/version.rb +1 -1
- data/lib/elibri_xml_versions.rb +20 -15
- data/spec/elibri_xml_versions_spec.rb +2 -1
- data/spec/spec_helper.rb +2 -2
- metadata +4 -4
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -18,9 +18,29 @@ It will return hash:
|
|
18
18
|
}
|
19
19
|
```
|
20
20
|
|
21
|
+
In case of comparising Elibri products:
|
22
|
+
|
23
|
+
* added and deleted may contain only: 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
|
24
|
+
|
25
|
+
* changes may contain all previous mentioned elements as a keys for embedded hashes (meaning changes in embedded elements) and also may contain additional attributes: 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, product_composition, product_form, imprint, publisher, product_form, no_contributor, edition_statement, number_of_illustrations, publishing_status, publishing_date, premiere, front_cover, series_names, elibri_product_category1_id, elibri_product_category2_id, preview_exists, short_description
|
26
|
+
|
27
|
+
* If attribute appear as a symbol in changes array, that it means it has been changed between compared products.
|
28
|
+
|
29
|
+
* If hash appears in changes, that means that key of that hash is a embedded relation that has been changed, and in values you will find array containing hashes. In that most inner hashes, key means Elibri internal id of element changed and value is symbol for attribute changed.
|
30
|
+
|
31
|
+
* In added and deleted arrays you will find objects that needed to be removed or added to your local copy of Elibri object.
|
32
|
+
|
21
33
|
under changes key, will be array of symbol and/or hashes.
|
22
34
|
If there is change deeper in structure it will be represented like this:
|
23
35
|
`:changes => [{:contributors => [{2167055520 => :key_names}]`
|
24
36
|
Symbols represents attributes that in product_ver2 are different then in product_ver1. If there is hash in changes key, it represents some changes in object that is in one <-> one relation with product_ver2.
|
25
37
|
|
26
|
-
Added and deleted contains array of hashes. Every hash has symbol as a key, that is used to access array of elements where changes occures. As a value it contains array of elements that has been added/deleted from product_ver2, in comparision to product_ver1.
|
38
|
+
Added and deleted contains array of hashes. Every hash has symbol as a key, that is used to access array of elements where changes occures. As a value it contains array of elements that has been added/deleted from product_ver2, in comparision to product_ver1.
|
39
|
+
|
40
|
+
Example of result, when comparing two elibri products, when full_title changed and in contributors name of one changes. Also it adds a new language and delete one text_content.
|
41
|
+
```ruby
|
42
|
+
{
|
43
|
+
:added => [<Elibri::ONIX::Release_3_0::Language>],
|
44
|
+
:changes => [:full_title, {:contributors => [ {123456 => :name} ] } ],
|
45
|
+
:deleted => [<Elibri::ONIX::Release_3_0::TextContent>]
|
46
|
+
}
|
data/lib/elibri_xml_versions.rb
CHANGED
@@ -17,6 +17,9 @@ module Elibri
|
|
17
17
|
SKIPPED_2 = ["@id", "@id_before_type_cast"]
|
18
18
|
|
19
19
|
|
20
|
+
def eid
|
21
|
+
return "fcb38e846e666d8d686c491a23431a7b0336451b"
|
22
|
+
end
|
20
23
|
|
21
24
|
attr_accessor :a, :b
|
22
25
|
|
@@ -76,11 +79,13 @@ module Elibri
|
|
76
79
|
if a.is_a? Array
|
77
80
|
a.compact!
|
78
81
|
b.compact!
|
79
|
-
a.
|
80
|
-
|
82
|
+
if a.all? { |x| x.respond_to?(:eid) }
|
83
|
+
a.sort! { |x,y| x.eid <=> y.eid }
|
84
|
+
b.sort! { |x,y| x.eid <=> y.eid }
|
85
|
+
end
|
81
86
|
if a.all? { |x| x.instance_variables.include? "@id_before_type_cast"} || a.all? { |x| x.instance_variables.include? "@import_id"}
|
82
|
-
a_m = a.map { |x| x.
|
83
|
-
b_m = b.map { |x| x.
|
87
|
+
a_m = a.map { |x| x.eid }
|
88
|
+
b_m = b.map { |x| x.eid }
|
84
89
|
else
|
85
90
|
=begin
|
86
91
|
ch = []
|
@@ -100,18 +105,18 @@ module Elibri
|
|
100
105
|
end
|
101
106
|
# if a.map(&:id) != b.map(&:id)
|
102
107
|
if a_m != b_m
|
103
|
-
deleted_ids = a.map(&:
|
104
|
-
added_ids = b.map(&:
|
105
|
-
deleted_ids.each do |
|
106
|
-
if a.find { |x| x.
|
107
|
-
deleted << a.find { |x| x.
|
108
|
-
a.delete(a.find { |x| x.
|
108
|
+
deleted_ids = a.map(&:eid) - b.map(&:eid)
|
109
|
+
added_ids = b.map(&:eid) - a.map(&:eid)
|
110
|
+
deleted_ids.each do |eid|
|
111
|
+
if a.find { |x| x.eid == eid } && !a.find { |x| x.eid == eid }.blank?
|
112
|
+
deleted << a.find { |x| x.eid == eid }
|
113
|
+
a.delete(a.find { |x| x.eid == eid })
|
109
114
|
end
|
110
115
|
end
|
111
|
-
added_ids.each do |
|
112
|
-
if b.find { |x| x.
|
113
|
-
added << b.find { |x| x.
|
114
|
-
b.delete(b.find { |x| x.
|
116
|
+
added_ids.each do |eid|
|
117
|
+
if b.find { |x| x.eid == eid } && !b.find { |x| x.eid == eid }.blank?
|
118
|
+
added << b.find { |x| x.eid == eid }
|
119
|
+
b.delete(b.find { |x| x.eid == eid })
|
115
120
|
end
|
116
121
|
end
|
117
122
|
end
|
@@ -119,7 +124,7 @@ module Elibri
|
|
119
124
|
a.each_with_index do |element, i|
|
120
125
|
ret = check_tree(element, b[i])
|
121
126
|
[:changes, :added, :deleted].each do |key|
|
122
|
-
ret[key] = ret[key].map { |x| {element.
|
127
|
+
ret[key] = ret[key].map { |x| {element.eid => x}}
|
123
128
|
end
|
124
129
|
changes += ret[:changes]
|
125
130
|
added += ret[:added]
|
data/spec/spec_helper.rb
CHANGED
@@ -22,11 +22,11 @@ RSpec.configure do |config|
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def onix_from_mock(sym, *args)
|
25
|
-
Elibri::ONIX::Release_3_0::ONIXMessage.
|
25
|
+
Elibri::ONIX::Release_3_0::ONIXMessage.new(Elibri::ONIX::XMLGenerator.new(Elibri::XmlMocks::Examples.send(sym, *args)).to_s)
|
26
26
|
end
|
27
27
|
|
28
28
|
def xml_parse(xml_string)
|
29
|
-
Elibri::ONIX::Release_3_0::ONIXMessage.
|
29
|
+
Elibri::ONIX::Release_3_0::ONIXMessage.new(xml_string)
|
30
30
|
end
|
31
31
|
|
32
32
|
def generate_xml(mock)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: elibri_xml_versions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 5
|
10
|
+
version: 0.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Piotr Szmielew
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-06-07 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|