see_as_vee 0.2.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +18 -0
- data/README.md +4 -8
- data/lib/see_as_vee.rb +6 -0
- data/lib/see_as_vee/sheet.rb +31 -6
- data/lib/see_as_vee/version.rb +1 -1
- data/see_as_vee.gemspec +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bda0e7c5604b2852ef6a5240f4d501a60d76355
|
4
|
+
data.tar.gz: f6a397f42b59089a4ba5c489da697350f8e138f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d43111bb60b34ff21005eea31cafea0a7633aae858e2489a9f41ec6346e11e1743992619d5c7ba36f357b6d59c32a309926a2155843b8ddb0a4c00a1484166d
|
7
|
+
data.tar.gz: 21b09d7abb0a3a408c26bf2c01bbb298362192e9ce6bf1d018c3380a94378077d3f1c0c9e26c0b19457e35d4575c77b2e007d0f7f7d5f4e9d5fa68e813ede564
|
data/.rubocop.yml
CHANGED
@@ -15,6 +15,24 @@ Style/AsciiComments:
|
|
15
15
|
- 'spec/**/*'
|
16
16
|
- 'lib/**/*'
|
17
17
|
|
18
|
+
Metrics/ClassLength:
|
19
|
+
Max: 200
|
20
|
+
|
21
|
+
Metrics/CyclomaticComplexity:
|
22
|
+
Max: 21
|
23
|
+
|
24
|
+
Metrics/LineLength:
|
25
|
+
Max: 180
|
26
|
+
|
27
|
+
Metrics/MethodLength:
|
28
|
+
Max: 42
|
29
|
+
|
30
|
+
Metrics/PerceivedComplexity:
|
31
|
+
Max: 21
|
32
|
+
|
33
|
+
Metrics/AbcSize:
|
34
|
+
Max: 42
|
35
|
+
|
18
36
|
Style/MethodDefParentheses:
|
19
37
|
EnforcedStyle: require_no_parentheses
|
20
38
|
|
data/README.md
CHANGED
@@ -7,14 +7,10 @@
|
|
7
7
|
|
8
8
|
Easy dealing with CSV import, including, but not limited to:
|
9
9
|
|
10
|
-
✓ import in any format: `String`, `csv`, `xlsx`;
|
11
|
-
|
12
|
-
✓
|
13
|
-
|
14
|
-
✓ input checkers;
|
15
|
-
|
16
|
-
✓ callbacks on errors;
|
17
|
-
|
10
|
+
✓ import in any format: `String`, `csv`, `xlsx`;
|
11
|
+
✓ additional input formatting;
|
12
|
+
✓ input checkers;
|
13
|
+
✓ callbacks on errors;
|
18
14
|
✓ producing of “suggested edits” version of input (both `csv` and `xlsx` formats).
|
19
15
|
|
20
16
|
## Installation
|
data/lib/see_as_vee.rb
CHANGED
@@ -2,6 +2,7 @@ begin
|
|
2
2
|
require 'filemagic'
|
3
3
|
rescue LoadError => e
|
4
4
|
# OK, we do not have filemagick, no worries
|
5
|
+
puts "We were unable to find “filemagick,” will use simple file guessing [#{e.message}]."
|
5
6
|
end
|
6
7
|
|
7
8
|
require 'axlsx'
|
@@ -26,6 +27,11 @@ module SeeAsVee
|
|
26
27
|
end
|
27
28
|
module_function :harvest
|
28
29
|
|
30
|
+
def validate whatever, schema
|
31
|
+
SeeAsVee::Sheet.new(whatever).map(&schema)
|
32
|
+
end
|
33
|
+
module_function :validate
|
34
|
+
|
29
35
|
def csv *args, **params
|
30
36
|
SeeAsVee::Producers::Hashes.csv(*args, **params)
|
31
37
|
end
|
data/lib/see_as_vee/sheet.rb
CHANGED
@@ -2,15 +2,18 @@ require_relative 'helpers'
|
|
2
2
|
|
3
3
|
module SeeAsVee
|
4
4
|
class Sheet
|
5
|
-
CELL_ERROR_MARKER = '
|
5
|
+
CELL_ERROR_MARKER = '⚑ '.freeze
|
6
6
|
CELL_ERROR_STYLE = {
|
7
7
|
bg_color: "FF880000",
|
8
8
|
fg_color: "FFFFFFFF",
|
9
9
|
sz: 14,
|
10
10
|
border: { style: :thin, color: "FFFF0000" }
|
11
11
|
}.freeze
|
12
|
+
WORK_SHEET_NAME = 'Processing errors shown in red'.freeze
|
13
|
+
LEAVE_ERROR_MARKER = true
|
12
14
|
|
13
15
|
attr_reader :rows, :formatters, :checkers
|
16
|
+
|
14
17
|
def initialize whatever, formatters: {}, checkers: {}
|
15
18
|
@formatters = formatters.map { |k, v| [str_to_sym(k), v] }.to_h
|
16
19
|
@checkers = checkers.map { |k, v| [str_to_sym(k), v] }.to_h
|
@@ -43,6 +46,14 @@ module SeeAsVee
|
|
43
46
|
end
|
44
47
|
end
|
45
48
|
|
49
|
+
def map
|
50
|
+
return enum_for unless block_given?
|
51
|
+
|
52
|
+
values.map do |row|
|
53
|
+
yield headers(true).zip(row).to_h
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
46
57
|
def produce csv: true, xlsx: nil, **params
|
47
58
|
[csv && produce_csv(**params), xlsx && produce_xlsx(**params)]
|
48
59
|
end
|
@@ -50,7 +61,7 @@ module SeeAsVee
|
|
50
61
|
private
|
51
62
|
|
52
63
|
def malformed? str
|
53
|
-
str.to_s
|
64
|
+
str.to_s.start_with? CELL_ERROR_MARKER
|
54
65
|
end
|
55
66
|
|
56
67
|
def produce_csv **params
|
@@ -61,12 +72,17 @@ module SeeAsVee
|
|
61
72
|
end
|
62
73
|
end
|
63
74
|
|
64
|
-
def produce_xlsx **
|
75
|
+
def produce_xlsx **params
|
76
|
+
params, axlsx_params = split_params(params)
|
65
77
|
Tempfile.new(['see_as_vee', '.xlsx']).tap do |f|
|
66
78
|
Axlsx::Package.new do |p|
|
67
|
-
red = p.workbook.styles.add_style(**
|
68
|
-
p.workbook.add_worksheet(
|
69
|
-
@rows.each
|
79
|
+
red = p.workbook.styles.add_style(**params[:ces]) if params[:ces].is_a?(Hash)
|
80
|
+
p.workbook.add_worksheet(**axlsx_params) do |sheet|
|
81
|
+
@rows.each do |row|
|
82
|
+
styles = row.map { |cell| malformed?(cell) ? red : nil }
|
83
|
+
row = row.map { |cell| cell.to_s.gsub(/\A#{params[:cem]}/, '') if malformed?(cell) } if params[:lem]
|
84
|
+
sheet.add_row row, style: styles
|
85
|
+
end
|
70
86
|
end
|
71
87
|
p.serialize(f.path)
|
72
88
|
end
|
@@ -109,5 +125,14 @@ module SeeAsVee
|
|
109
125
|
end ? cell : CELL_ERROR_MARKER + cell.to_s.split('').map { |c| "#{c}\u0336" }.join
|
110
126
|
end
|
111
127
|
# rubocop:enable Style/MultilineTernaryOperator
|
128
|
+
|
129
|
+
def split_params params
|
130
|
+
params = params.dup
|
131
|
+
[
|
132
|
+
{ ces: params.delete(:cell_error_style) { CELL_ERROR_STYLE.dup },
|
133
|
+
lem: params.delete(:leave_error_marker) { LEAVE_ERROR_MARKER } },
|
134
|
+
{ name: WORK_SHEET_NAME }.merge(params)
|
135
|
+
]
|
136
|
+
end
|
112
137
|
end
|
113
138
|
end
|
data/lib/see_as_vee/version.rb
CHANGED
data/see_as_vee.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_dependency 'simple_xlsx_reader'
|
29
29
|
spec.add_dependency 'axlsx'
|
30
30
|
# spec.add_dependency 'ruby-filemagic', require: false
|
31
|
-
spec.add_dependency 'mutations'
|
31
|
+
spec.add_dependency 'dry-mutations'
|
32
32
|
|
33
33
|
spec.add_development_dependency 'bundler', '~> 1.10'
|
34
34
|
spec.add_development_dependency 'rake', '~> 10.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: see_as_vee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksei Matiushkin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simple_xlsx_reader
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name: mutations
|
42
|
+
name: dry-mutations
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0
|
47
|
+
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|