csv-diff-report 0.3.1 → 0.3.2
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/lib/csv-diff-report/cli.rb +3 -1
- data/lib/csv-diff-report/excel.rb +2 -2
- data/lib/csv-diff-report/html.rb +8 -11
- data/lib/csv-diff-report/report.rb +15 -11
- data/lib/csv-diff-report/text.rb +44 -0
- metadata +20 -8
- checksums.yaml +0 -15
data/lib/csv-diff-report/cli.rb
CHANGED
@@ -45,6 +45,8 @@ class CSVDiff
|
|
45
45
|
keyword_arg :encoding, 'The encoding to use when opening the CSV files',
|
46
46
|
short_key: 'e'
|
47
47
|
flag_arg :tab_delimited, 'If true, the file is assumed to be tab-delimited rather than comma-delimited'
|
48
|
+
flag_arg :diff_common_fields_only, 'If true, only fields in both files are compared'
|
49
|
+
flag_arg :trim_whitespace, 'If true, trim leading/trailing whitespace before comparing fields'
|
48
50
|
flag_arg :ignore_header, 'If true, the first line in each source file is ignored; ' +
|
49
51
|
'requires the use of the --field-names option to name the fields'
|
50
52
|
flag_arg :ignore_case, 'If true, field comparisons are performed without regard to case'
|
@@ -63,7 +65,7 @@ class CSVDiff
|
|
63
65
|
|
64
66
|
usage_break 'Output Options'
|
65
67
|
keyword_arg :format, 'The format in which to produce the diff report',
|
66
|
-
default: 'HTML', validation: /^(html|
|
68
|
+
default: 'HTML', validation: /^(html|xlsx?|te?xt)$/i
|
67
69
|
keyword_arg :output, 'The path to save the diff report to. If not specified, the diff ' +
|
68
70
|
'report will be placed in the same directory as the FROM file, and will be named ' +
|
69
71
|
'Diff_<FROM>_to_<TO>.<FORMAT>'
|
@@ -50,11 +50,11 @@ class CSVDiff
|
|
50
50
|
xl.workbook.add_worksheet(name: 'Summary') do |sheet|
|
51
51
|
sheet.add_row do |row|
|
52
52
|
row.add_cell 'From:', :style => @xl_styles['Title']
|
53
|
-
row.add_cell
|
53
|
+
row.add_cell compare_from
|
54
54
|
end
|
55
55
|
sheet.add_row do |row|
|
56
56
|
row.add_cell 'To:', :style => @xl_styles['Title']
|
57
|
-
row.add_cell
|
57
|
+
row.add_cell compare_to
|
58
58
|
end
|
59
59
|
sheet.add_row
|
60
60
|
sheet.add_row ['Sheet', 'Adds', 'Deletes', 'Updates', 'Moves'], :style => @xl_styles['Title']
|
data/lib/csv-diff-report/html.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'cgi'
|
2
|
+
|
1
3
|
|
2
4
|
class CSVDiff
|
3
5
|
|
@@ -6,7 +8,7 @@ class CSVDiff
|
|
6
8
|
|
7
9
|
private
|
8
10
|
|
9
|
-
# Generare a diff report in
|
11
|
+
# Generare a diff report in HTML format.
|
10
12
|
def html_output(output)
|
11
13
|
content = []
|
12
14
|
content << '<html>'
|
@@ -25,7 +27,7 @@ class CSVDiff
|
|
25
27
|
content << '</body>'
|
26
28
|
content << '</html>'
|
27
29
|
|
28
|
-
# Save
|
30
|
+
# Save page
|
29
31
|
path = "#{File.dirname(output)}/#{File.basename(output, File.extname(output))}.html"
|
30
32
|
File.open(path, 'w'){ |f| f.write(content.join("\n")) }
|
31
33
|
path
|
@@ -69,13 +71,8 @@ class CSVDiff
|
|
69
71
|
body << '<p>Source Locations:</p>'
|
70
72
|
body << '<table>'
|
71
73
|
body << '<tbody>'
|
72
|
-
|
73
|
-
|
74
|
-
body << "<tr><th>To:</th><td>#{File.dirname(@right)}</td></tr>"
|
75
|
-
else
|
76
|
-
body << "<tr><th>From:</th><td>#{@left}</td></tr>"
|
77
|
-
body << "<tr><th>To:</th><td>#{@right}</td></tr>"
|
78
|
-
end
|
74
|
+
body << "<tr><th>From:</th><td>#{@left}</td></tr>"
|
75
|
+
body << "<tr><th>To:</th><td>#{@right}</td></tr>"
|
79
76
|
body << '</tbody>'
|
80
77
|
body << '</table>'
|
81
78
|
body << '<br>'
|
@@ -161,9 +158,9 @@ class CSVDiff
|
|
161
158
|
style = chg.downcase if i == 1
|
162
159
|
end
|
163
160
|
body << '<td>'
|
164
|
-
body << "<span class='delete'>#{old}</span>" if old
|
161
|
+
body << "<span class='delete'>#{CGI.escapeHTML(old.to_s)}</span>" if old
|
165
162
|
body << '<br>' if old && old.to_s.length > 10
|
166
|
-
body << "<span#{style ? " class='#{style}'" : ''}>#{new}</span>"
|
163
|
+
body << "<span#{style ? " class='#{style}'" : ''}>#{CGI.escapeHTML(new.to_s)}</span>"
|
167
164
|
body << '</td>'
|
168
165
|
end
|
169
166
|
body << '</tr>'
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'csv-diff-report/excel'
|
2
2
|
require 'csv-diff-report/html'
|
3
|
+
require 'csv-diff-report/text'
|
3
4
|
|
4
5
|
|
5
6
|
class CSVDiff
|
@@ -12,6 +13,7 @@ class CSVDiff
|
|
12
13
|
|
13
14
|
include Excel
|
14
15
|
include Html
|
16
|
+
include Text
|
15
17
|
|
16
18
|
|
17
19
|
# Instantiate a new diff report object. Takes an optional block callback
|
@@ -49,7 +51,7 @@ class CSVDiff
|
|
49
51
|
@left = Pathname.new(diff.left.path)
|
50
52
|
@right = Pathname.new(diff.right.path)
|
51
53
|
end
|
52
|
-
diff.diff_warnings.each{ |warn| echo warn, :yellow }
|
54
|
+
diff.diff_warnings.each{ |warn| echo [warn, :yellow] }
|
53
55
|
out = []
|
54
56
|
out << ["Found #{diff.diffs.size} differences"]
|
55
57
|
diff.summary.each_with_index.map do |pair, i|
|
@@ -115,6 +117,8 @@ class CSVDiff
|
|
115
117
|
xl_output(path)
|
116
118
|
when format.to_s =~ /^html$/i || File.extname(path) =~ /html$/i
|
117
119
|
html_output(path)
|
120
|
+
when format.to_s =~ /^te?xt$/i || File.extname(path) =~ /txt$/i
|
121
|
+
text_output(path)
|
118
122
|
else
|
119
123
|
raise ArgumentError, "Unrecognised output format: #{format}"
|
120
124
|
end
|
@@ -160,16 +164,16 @@ class CSVDiff
|
|
160
164
|
if matches.size > 0
|
161
165
|
matched_fts.concat(matches)
|
162
166
|
else
|
163
|
-
echo "No file type matching '#{ft}' defined in .csvdiff", :yellow
|
164
|
-
echo "Known file types are: #{opt_file[:file_types].keys.join(', ')}", :yellow
|
167
|
+
echo ["No file type matching '#{ft}' defined in .csvdiff", :yellow]
|
168
|
+
echo ["Known file types are: #{opt_file[:file_types].keys.join(', ')}", :yellow]
|
165
169
|
end
|
166
170
|
end
|
167
171
|
else
|
168
172
|
if opt_file
|
169
|
-
echo "No file types are defined in .csvdiff", :yellow
|
173
|
+
echo ["No file types are defined in .csvdiff", :yellow]
|
170
174
|
else
|
171
|
-
echo "The file_types option can only be used when a " +
|
172
|
-
".csvdiff is present in the LEFT or current directory", :yellow
|
175
|
+
echo ["The file_types option can only be used when a " +
|
176
|
+
".csvdiff is present in the LEFT or current directory", :yellow]
|
173
177
|
end
|
174
178
|
end
|
175
179
|
matched_fts.uniq
|
@@ -191,8 +195,8 @@ class CSVDiff
|
|
191
195
|
if right_file.file?
|
192
196
|
diff_file(file, right_file.to_s, options, opt_file)
|
193
197
|
else
|
194
|
-
echo "Skipping file '#{File.basename(file)}', as there is " +
|
195
|
-
"no corresponding TO file", :yellow
|
198
|
+
echo ["Skipping file '#{File.basename(file)}', as there is " +
|
199
|
+
"no corresponding TO file", :yellow]
|
196
200
|
end
|
197
201
|
end
|
198
202
|
end
|
@@ -221,8 +225,8 @@ class CSVDiff
|
|
221
225
|
settings = opt_file && opt_file[:defaults] || {}
|
222
226
|
opt_file && opt_file[:file_types] && opt_file[:file_types].each do |file_type, hsh|
|
223
227
|
unless hsh[:pattern]
|
224
|
-
echo "Invalid setting for file_type #{file_type} in .csvdiff; " +
|
225
|
-
"missing a 'pattern' key to use to match files", :yellow
|
228
|
+
echo ["Invalid setting for file_type #{file_type} in .csvdiff; " +
|
229
|
+
"missing a 'pattern' key to use to match files", :yellow]
|
226
230
|
hsh[:pattern] = '-'
|
227
231
|
end
|
228
232
|
next if hsh[:pattern] == '-'
|
@@ -249,7 +253,7 @@ class CSVDiff
|
|
249
253
|
csv_src = CSVDiff::CSVSource.new(src.to_s, options)
|
250
254
|
out << [" #{csv_src.lines.size} lines read", :white]
|
251
255
|
echo(*out)
|
252
|
-
csv_src.warnings.each{ |warn| echo warn, :yellow }
|
256
|
+
csv_src.warnings.each{ |warn| echo [warn, :yellow] }
|
253
257
|
csv_src
|
254
258
|
end
|
255
259
|
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
|
4
|
+
class CSVDiff
|
5
|
+
|
6
|
+
# Defines functionality for exporting a Diff report in TEXT format. This is
|
7
|
+
# a CSV format where only fields with differences have values.
|
8
|
+
module Text
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
# Generare a diff report in TEXT format.
|
13
|
+
def text_output(output)
|
14
|
+
path = "#{File.dirname(output)}/#{File.basename(output, File.extname(output))}.diff"
|
15
|
+
CSV.open(path, 'w') do |csv|
|
16
|
+
@diffs.each do |file_diff|
|
17
|
+
text_diff(csv, file_diff) if file_diff.diffs.size > 0
|
18
|
+
end
|
19
|
+
end
|
20
|
+
path
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def text_diff(csv, file_diff)
|
25
|
+
count = 0
|
26
|
+
|
27
|
+
all_fields = [:row, :action]
|
28
|
+
all_fields << :sibling_position unless file_diff.options[:ignore_moves]
|
29
|
+
all_fields.concat(file_diff.diff_fields)
|
30
|
+
|
31
|
+
csv << all_fields.map{ |fld| fld.is_a?(Symbol) ? titleize(fld) : fld }
|
32
|
+
file_diff.diffs.each do |key, diff|
|
33
|
+
row = all_fields.map do |field|
|
34
|
+
d = diff[field]
|
35
|
+
d = d.last if d.is_a?(Array)
|
36
|
+
d
|
37
|
+
end
|
38
|
+
csv << row
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
metadata
CHANGED
@@ -1,18 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csv-diff-report
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Adam Gardiner
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2016-01-26 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: csv-diff
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ! '>='
|
18
20
|
- !ruby/object:Gem::Version
|
@@ -20,6 +22,7 @@ dependencies:
|
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
27
|
- - ! '>='
|
25
28
|
- !ruby/object:Gem::Version
|
@@ -27,6 +30,7 @@ dependencies:
|
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: arg-parser
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
35
|
- - ! '>='
|
32
36
|
- !ruby/object:Gem::Version
|
@@ -34,6 +38,7 @@ dependencies:
|
|
34
38
|
type: :runtime
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
43
|
- - ! '>='
|
39
44
|
- !ruby/object:Gem::Version
|
@@ -41,6 +46,7 @@ dependencies:
|
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: color-console
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
51
|
- - ! '>='
|
46
52
|
- !ruby/object:Gem::Version
|
@@ -48,6 +54,7 @@ dependencies:
|
|
48
54
|
type: :runtime
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
59
|
- - ! '>='
|
53
60
|
- !ruby/object:Gem::Version
|
@@ -55,6 +62,7 @@ dependencies:
|
|
55
62
|
- !ruby/object:Gem::Dependency
|
56
63
|
name: axlsx
|
57
64
|
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
58
66
|
requirements:
|
59
67
|
- - ~>
|
60
68
|
- !ruby/object:Gem::Version
|
@@ -62,6 +70,7 @@ dependencies:
|
|
62
70
|
type: :runtime
|
63
71
|
prerelease: false
|
64
72
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
65
74
|
requirements:
|
66
75
|
- - ~>
|
67
76
|
- !ruby/object:Gem::Version
|
@@ -80,37 +89,40 @@ executables:
|
|
80
89
|
extensions: []
|
81
90
|
extra_rdoc_files: []
|
82
91
|
files:
|
83
|
-
- LICENSE
|
84
92
|
- README.md
|
85
|
-
-
|
86
|
-
- lib/csv-diff-report.rb
|
93
|
+
- LICENSE
|
87
94
|
- lib/csv-diff-report/cli.rb
|
88
95
|
- lib/csv-diff-report/excel.rb
|
89
96
|
- lib/csv-diff-report/html.rb
|
90
97
|
- lib/csv-diff-report/report.rb
|
98
|
+
- lib/csv-diff-report/text.rb
|
99
|
+
- lib/csv-diff-report.rb
|
91
100
|
- lib/csv_diff_report.rb
|
101
|
+
- !binary |-
|
102
|
+
YmluL2NzdmRpZmY=
|
92
103
|
homepage: https://github.com/agardiner/csv-diff-report
|
93
104
|
licenses: []
|
94
|
-
metadata: {}
|
95
105
|
post_install_message:
|
96
106
|
rdoc_options: []
|
97
107
|
require_paths:
|
98
108
|
- lib
|
99
109
|
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
100
111
|
requirements:
|
101
112
|
- - ! '>='
|
102
113
|
- !ruby/object:Gem::Version
|
103
114
|
version: '0'
|
104
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
105
117
|
requirements:
|
106
118
|
- - ! '>='
|
107
119
|
- !ruby/object:Gem::Version
|
108
120
|
version: '0'
|
109
121
|
requirements: []
|
110
122
|
rubyforge_project:
|
111
|
-
rubygems_version:
|
123
|
+
rubygems_version: 1.8.21
|
112
124
|
signing_key:
|
113
|
-
specification_version:
|
125
|
+
specification_version: 3
|
114
126
|
summary: CSV Diff Report is a library for generating diff reports using the CSV Diff
|
115
127
|
gem
|
116
128
|
test_files: []
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
NmNhMzlmNDc4ZGQ5NWU1MjdlMjdmN2JlNTI4NGQ0NWE1ODY0ZmVlMw==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NjY0ODgxMmU1ZDFkZWQ2ZmY4MWQwNDU5NmM5YTUzNGJlODNmNzVkNw==
|
7
|
-
SHA512:
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
YTFiNmQ5YWZkNDllNmI0OGE3ZjI0ZjE2ZTYwY2U4YTUwZDliZDUzYTc1Njg1
|
10
|
-
NzBmOTg1YmFmMTkxY2VmNTdkNTliZTA0YTgzODJhMDZhOTFmN2U2MTlkZmQ1
|
11
|
-
MWEzMDcxM2U1NTZhNDVhMjgwYWI0MDNjNjA0NGRiOTZkMGUxNGY=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
Y2Y4YzVjMzY1NGJlZTE0MTkzOGQ2YWEwODU1MzVmYjJmYzNhMWIxYTJjNDBh
|
14
|
-
NDQ5NTE1NTA0MjkyYmY0YTkxMmQ5NGUyYTkxYTE3NTQ5YzEzODJjMWI3NTJj
|
15
|
-
MzQ1ZTQyMmI1NzcxOWY3OWI4ZTNkZDYwZmE3MjkzYzEyMGVkNWE=
|