rexle-diff 0.1.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 956b5297dd801c3f172110850358280cc3a6649c
4
+ data.tar.gz: 2383a98963cd4cb736658614a66b4c515e684cb4
5
+ SHA512:
6
+ metadata.gz: 2768d360b4a9635eabca61e1e7d7d95ffdbb3a310b13eea72d78b8c3580a619e95eb0622e15a28c2ab2d0ca8261392c045323c057ebf70fd43301eedb88a7515
7
+ data.tar.gz: 48ae56e7f1fb8098608258f466aabc6a80f34c2a840fa3f2c035fb9527f6227c8bb9698e1a81e55c454f721a3153312b22ad68f4e0ea911540c7daa7bdd2db26
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ �|��?� �RC�퀪� ���7(��Xrt�{���G��(1@�X���'�L�܈���Z�꒤43돠��52i{'�QT���B��eޘ�q��w�+�1��Fa�+9������W�A��"���F����G 6�}j>?�]�� %t���s*��
2
+ 1g�Z���$���NI�O��Cs%2��R�㷛Ы3�T��#f]śD�Vܭ?*ߤ����.��$����>픗��Fg�鼆���K�͗��S�(,c;7�
data/lib/rexle-diff.rb ADDED
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # file: rexle-diff.rb
4
+
5
+ require 'rexle'
6
+
7
+
8
+ class RexleDiff
9
+
10
+ attr_reader :to_doc
11
+
12
+ def initialize(source1, source2, ignore_removed: true)
13
+
14
+ a = timestamp(Rexle.new(source1)).to_a
15
+ a2 = RexleParser.new(source2).to_a
16
+
17
+ compare(a, a2)
18
+
19
+ @to_doc = Rexle.new(a2)
20
+ end
21
+
22
+ private
23
+
24
+ def names_values(c)
25
+
26
+ c.inject([[],[]]) {|r, x| r.first << x[0]; r.last << x[2]; r }
27
+
28
+ end
29
+
30
+ def added(list, list2)
31
+
32
+ result = list2 - list
33
+ indexes = result.map {|x| list2.index x}
34
+
35
+ end
36
+
37
+ def array_index(a,i)
38
+ a2 = a.select{|x| x.is_a? Array}
39
+ a.index a2[i]
40
+ end
41
+
42
+ def compare(a, a2)
43
+ _, _, _, *raw_c = a
44
+ c = raw_c.select{|x| x.is_a? Array}
45
+ names, values = names_values(c)
46
+
47
+ _, _, _, *raw_c2 = a2
48
+ c2 = raw_c2.select{|x| x.is_a? Array}
49
+ names2, values2 = names_values(c2)
50
+
51
+ added_indexes = added(values, values2)
52
+
53
+ added_indexes.each do |i|
54
+
55
+ offset = array_index(a2, i)
56
+ a2[offset][1].merge!(created: Time.now, last_modified: Time.now)
57
+ end
58
+
59
+ # we need to know the deleted index
60
+ deleted_indexes = deleted(values, values2)
61
+
62
+ unchanged_indexes = unchanged(values, values2)
63
+ #puts 'c : ' + c.inspect
64
+ #puts 'added: ' + added_indexes.inspect
65
+ #puts 'deleted :' + deleted_indexes.inspect
66
+ #puts 'unchanged : ' + unchanged_indexes.inspect
67
+
68
+ # check the child element if any
69
+
70
+ unchanged_indexes.each do |i, i2|
71
+
72
+ offset = array_index(a, i)
73
+ offset2 = array_index(a2, i2)
74
+ a2[offset2][1].merge!(a[offset][1])
75
+ compare(c[i],c2[i]) if c[i].length > 3
76
+ end
77
+
78
+ end
79
+
80
+ def deleted(list, list2)
81
+
82
+ result = list - list2
83
+ indexes = result.map {|x| list.index x}
84
+
85
+ end
86
+
87
+ def timestamp(doc)
88
+
89
+ doc.root.traverse do |x|
90
+ x.attributes[:created] = Time.now unless x.attributes[:created]
91
+ end
92
+
93
+ return doc
94
+ end
95
+
96
+ def unchanged(list, list2)
97
+
98
+ result = list & list2
99
+ indexes = result.map {|x| list.index x}
100
+ indexes2 = result.map {|x| list2.index x}
101
+
102
+ indexes.zip(indexes2)
103
+
104
+ end
105
+
106
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rexle-diff
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - James Robertson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
+ YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
+ 8ixkARkWAmV1MB4XDTE1MDMyMjIwNDkyMloXDTE2MDMyMTIwNDkyMlowSDESMBAG
16
+ A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
+ EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
+ ggEBAMiYrKeP9vQrQ7WRzzXlh1LUBgFNuKSQyppkKdWiAXyIwOkbuW9Z/p7UkC3D
19
+ SOKVlnndW69FEQ2abJCDfqmmXLXU2p67meF8vGcxdK7VzLUe4vUocJYhSqPUy4V4
20
+ LweSfcanhY+0AvZ1WRgfnbMvgpDWNg3Bpx6SrxoFUuPJgtWjui6eq4jPiw2MQuJC
21
+ zDfe1hpNO0jkuNho8hQHmUQWCXXt04s9jT+Pt5Somrc3GOiRyF72tuilZLmIAv8O
22
+ ACxhbCy6hhGa77VAQEv1rLCNc/gEc6/Y6Bkbufy9DJ/fFC3XHruZ5PMMBN5ztBxf
23
+ brAGWbPfMYTJEbjy7x39BFNi3iMCAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
24
+ DwQEAwIEsDAdBgNVHQ4EFgQUQidYCjP6g5ocez2NRp80Q31bvHAwJgYDVR0RBB8w
25
+ HYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1h
26
+ c3RlckBqYW1lc3JvYmVydHNvbi5ldTANBgkqhkiG9w0BAQUFAAOCAQEApchg6EQj
27
+ q8Exyo/LU2hyzG4//R+oiY2zBE7oM3RUMzVtms+R8n//pdw8nMVG4WXrwaGW7vlt
28
+ MHC+TBgGBQWQdXTdP+/eDi01s9Qd+rLl7zxmmw7u8JGQpizZqVGGZCzX/VtMNskJ
29
+ Lt2WkJjRXTGGCU6Qk9U/awUr4lAQlxiHciTgG/BsQvuegNUZBFpp7PMaIZ82aAQg
30
+ NoitOpFoKRpE0GNLypJU/FJS++2hs1nKKFPZLtrrncRDnI6/9ImymDgBstSfmQH/
31
+ 1dtvoSgugum4cZlSFYiRyLXuJz4nZeMJGod1r8cOFR0dwx7yOdvKZybPd4FXWVjG
32
+ EozQjWbvhzsspQ==
33
+ -----END CERTIFICATE-----
34
+ date: 2015-03-22 00:00:00.000000000 Z
35
+ dependencies:
36
+ - !ruby/object:Gem::Dependency
37
+ name: rexle
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.2'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 1.2.23
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.2'
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 1.2.23
56
+ - !ruby/object:Gem::Dependency
57
+ name: rexle-builder
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '0.2'
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: 0.2.1
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - "~>"
71
+ - !ruby/object:Gem::Version
72
+ version: '0.2'
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.2.1
76
+ description:
77
+ email: james@r0bertson.co.uk
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - lib/rexle-diff.rb
83
+ homepage: https://github.com/jrobertson/rexle-diff
84
+ licenses:
85
+ - MIT
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 2.4.6
104
+ signing_key:
105
+ specification_version: 4
106
+ summary: rexle-diff
107
+ test_files: []
metadata.gz.sig ADDED
Binary file