cure 0.1.2 → 0.4.0
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 +4 -4
- data/.rubocop.yml +13 -3
- data/.tool-versions +1 -0
- data/Dockerfile +1 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +25 -6
- data/README.md +61 -93
- data/docs/README.md +33 -0
- data/docs/about.md +219 -0
- data/docs/builder/add.md +52 -0
- data/docs/builder/black_white_list.md +83 -0
- data/docs/builder/copy.md +48 -0
- data/docs/builder/explode.md +70 -0
- data/docs/builder/main.md +43 -0
- data/docs/builder/remove.md +46 -0
- data/docs/examples/examples.md +164 -0
- data/docs/export/main.md +37 -0
- data/docs/extract/main.md +89 -0
- data/docs/metadata/main.md +29 -0
- data/docs/query/main.md +45 -0
- data/docs/sources/main.md +36 -0
- data/docs/transform/main.md +53 -0
- data/docs/validate/main.md +42 -0
- data/exe/cure +12 -41
- data/exe/cure.old +59 -0
- data/lib/cure/builder/base_builder.rb +151 -0
- data/lib/cure/builder/candidate.rb +56 -0
- data/lib/cure/cli/command.rb +105 -0
- data/lib/cure/cli/generate_command.rb +54 -0
- data/lib/cure/cli/new_command.rb +52 -0
- data/lib/cure/cli/run_command.rb +19 -0
- data/lib/cure/cli/templates/README.md.erb +1 -0
- data/lib/cure/cli/templates/gemfile.erb +5 -0
- data/lib/cure/cli/templates/gitignore.erb +181 -0
- data/lib/cure/cli/templates/new_template.rb.erb +31 -0
- data/lib/cure/cli/templates/tool-versions.erb +1 -0
- data/lib/cure/config.rb +142 -18
- data/lib/cure/coordinator.rb +61 -25
- data/lib/cure/database.rb +191 -0
- data/lib/cure/dsl/builder.rb +26 -0
- data/lib/cure/dsl/exporters.rb +45 -0
- data/lib/cure/dsl/extraction.rb +60 -0
- data/lib/cure/dsl/metadata.rb +33 -0
- data/lib/cure/dsl/queries.rb +36 -0
- data/lib/cure/dsl/source_files.rb +36 -0
- data/lib/cure/dsl/template.rb +131 -0
- data/lib/cure/dsl/transformations.rb +95 -0
- data/lib/cure/dsl/validator.rb +22 -0
- data/lib/cure/export/base_processor.rb +194 -0
- data/lib/cure/export/manager.rb +24 -0
- data/lib/cure/extract/base_processor.rb +47 -0
- data/lib/cure/extract/csv_lookup.rb +14 -3
- data/lib/cure/extract/extractor.rb +41 -84
- data/lib/cure/extract/filter.rb +118 -0
- data/lib/cure/extract/named_range.rb +94 -0
- data/lib/cure/extract/named_range_processor.rb +128 -0
- data/lib/cure/extract/variable.rb +25 -0
- data/lib/cure/extract/variable_processor.rb +57 -0
- data/lib/cure/generator/base_generator.rb +14 -4
- data/lib/cure/generator/case_generator.rb +10 -3
- data/lib/cure/generator/character_generator.rb +9 -3
- data/lib/cure/generator/erb_generator.rb +21 -0
- data/lib/cure/generator/eval_generator.rb +34 -0
- data/lib/cure/generator/faker_generator.rb +7 -1
- data/lib/cure/generator/guid_generator.rb +7 -2
- data/lib/cure/generator/hex_generator.rb +6 -1
- data/lib/cure/generator/imports.rb +4 -0
- data/lib/cure/generator/number_generator.rb +6 -1
- data/lib/cure/generator/placeholder_generator.rb +7 -1
- data/lib/cure/generator/proc_generator.rb +21 -0
- data/lib/cure/generator/redact_generator.rb +9 -3
- data/lib/cure/generator/static_generator.rb +21 -0
- data/lib/cure/generator/variable_generator.rb +11 -5
- data/lib/cure/helpers/file_helpers.rb +12 -2
- data/lib/cure/helpers/object_helpers.rb +5 -17
- data/lib/cure/helpers/perf_helpers.rb +30 -0
- data/lib/cure/helpers/string.rb +54 -0
- data/lib/cure/launcher.rb +125 -0
- data/lib/cure/log.rb +7 -0
- data/lib/cure/planner.rb +136 -0
- data/lib/cure/strategy/append_strategy.rb +4 -0
- data/lib/cure/strategy/base_strategy.rb +19 -44
- data/lib/cure/strategy/contain_strategy.rb +51 -0
- data/lib/cure/strategy/end_with_strategy.rb +7 -1
- data/lib/cure/strategy/full_strategy.rb +4 -0
- data/lib/cure/strategy/history/history_cache.rb +82 -0
- data/lib/cure/strategy/imports.rb +2 -0
- data/lib/cure/strategy/match_strategy.rb +7 -2
- data/lib/cure/strategy/prepend_strategy.rb +28 -0
- data/lib/cure/strategy/regex_strategy.rb +7 -1
- data/lib/cure/strategy/split_strategy.rb +8 -3
- data/lib/cure/strategy/start_with_strategy.rb +7 -1
- data/lib/cure/transformation/candidate.rb +32 -35
- data/lib/cure/transformation/transform.rb +22 -56
- data/lib/cure/validator/base_rule.rb +78 -0
- data/lib/cure/validator/candidate.rb +54 -0
- data/lib/cure/validator/manager.rb +21 -0
- data/lib/cure/validators.rb +3 -3
- data/lib/cure/version.rb +1 -1
- data/lib/cure.rb +19 -11
- data/templates/dsl_example.rb +48 -0
- data/templates/empty_template.rb +31 -0
- metadata +132 -21
- data/lib/cure/export/exporter.rb +0 -74
- data/lib/cure/extract/builder.rb +0 -27
- data/lib/cure/main.rb +0 -72
- data/lib/cure/template/dispatch.rb +0 -30
- data/lib/cure/template/extraction.rb +0 -38
- data/lib/cure/template/template.rb +0 -28
- data/lib/cure/template/transformations.rb +0 -26
- data/templates/aws_cur_template.json +0 -145
- data/templates/example_template.json +0 -54
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cure
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- william
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simplecov
|
@@ -24,45 +24,103 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: artii
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.1.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.1.2
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: faker
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - "
|
45
|
+
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
47
|
+
version: 3.2.2
|
34
48
|
type: :runtime
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - "
|
52
|
+
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
54
|
+
version: 3.2.2
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rcsv
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - "
|
59
|
+
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
61
|
+
version: 0.3.1
|
48
62
|
type: :runtime
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
|
-
- - "
|
66
|
+
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
68
|
+
version: 0.3.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sequel
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 5.74.0
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 5.74.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sqlite3
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.6.8
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.6.8
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: terminal-table
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.0.2
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 3.0.2
|
55
111
|
description: Transform, select, anonymize or manipulate data inside CSV files with
|
56
112
|
templates.
|
57
113
|
email:
|
58
114
|
- me@williamthom.as
|
59
115
|
executables:
|
60
116
|
- cure
|
117
|
+
- cure.old
|
61
118
|
extensions: []
|
62
119
|
extra_rdoc_files: []
|
63
120
|
files:
|
64
121
|
- ".rspec"
|
65
122
|
- ".rubocop.yml"
|
123
|
+
- ".tool-versions"
|
66
124
|
- CODE_OF_CONDUCT.md
|
67
125
|
- Dockerfile
|
68
126
|
- Gemfile
|
@@ -70,48 +128,101 @@ files:
|
|
70
128
|
- LICENSE.txt
|
71
129
|
- README.md
|
72
130
|
- Rakefile
|
131
|
+
- docs/README.md
|
132
|
+
- docs/about.md
|
133
|
+
- docs/builder/add.md
|
134
|
+
- docs/builder/black_white_list.md
|
135
|
+
- docs/builder/copy.md
|
136
|
+
- docs/builder/explode.md
|
137
|
+
- docs/builder/main.md
|
138
|
+
- docs/builder/remove.md
|
139
|
+
- docs/examples/examples.md
|
140
|
+
- docs/export/main.md
|
141
|
+
- docs/extract/main.md
|
142
|
+
- docs/metadata/main.md
|
143
|
+
- docs/query/main.md
|
144
|
+
- docs/sources/main.md
|
145
|
+
- docs/transform/main.md
|
146
|
+
- docs/validate/main.md
|
73
147
|
- exe/cure
|
148
|
+
- exe/cure.old
|
74
149
|
- lib/cure.rb
|
150
|
+
- lib/cure/builder/base_builder.rb
|
151
|
+
- lib/cure/builder/candidate.rb
|
152
|
+
- lib/cure/cli/command.rb
|
153
|
+
- lib/cure/cli/generate_command.rb
|
154
|
+
- lib/cure/cli/new_command.rb
|
155
|
+
- lib/cure/cli/run_command.rb
|
156
|
+
- lib/cure/cli/templates/README.md.erb
|
157
|
+
- lib/cure/cli/templates/gemfile.erb
|
158
|
+
- lib/cure/cli/templates/gitignore.erb
|
159
|
+
- lib/cure/cli/templates/new_template.rb.erb
|
160
|
+
- lib/cure/cli/templates/tool-versions.erb
|
75
161
|
- lib/cure/config.rb
|
76
162
|
- lib/cure/coordinator.rb
|
77
|
-
- lib/cure/
|
78
|
-
- lib/cure/
|
163
|
+
- lib/cure/database.rb
|
164
|
+
- lib/cure/dsl/builder.rb
|
165
|
+
- lib/cure/dsl/exporters.rb
|
166
|
+
- lib/cure/dsl/extraction.rb
|
167
|
+
- lib/cure/dsl/metadata.rb
|
168
|
+
- lib/cure/dsl/queries.rb
|
169
|
+
- lib/cure/dsl/source_files.rb
|
170
|
+
- lib/cure/dsl/template.rb
|
171
|
+
- lib/cure/dsl/transformations.rb
|
172
|
+
- lib/cure/dsl/validator.rb
|
173
|
+
- lib/cure/export/base_processor.rb
|
174
|
+
- lib/cure/export/manager.rb
|
175
|
+
- lib/cure/extract/base_processor.rb
|
79
176
|
- lib/cure/extract/csv_lookup.rb
|
80
177
|
- lib/cure/extract/extractor.rb
|
178
|
+
- lib/cure/extract/filter.rb
|
179
|
+
- lib/cure/extract/named_range.rb
|
180
|
+
- lib/cure/extract/named_range_processor.rb
|
181
|
+
- lib/cure/extract/variable.rb
|
182
|
+
- lib/cure/extract/variable_processor.rb
|
81
183
|
- lib/cure/generator/base_generator.rb
|
82
184
|
- lib/cure/generator/case_generator.rb
|
83
185
|
- lib/cure/generator/character_generator.rb
|
186
|
+
- lib/cure/generator/erb_generator.rb
|
187
|
+
- lib/cure/generator/eval_generator.rb
|
84
188
|
- lib/cure/generator/faker_generator.rb
|
85
189
|
- lib/cure/generator/guid_generator.rb
|
86
190
|
- lib/cure/generator/hex_generator.rb
|
87
191
|
- lib/cure/generator/imports.rb
|
88
192
|
- lib/cure/generator/number_generator.rb
|
89
193
|
- lib/cure/generator/placeholder_generator.rb
|
194
|
+
- lib/cure/generator/proc_generator.rb
|
90
195
|
- lib/cure/generator/redact_generator.rb
|
196
|
+
- lib/cure/generator/static_generator.rb
|
91
197
|
- lib/cure/generator/variable_generator.rb
|
92
198
|
- lib/cure/helpers/file_helpers.rb
|
93
199
|
- lib/cure/helpers/object_helpers.rb
|
200
|
+
- lib/cure/helpers/perf_helpers.rb
|
201
|
+
- lib/cure/helpers/string.rb
|
202
|
+
- lib/cure/launcher.rb
|
94
203
|
- lib/cure/log.rb
|
95
|
-
- lib/cure/
|
204
|
+
- lib/cure/planner.rb
|
96
205
|
- lib/cure/strategy/append_strategy.rb
|
97
206
|
- lib/cure/strategy/base_strategy.rb
|
207
|
+
- lib/cure/strategy/contain_strategy.rb
|
98
208
|
- lib/cure/strategy/end_with_strategy.rb
|
99
209
|
- lib/cure/strategy/full_strategy.rb
|
210
|
+
- lib/cure/strategy/history/history_cache.rb
|
100
211
|
- lib/cure/strategy/imports.rb
|
101
212
|
- lib/cure/strategy/match_strategy.rb
|
213
|
+
- lib/cure/strategy/prepend_strategy.rb
|
102
214
|
- lib/cure/strategy/regex_strategy.rb
|
103
215
|
- lib/cure/strategy/split_strategy.rb
|
104
216
|
- lib/cure/strategy/start_with_strategy.rb
|
105
|
-
- lib/cure/template/dispatch.rb
|
106
|
-
- lib/cure/template/extraction.rb
|
107
|
-
- lib/cure/template/template.rb
|
108
|
-
- lib/cure/template/transformations.rb
|
109
217
|
- lib/cure/transformation/candidate.rb
|
110
218
|
- lib/cure/transformation/transform.rb
|
219
|
+
- lib/cure/validator/base_rule.rb
|
220
|
+
- lib/cure/validator/candidate.rb
|
221
|
+
- lib/cure/validator/manager.rb
|
111
222
|
- lib/cure/validators.rb
|
112
223
|
- lib/cure/version.rb
|
113
|
-
- templates/
|
114
|
-
- templates/
|
224
|
+
- templates/dsl_example.rb
|
225
|
+
- templates/empty_template.rb
|
115
226
|
homepage: https://www.github.com/williamthom-as/cure
|
116
227
|
licenses:
|
117
228
|
- MIT
|
@@ -124,14 +235,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
235
|
requirements:
|
125
236
|
- - ">="
|
126
237
|
- !ruby/object:Gem::Version
|
127
|
-
version:
|
238
|
+
version: '3.1'
|
128
239
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
240
|
requirements:
|
130
241
|
- - ">="
|
131
242
|
- !ruby/object:Gem::Version
|
132
243
|
version: '0'
|
133
244
|
requirements: []
|
134
|
-
rubygems_version: 3.
|
245
|
+
rubygems_version: 3.4.6
|
135
246
|
signing_key:
|
136
247
|
specification_version: 4
|
137
248
|
summary: Cure provides the ability to transform CSVs using descriptive templates.
|
data/lib/cure/export/exporter.rb
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "cure/log"
|
4
|
-
require "cure/config"
|
5
|
-
require "cure/helpers/file_helpers"
|
6
|
-
|
7
|
-
module Cure
|
8
|
-
module Export
|
9
|
-
class Exporter
|
10
|
-
include Helpers::FileHelpers
|
11
|
-
include Configuration
|
12
|
-
include Log
|
13
|
-
|
14
|
-
# @param [Array<Cure::Transform::TransformResult>] result
|
15
|
-
def self.export_result(results, output_dir)
|
16
|
-
exporter = Exporter.new(output_dir)
|
17
|
-
exporter.export_results(results)
|
18
|
-
end
|
19
|
-
|
20
|
-
attr_reader :output_dir
|
21
|
-
|
22
|
-
def initialize(output_dir)
|
23
|
-
@output_dir = output_dir
|
24
|
-
end
|
25
|
-
|
26
|
-
# @param [Array<Cure::Transform::TransformResult>] result
|
27
|
-
def export_results(result)
|
28
|
-
export_ranges = config.template.dispatch.named_ranges
|
29
|
-
|
30
|
-
export_ranges.each do |range|
|
31
|
-
named_range = range["named_range"]
|
32
|
-
unless result.has_key?(named_range)
|
33
|
-
raise "Missing named range - #{range} from candidates [#{result.keys.join(", ")}]"
|
34
|
-
end
|
35
|
-
|
36
|
-
data = result[named_range]
|
37
|
-
column_headers = data.column_headers.keys
|
38
|
-
export(@output_dir, range["file_name"], data.transformed_rows, column_headers)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
# @param [Array] rows
|
43
|
-
# @param [Array] columns
|
44
|
-
def export(output_dir, file_name, rows, columns)
|
45
|
-
file_name = "#{file_name}-#{Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S%-z")}"
|
46
|
-
|
47
|
-
log_info("Exporting file to [#{output_dir}/#{file_name}] with #{rows.length} rows")
|
48
|
-
|
49
|
-
file_contents = []
|
50
|
-
file_contents << columns.join(",")
|
51
|
-
|
52
|
-
rows.each do |row|
|
53
|
-
file_contents << row.join(",")
|
54
|
-
end
|
55
|
-
|
56
|
-
write_to_file(
|
57
|
-
output_dir, file_name, "csv", file_contents.join("\n")
|
58
|
-
)
|
59
|
-
end
|
60
|
-
|
61
|
-
# @param [String] file_path
|
62
|
-
# @param [String] contents
|
63
|
-
# @param [String] file_extension
|
64
|
-
def write_to_file(file_path, file_name, file_extension, contents)
|
65
|
-
file_location = "#{file_path}/#{file_name}"
|
66
|
-
clean_dir(file_path)
|
67
|
-
|
68
|
-
with_file(file_location, file_extension) do |file|
|
69
|
-
file.write(contents)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
data/lib/cure/extract/builder.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "cure/extract/csv_lookup"
|
4
|
-
|
5
|
-
module Cure
|
6
|
-
module Extract
|
7
|
-
class Builder
|
8
|
-
|
9
|
-
# @param [Hash] opts
|
10
|
-
attr_reader :opts
|
11
|
-
|
12
|
-
# @param [Hash] opts
|
13
|
-
def initialize(opts)
|
14
|
-
@opts = opts
|
15
|
-
end
|
16
|
-
|
17
|
-
# @param [Array<Array>] _sheet
|
18
|
-
# @param [Hash<String, Integer>] _column_headers
|
19
|
-
# @return [Array]
|
20
|
-
#
|
21
|
-
# This returns changed column headers and sheets
|
22
|
-
def handle(_sheet, _column_headers)
|
23
|
-
[]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/lib/cure/main.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "cure/template/template"
|
4
|
-
require "cure/transformation/candidate"
|
5
|
-
require "cure/transformation/transform"
|
6
|
-
require "cure/export/exporter"
|
7
|
-
require "cure/coordinator"
|
8
|
-
|
9
|
-
require "cure"
|
10
|
-
require "json"
|
11
|
-
|
12
|
-
module Cure
|
13
|
-
class Main
|
14
|
-
include Configuration
|
15
|
-
include Helpers::FileHelpers
|
16
|
-
|
17
|
-
# @param [String] template_file_loc
|
18
|
-
# @param [String] csv_file_loc
|
19
|
-
# @param [String] output_dir
|
20
|
-
# @return [Cure::Main]
|
21
|
-
def self.init_from_file(template_file_loc, csv_file_loc, output_dir)
|
22
|
-
# Run all init stuff here.
|
23
|
-
# Run validator?
|
24
|
-
|
25
|
-
main = Main.new
|
26
|
-
template_hash = JSON.parse(main.read_file(template_file_loc))
|
27
|
-
template = Template.from_hash(template_hash)
|
28
|
-
main.setup(csv_file_loc, template, output_dir)
|
29
|
-
main
|
30
|
-
end
|
31
|
-
|
32
|
-
# @param [Hash] template_hash
|
33
|
-
# @param [String] csv_file_loc
|
34
|
-
# @param [String] output_dir
|
35
|
-
# @return [Cure::Main]
|
36
|
-
def self.init_from_hash(template_hash, csv_file_loc, output_dir)
|
37
|
-
# Run all init stuff here.
|
38
|
-
# Run validator?
|
39
|
-
|
40
|
-
main = Main.new
|
41
|
-
template = Template.from_hash(template_hash)
|
42
|
-
main.setup(csv_file_loc, template, output_dir)
|
43
|
-
main
|
44
|
-
end
|
45
|
-
|
46
|
-
# @return [Cure::Coordinator]
|
47
|
-
attr_accessor :coordinator
|
48
|
-
|
49
|
-
# @return [Boolean]
|
50
|
-
attr_reader :is_initialised
|
51
|
-
|
52
|
-
def initialize
|
53
|
-
@is_initialised = false
|
54
|
-
@coordinator = Coordinator.new
|
55
|
-
end
|
56
|
-
|
57
|
-
def run_export
|
58
|
-
@coordinator.process
|
59
|
-
end
|
60
|
-
|
61
|
-
# @param [String] csv_file_location
|
62
|
-
# @param [Cure::Template] template
|
63
|
-
# @param [String] output_dir
|
64
|
-
# @return [Cure::Main]
|
65
|
-
def setup(csv_file_location, template, output_dir)
|
66
|
-
config = create_config(csv_file_location, template, output_dir)
|
67
|
-
register_config(config)
|
68
|
-
|
69
|
-
self
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Cure
|
4
|
-
# This name sucks, it is just an exporter
|
5
|
-
class Dispatch
|
6
|
-
|
7
|
-
# @param [Array<Hash>] named_ranges
|
8
|
-
attr_accessor :named_ranges
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
@named_ranges = [default]
|
12
|
-
end
|
13
|
-
|
14
|
-
# @param [Array<String>] hash
|
15
|
-
# @return [Cure::Dispatch]
|
16
|
-
def self.from_hash(hash)
|
17
|
-
this = Cure::Dispatch.new
|
18
|
-
this.named_ranges = hash["sections"] if hash.key?("sections")
|
19
|
-
this
|
20
|
-
end
|
21
|
-
|
22
|
-
def default
|
23
|
-
{
|
24
|
-
"named_range" => "default",
|
25
|
-
"file_name" => "cure-export",
|
26
|
-
"type" => "csv"
|
27
|
-
}
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
@@ -1,38 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Cure
|
4
|
-
class Extraction
|
5
|
-
# @param [Array<Hash>] named_ranges
|
6
|
-
attr_accessor :named_ranges
|
7
|
-
|
8
|
-
# @param [Array<Hash>] named_ranges
|
9
|
-
attr_accessor :variables
|
10
|
-
|
11
|
-
def initialize
|
12
|
-
@named_ranges = [{
|
13
|
-
"name" => "default",
|
14
|
-
"section" => -1
|
15
|
-
}]
|
16
|
-
|
17
|
-
@variables = []
|
18
|
-
end
|
19
|
-
|
20
|
-
# @param [Hash] hash
|
21
|
-
# @return [Cure::Extraction]
|
22
|
-
def self.from_hash(hash)
|
23
|
-
this = Cure::Extraction.new
|
24
|
-
this.named_ranges.push(*hash["named_ranges"])
|
25
|
-
this.variables.push(*hash["variables"])
|
26
|
-
this
|
27
|
-
end
|
28
|
-
|
29
|
-
# We only need to get the named ranges where the candidates have specified
|
30
|
-
# interest in them.
|
31
|
-
#
|
32
|
-
# @param [Array] candidate_nrs
|
33
|
-
# @return [Array]
|
34
|
-
def required_named_ranges(candidate_nrs)
|
35
|
-
@named_ranges.select { |nr| candidate_nrs.include?(nr["name"]) }
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "cure/template/transformations"
|
4
|
-
require "cure/template/extraction"
|
5
|
-
require "cure/template/dispatch"
|
6
|
-
|
7
|
-
module Cure
|
8
|
-
class Template
|
9
|
-
# @param [Cure::Transformations] transformations
|
10
|
-
attr_accessor :transformations
|
11
|
-
|
12
|
-
# @param [Cure::Extraction] extraction
|
13
|
-
attr_accessor :extraction
|
14
|
-
|
15
|
-
# @param [Cure::Dispatch] dispatch
|
16
|
-
attr_accessor :dispatch
|
17
|
-
|
18
|
-
# @param [Hash] hash
|
19
|
-
# @return [Cure::Template]
|
20
|
-
def self.from_hash(hash)
|
21
|
-
this = Cure::Template.new
|
22
|
-
this.transformations = Cure::Transformations.from_hash(hash.fetch("transformations", {}))
|
23
|
-
this.extraction = Cure::Extraction.from_hash(hash.fetch("extraction", {}))
|
24
|
-
this.dispatch = Cure::Dispatch.from_hash(hash.fetch("dispatch", {}))
|
25
|
-
this
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Cure
|
4
|
-
class Transformations
|
5
|
-
# @param [Array<Transformation::Candidate>] candidates
|
6
|
-
attr_accessor :candidates
|
7
|
-
|
8
|
-
# @param [Array<Hash>] placeholders
|
9
|
-
# TODO: make class Placeholder
|
10
|
-
attr_accessor :placeholders
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
@candidates = []
|
14
|
-
@placeholders = {}
|
15
|
-
end
|
16
|
-
|
17
|
-
# @param [Hash] hash
|
18
|
-
# @return [Cure::Transformations]
|
19
|
-
def self.from_hash(hash)
|
20
|
-
this = Cure::Transformations.new
|
21
|
-
this.candidates = hash["candidates"].map { |c| Cure::Transformation::Candidate.new.from_json(c) }
|
22
|
-
this.placeholders = hash["placeholders"]
|
23
|
-
this
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,145 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"transformations" : {
|
3
|
-
"candidates" : [
|
4
|
-
{
|
5
|
-
"column" : "identity/LineItemId",
|
6
|
-
"translations" : [{
|
7
|
-
"strategy" : {
|
8
|
-
"name": "full",
|
9
|
-
"options" : {}
|
10
|
-
},
|
11
|
-
"generator" : {
|
12
|
-
"name" : "character",
|
13
|
-
"options" : {
|
14
|
-
"length" : 52,
|
15
|
-
"types" : [
|
16
|
-
"lowercase", "number"
|
17
|
-
]
|
18
|
-
}
|
19
|
-
}
|
20
|
-
}]
|
21
|
-
},
|
22
|
-
{
|
23
|
-
"column" : "bill/PayerAccountId",
|
24
|
-
"translations" : [{
|
25
|
-
"strategy" : {
|
26
|
-
"name": "full",
|
27
|
-
"options" : {}
|
28
|
-
},
|
29
|
-
"generator" : {
|
30
|
-
"name" : "placeholder",
|
31
|
-
"options" : {
|
32
|
-
"name" : "$account_number"
|
33
|
-
}
|
34
|
-
}
|
35
|
-
}]
|
36
|
-
},
|
37
|
-
{
|
38
|
-
"column" : "lineItem/UsageAccountId",
|
39
|
-
"translations" : [{
|
40
|
-
"strategy" : {
|
41
|
-
"name": "full",
|
42
|
-
"options" : {}
|
43
|
-
},
|
44
|
-
"generator" : {
|
45
|
-
"name" : "number",
|
46
|
-
"options" : {
|
47
|
-
"length" : 6
|
48
|
-
}
|
49
|
-
}
|
50
|
-
}]
|
51
|
-
},
|
52
|
-
{
|
53
|
-
"column" : "lineItem/ResourceId",
|
54
|
-
"translations" : [{
|
55
|
-
"strategy" : {
|
56
|
-
"name": "regex",
|
57
|
-
"options" : {
|
58
|
-
"regex_cg" : "^i-(.*)"
|
59
|
-
}
|
60
|
-
},
|
61
|
-
"generator" : {
|
62
|
-
"name" : "hex",
|
63
|
-
"options" : {
|
64
|
-
"length" : 10
|
65
|
-
}
|
66
|
-
}
|
67
|
-
},{
|
68
|
-
"strategy" : {
|
69
|
-
"name": "regex",
|
70
|
-
"options" : {
|
71
|
-
"regex_cg" : "^vol-(.*)"
|
72
|
-
}
|
73
|
-
},
|
74
|
-
"generator" : {
|
75
|
-
"name" : "hex",
|
76
|
-
"options" : {
|
77
|
-
"length" : 10
|
78
|
-
}
|
79
|
-
}
|
80
|
-
},{
|
81
|
-
"strategy" : {
|
82
|
-
"name": "split",
|
83
|
-
"options" : {
|
84
|
-
"token": ":",
|
85
|
-
"index": 4
|
86
|
-
}
|
87
|
-
},
|
88
|
-
"generator" : {
|
89
|
-
"name" : "placeholder",
|
90
|
-
"options" : {
|
91
|
-
"name" : "$account_number"
|
92
|
-
}
|
93
|
-
}
|
94
|
-
},{
|
95
|
-
"strategy" : {
|
96
|
-
"name": "split",
|
97
|
-
"options" : {
|
98
|
-
"token": ":",
|
99
|
-
"index": -1
|
100
|
-
}
|
101
|
-
},
|
102
|
-
"generator" : {
|
103
|
-
"name" : "faker",
|
104
|
-
"options" : {
|
105
|
-
"module" : "App",
|
106
|
-
"method" : "name"
|
107
|
-
}
|
108
|
-
}
|
109
|
-
}],
|
110
|
-
"no_match_translation" : {
|
111
|
-
"strategy" : {
|
112
|
-
"name": "full",
|
113
|
-
"options" : {}
|
114
|
-
},
|
115
|
-
"generator" : {
|
116
|
-
"name" : "hex",
|
117
|
-
"options" : {
|
118
|
-
"length" : 10,
|
119
|
-
"prefix" : "s3_bucket_"
|
120
|
-
}
|
121
|
-
}
|
122
|
-
}
|
123
|
-
},
|
124
|
-
{
|
125
|
-
"column" : "resourceTags/aws:createdBy",
|
126
|
-
"translations" : [{
|
127
|
-
"strategy" : {
|
128
|
-
"name": "full",
|
129
|
-
"options" : {}
|
130
|
-
},
|
131
|
-
"generator" : {
|
132
|
-
"name" : "faker",
|
133
|
-
"options" : {
|
134
|
-
"module" : "Faker::Movies::StarWars",
|
135
|
-
"method" : "character"
|
136
|
-
}
|
137
|
-
}
|
138
|
-
}]
|
139
|
-
}
|
140
|
-
],
|
141
|
-
"placeholders" : {
|
142
|
-
"$account_number" : "1234567891234"
|
143
|
-
}
|
144
|
-
}
|
145
|
-
}
|