elibri_xml_versions 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -0
- data/README.md +3 -1
- data/lib/elibri_xml_versions/version.rb +1 -1
- data/lib/elibri_xml_versions.rb +10 -6
- data/spec/elibri_xml_versions_spec.rb +12 -0
- metadata +5 -5
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem created for comparing eLibri xml objects.
|
4
4
|
|
5
|
-
Currently working and tested
|
5
|
+
Currently working and tested on 1.8 version of Ruby (REE, jRuby 1.8, Ruby 1.8.7).
|
6
6
|
|
7
7
|
Basic usage:
|
8
8
|
``Elibri::XmlVersions.new(product_ver1, product_ver2).diff``
|
@@ -19,6 +19,8 @@ It will return hash:
|
|
19
19
|
```
|
20
20
|
|
21
21
|
under changes key, will be array of symbol and/or hashes.
|
22
|
+
If there is change deeper in structure it will be represented like this:
|
23
|
+
`:changes => [{:contributors => [{2167055520 => :key_names}]`
|
22
24
|
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.
|
23
25
|
|
24
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.
|
data/lib/elibri_xml_versions.rb
CHANGED
@@ -118,6 +118,9 @@ module Elibri
|
|
118
118
|
#obsługa różnych elementów w arrayu
|
119
119
|
a.each_with_index do |element, i|
|
120
120
|
ret = check_tree(element, b[i])
|
121
|
+
[:changes, :added, :deleted].each do |key|
|
122
|
+
ret[key] = ret[key].map { |x| {element.id => x}}
|
123
|
+
end
|
121
124
|
changes += ret[:changes]
|
122
125
|
added += ret[:added]
|
123
126
|
deleted += ret[:deleted]
|
@@ -128,18 +131,19 @@ module Elibri
|
|
128
131
|
attrib = attrib.to_s.gsub("@", "").to_sym
|
129
132
|
if a.send(attrib).is_a? Array
|
130
133
|
ret = check_tree(a.send(attrib), b.send(attrib))
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
+
#TODO: otestować to
|
135
|
+
changes << {attrib => ret[:changes]} if !ret[:changes].blank?
|
136
|
+
added << {attrib => ret[:added]} if !ret[:added].blank?
|
137
|
+
deleted << {attrib => ret[:deleted]} if !ret[:deleted].blank?
|
134
138
|
else
|
135
139
|
if (a.send(attrib).is_a?(String) || a.send(attrib).is_a?(Numeric) || a.send(attrib).is_a?(NilClass) || b.send(attrib).is_a?(NilClass))
|
136
140
|
changes << attrib if a.send(attrib) != b.send(attrib)
|
137
141
|
else
|
138
142
|
#klasa zlozona
|
139
143
|
ret = check_tree(a.send(attrib), b.send(attrib))
|
140
|
-
changes << {attrib
|
141
|
-
added << {attrib
|
142
|
-
deleted << {attrib
|
144
|
+
changes << {attrib => ret[:changes]} if !ret[:changes].blank?
|
145
|
+
added << {attrib => ret[:added]} if !ret[:added].blank?
|
146
|
+
deleted << {attrib => ret[:deleted]} if !ret[:deleted].blank?
|
143
147
|
end
|
144
148
|
end
|
145
149
|
end
|
@@ -35,6 +35,18 @@ describe Elibri::XmlVersions do
|
|
35
35
|
@elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
|
36
36
|
@elibri_xml_versions.diff.should eq({:deleted => [], :added => [], :changes => [:record_reference]})
|
37
37
|
end
|
38
|
+
|
39
|
+
it "should return change in author on same basic elibri objects" do
|
40
|
+
author = Elibri::XmlMocks::Examples.contributor_mock(:id => 2167055520)
|
41
|
+
author_2 = Elibri::XmlMocks::Examples.contributor_mock(:last_name => 'Waza', :id => 2167055520)
|
42
|
+
generated_product = onix_from_mock(:basic_product, :record_reference => 'fdb8fa072be774d97a97', :contributors => [author])
|
43
|
+
generated_product_2 = onix_from_mock(:basic_product, :record_reference => 'fdb8fa072be774d97a97', :contributors => [author_2])
|
44
|
+
@elibri_xml_versions = Elibri::XmlVersions.new(generated_product.products.first, generated_product_2.products.first)
|
45
|
+
diff = @elibri_xml_versions.diff
|
46
|
+
diff[:deleted].should eq([])
|
47
|
+
diff[:added].should eq([])
|
48
|
+
diff[:changes].should eq( [ {:contributors => [{2167055520 => :key_names}] } ] )
|
49
|
+
end
|
38
50
|
|
39
51
|
it "should return no changes for same book elibri objects" do
|
40
52
|
generated_product = onix_from_mock(:book_example)
|
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: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
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-05-07 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
139
|
requirements: []
|
140
140
|
|
141
141
|
rubyforge_project: elibri_xml_versions
|
142
|
-
rubygems_version: 1.8.
|
142
|
+
rubygems_version: 1.8.21
|
143
143
|
signing_key:
|
144
144
|
specification_version: 3
|
145
145
|
summary: Gem created for comparing eLibri xml objects.
|