importa 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rspec_status +23 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +80 -0
- data/README.md +57 -0
- data/Rakefile +10 -0
- data/lib/importa/base_transformer.rb +125 -0
- data/lib/importa/reporter.rb +43 -0
- data/lib/importa/version.rb +5 -0
- data/lib/importa.rb +9 -0
- data/sig/importa.rbs +4 -0
- data/transformer.rb +11 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b3c91e5123454af31705c6130b535c540f8b46c998d337807bcfb2cee79364b5
|
4
|
+
data.tar.gz: a30112f5dfcfa0cc688a27aced4773788e9a30f69d3047adfe781c6674ba7db5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7c52443795e423c66ba87ba9eba2675a36aac6c0b9d4644cb45fc77f4c8ee11b8744e05804a42519317973e4d30d333dee158797c300c1721622e1214ff666b5
|
7
|
+
data.tar.gz: b584161e0a46d42b8ebc60cd9d1e5b8027ddd625897549915847500bf04d529e1f002a0c81141b74020a52d11051b08b4f126a21c3826b7909215a74b932155b
|
data/.rspec
ADDED
data/.rspec_status
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
example_id | status | run_time |
|
2
|
+
------------------------------ | ------ | --------------- |
|
3
|
+
./spec/importa_spec.rb[1:1] | passed | 0.00044 seconds |
|
4
|
+
./spec/importa_spec.rb[1:2] | passed | 0.00041 seconds |
|
5
|
+
./spec/importa_spec.rb[1:3] | passed | 0.00016 seconds |
|
6
|
+
./spec/importa_spec.rb[1:4] | passed | 0.00003 seconds |
|
7
|
+
./spec/importa_spec.rb[1:5] | passed | 0.00166 seconds |
|
8
|
+
./spec/importa_spec.rb[1:6] | passed | 0.00005 seconds |
|
9
|
+
./spec/importa_spec.rb[1:7] | passed | 0.00047 seconds |
|
10
|
+
./spec/importa_spec.rb[1:8] | passed | 0.00027 seconds |
|
11
|
+
./spec/importa_spec.rb[1:9] | passed | 0.00069 seconds |
|
12
|
+
./spec/importa_spec.rb[1:10:1] | passed | 0.00042 seconds |
|
13
|
+
./spec/importa_spec.rb[1:10:2] | passed | 0.00003 seconds |
|
14
|
+
./spec/importa_spec.rb[1:10:3] | passed | 0.00003 seconds |
|
15
|
+
./spec/importa_spec.rb[1:10:4] | passed | 0.00002 seconds |
|
16
|
+
./spec/importa_spec.rb[1:11:1] | passed | 0.00003 seconds |
|
17
|
+
./spec/importa_spec.rb[1:11:2] | passed | 0.00002 seconds |
|
18
|
+
./spec/importa_spec.rb[1:11:3] | passed | 0.00039 seconds |
|
19
|
+
./spec/importa_spec.rb[1:11:4] | passed | 0.00003 seconds |
|
20
|
+
./spec/importa_spec.rb[1:11:5] | passed | 0.00012 seconds |
|
21
|
+
./spec/importa_spec.rb[1:11:6] | passed | 0.00004 seconds |
|
22
|
+
./spec/importa_spec.rb[1:11:7] | passed | 0.00044 seconds |
|
23
|
+
./spec/importa_spec.rb[1:11:8] | passed | 0.00002 seconds |
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.8
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at double.emms@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
importa (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.2)
|
10
|
+
base64 (0.1.1)
|
11
|
+
diff-lcs (1.5.0)
|
12
|
+
json (2.6.3)
|
13
|
+
language_server-protocol (3.17.0.3)
|
14
|
+
lint_roller (1.1.0)
|
15
|
+
parallel (1.23.0)
|
16
|
+
parser (3.2.2.4)
|
17
|
+
ast (~> 2.4.1)
|
18
|
+
racc
|
19
|
+
racc (1.7.1)
|
20
|
+
rainbow (3.1.1)
|
21
|
+
rake (13.0.6)
|
22
|
+
regexp_parser (2.8.2)
|
23
|
+
rexml (3.2.6)
|
24
|
+
rspec (3.12.0)
|
25
|
+
rspec-core (~> 3.12.0)
|
26
|
+
rspec-expectations (~> 3.12.0)
|
27
|
+
rspec-mocks (~> 3.12.0)
|
28
|
+
rspec-core (3.12.2)
|
29
|
+
rspec-support (~> 3.12.0)
|
30
|
+
rspec-expectations (3.12.3)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.12.0)
|
33
|
+
rspec-mocks (3.12.6)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.12.0)
|
36
|
+
rspec-support (3.12.1)
|
37
|
+
rubocop (1.56.4)
|
38
|
+
base64 (~> 0.1.1)
|
39
|
+
json (~> 2.3)
|
40
|
+
language_server-protocol (>= 3.17.0)
|
41
|
+
parallel (~> 1.10)
|
42
|
+
parser (>= 3.2.2.3)
|
43
|
+
rainbow (>= 2.2.2, < 4.0)
|
44
|
+
regexp_parser (>= 1.8, < 3.0)
|
45
|
+
rexml (>= 3.2.5, < 4.0)
|
46
|
+
rubocop-ast (>= 1.28.1, < 2.0)
|
47
|
+
ruby-progressbar (~> 1.7)
|
48
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
49
|
+
rubocop-ast (1.29.0)
|
50
|
+
parser (>= 3.2.1.0)
|
51
|
+
rubocop-performance (1.19.1)
|
52
|
+
rubocop (>= 1.7.0, < 2.0)
|
53
|
+
rubocop-ast (>= 0.4.0)
|
54
|
+
ruby-progressbar (1.13.0)
|
55
|
+
standard (1.31.2)
|
56
|
+
language_server-protocol (~> 3.17.0.2)
|
57
|
+
lint_roller (~> 1.0)
|
58
|
+
rubocop (~> 1.56.4)
|
59
|
+
standard-custom (~> 1.0.0)
|
60
|
+
standard-performance (~> 1.2)
|
61
|
+
standard-custom (1.0.2)
|
62
|
+
lint_roller (~> 1.0)
|
63
|
+
rubocop (~> 1.50)
|
64
|
+
standard-performance (1.2.1)
|
65
|
+
lint_roller (~> 1.1)
|
66
|
+
rubocop-performance (~> 1.19.1)
|
67
|
+
unicode-display_width (2.5.0)
|
68
|
+
|
69
|
+
PLATFORMS
|
70
|
+
arm64-darwin-21
|
71
|
+
arm64-darwin-22
|
72
|
+
|
73
|
+
DEPENDENCIES
|
74
|
+
importa!
|
75
|
+
rake (~> 13.0)
|
76
|
+
rspec (~> 3.2)
|
77
|
+
standard (~> 1.3)
|
78
|
+
|
79
|
+
BUNDLED WITH
|
80
|
+
2.4.19
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Importa
|
2
|
+
|
3
|
+
A flexible toolkit for importing, transforming, and validating data from external sources.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
8
|
+
|
9
|
+
$ bundle add importa
|
10
|
+
|
11
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
12
|
+
|
13
|
+
$ gem install importa
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
require 'importa'
|
19
|
+
require 'csv'
|
20
|
+
|
21
|
+
class ClientTransformer < Importa::BaseTransformer
|
22
|
+
field :first_name
|
23
|
+
field :last_name
|
24
|
+
field :email do |value|
|
25
|
+
value.downcase if value.match?(/\A[^@]+@[^@]+\z/)
|
26
|
+
end
|
27
|
+
field :phone_number, :phone
|
28
|
+
field :date_of_birth, :date, optional: true
|
29
|
+
end
|
30
|
+
|
31
|
+
input = CSV.read('clients.csv', headers: true)
|
32
|
+
output = ClientTransformer.transform_batch(input)
|
33
|
+
|
34
|
+
CSV.open('clients-transformed.csv', 'w', headers: output.headers, write_headers: true) do |csv|
|
35
|
+
output.each do |row|
|
36
|
+
csv << row
|
37
|
+
end
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
## Development
|
42
|
+
|
43
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
44
|
+
|
45
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/matt-morris/importa. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/matt-morris/importa/blob/main/CODE_OF_CONDUCT.md).
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
54
|
+
|
55
|
+
## Code of Conduct
|
56
|
+
|
57
|
+
Everyone interacting in the Importa project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/matt-morris/importa/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Importa
|
4
|
+
class BaseTransformer
|
5
|
+
attr_reader :input, :output, :errors
|
6
|
+
attr_accessor :reporter
|
7
|
+
@field_names = []
|
8
|
+
@formatters = {}
|
9
|
+
|
10
|
+
FORMATTERS = {
|
11
|
+
raw: ->(value) { value },
|
12
|
+
string: ->(value) { value.to_s.strip },
|
13
|
+
date: ->(value) {
|
14
|
+
[
|
15
|
+
["%m-%d-%y", /^\d{1,2}-\d{1,2}-\d{2}$/], # 1-11-88
|
16
|
+
["%m/%d/%y", /^\d{1,2}\/\d{1,2}\/\d{2}$/], # 01/11/88
|
17
|
+
["%m-%d-%Y", /^\d{1,2}-\d{1,2}-\d{4}$/], # 01-11-1988
|
18
|
+
["%m/%d/%Y", /^\d{1,2}\/\d{1,2}\/\d{4}$/], # 01/11/1988
|
19
|
+
["%m-%d-%y", /^\d{1,2}-\d{1,2}-\d{4}$/], # 01-11-1988
|
20
|
+
["%m/%d/%y", /^\d{1,2}\/\d{1,2}\/\d{2}$/], # 01/11/88
|
21
|
+
["%d-%m-%y", /^\d{1,2}-\d{1,2}-\d{2}$/], # 11-01-88
|
22
|
+
["%d/%m/%y", /^\d{1,2}\/\d{1,2}\/\d{2}$/], # 11/01/88
|
23
|
+
["%d-%m-%Y", /^\d{1,2}-\d{1,2}-\d{4}$/], # 11-01-1988
|
24
|
+
["%d/%m/%Y", /^\d{1,2}\/\d{1,2}\/\d{4}$/], # 11/01/1988
|
25
|
+
["%Y-%m-%d", /^\d{4}-\d{2}-\d{2}$/], # 1988-01-11
|
26
|
+
["%d-%m-%Y", /^\d{1,2}-\d{1,2}-\d{4}$/], # 11-01-1988
|
27
|
+
["%Y/%m/%d", /^\d{4}\/\d{2}\/\d{2}$/], # 1988/01/11
|
28
|
+
["%d/%m/%Y", /^\d{1,2}\/\d{1,2}\/\d{4}$/], # 11/01/1988
|
29
|
+
["%B %d, %Y", /^[A-Za-z]+ \d{1,2}, \d{4}$/], # January 11, 1988
|
30
|
+
["%b %d, %Y", /^[A-Za-z]{3} \d{1,2}, \d{4}$/], # Jan 11, 1988
|
31
|
+
["%d %B, %Y", /^\d{1,2} [A-Za-z]+, \d{4}$/], # 11 January, 1988
|
32
|
+
["%d %b, %Y", /^\d{1,2} [A-Za-z]{3}, \d{4}$/] # 11 Jan, 1988
|
33
|
+
].each do |format, regex|
|
34
|
+
next unless value.to_s.match?(regex)
|
35
|
+
return Date.strptime(value.to_s, format).iso8601
|
36
|
+
rescue ArgumentError
|
37
|
+
next
|
38
|
+
rescue
|
39
|
+
nil
|
40
|
+
end
|
41
|
+
nil
|
42
|
+
},
|
43
|
+
phone: ->(value) {
|
44
|
+
cleaned_value = value.to_s.gsub(/\D/, "").sub(/^1/, "")
|
45
|
+
(cleaned_value.length == 10) ? "+1#{cleaned_value}" : nil
|
46
|
+
},
|
47
|
+
|
48
|
+
# other types aren't necessary for the exercise, but easy and useful
|
49
|
+
integer: ->(value) { value.to_i },
|
50
|
+
float: ->(value) { value.to_f },
|
51
|
+
boolean: ->(value) { value == "true" }
|
52
|
+
}
|
53
|
+
|
54
|
+
# we want to make sure that subclasses have their own copies of these
|
55
|
+
def self.inherited(subclass)
|
56
|
+
subclass.instance_variable_set(:@field_names, [])
|
57
|
+
subclass.instance_variable_set(:@formatters, FORMATTERS.dup)
|
58
|
+
end
|
59
|
+
|
60
|
+
class << self
|
61
|
+
attr_reader :field_names, :formatters
|
62
|
+
|
63
|
+
# this is where the magic happens:
|
64
|
+
# importers define a mapping using the `field` DSL
|
65
|
+
# - optionally provide a formatter type (defaults to :string, as that's the most common)
|
66
|
+
# - providing a block will allow you to do custom formatting or quick one-offs
|
67
|
+
# - optional: true will allow the field to be nil or empty
|
68
|
+
def field(name, type = :string, optional: false, &block)
|
69
|
+
@field_names.push(name)
|
70
|
+
formatter = @formatters[type]
|
71
|
+
define_method("field_#{name}") do
|
72
|
+
value = input[name.to_s]
|
73
|
+
value = formatter.call(value)
|
74
|
+
value = instance_exec(value, &block) if block
|
75
|
+
@errors.push([name, "is required"]) if !optional && (value.nil? || value.empty?)
|
76
|
+
value
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def formatter(name, formatter_lambda = nil, &block)
|
81
|
+
@formatters[name] = formatter_lambda || block
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def initialize(input, row_number = nil)
|
86
|
+
@input = input
|
87
|
+
@row_number = row_number
|
88
|
+
@errors = []
|
89
|
+
@run_at = nil
|
90
|
+
end
|
91
|
+
|
92
|
+
def [](name)
|
93
|
+
send("field_#{name}")
|
94
|
+
end
|
95
|
+
|
96
|
+
def valid?
|
97
|
+
transform unless @run_at
|
98
|
+
@errors.empty?
|
99
|
+
end
|
100
|
+
|
101
|
+
def transform
|
102
|
+
@errors = []
|
103
|
+
@run_at = Time.now
|
104
|
+
results = self.class.field_names.map do |name|
|
105
|
+
send("field_#{name}")
|
106
|
+
end
|
107
|
+
valid? ? reporter&.record_transformed : reporter&.record_invalid(@row_number, @errors)
|
108
|
+
|
109
|
+
results
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.transform_batch(input, reporter = nil)
|
113
|
+
reporter ||= Reporter.new
|
114
|
+
results = []
|
115
|
+
input.each.with_index do |row, index|
|
116
|
+
t = new(row, index)
|
117
|
+
t.reporter = reporter
|
118
|
+
row = t.transform
|
119
|
+
results.push(row) if t.valid?
|
120
|
+
end
|
121
|
+
reporter.report
|
122
|
+
results
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Importa
|
4
|
+
class Reporter
|
5
|
+
attr_reader :transformed_records, :invalid_records
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@start_time = Time.now
|
9
|
+
@transformed_records = 0
|
10
|
+
@invalid_records = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def record_transformed
|
14
|
+
@transformed_records += 1
|
15
|
+
end
|
16
|
+
|
17
|
+
def record_invalid(row_number, errors)
|
18
|
+
@invalid_records << {row: row_number, errors: errors}
|
19
|
+
end
|
20
|
+
|
21
|
+
def report
|
22
|
+
total_records = @transformed_records + @invalid_records.count
|
23
|
+
|
24
|
+
File.write("report.txt", [
|
25
|
+
"Importa report:",
|
26
|
+
"---------------",
|
27
|
+
"Started at: #{@start_time}",
|
28
|
+
"Finished at: #{Time.now}",
|
29
|
+
"Duration: #{Time.now - @start_time} seconds",
|
30
|
+
"Total records: #{total_records}",
|
31
|
+
"Transformed records: #{@transformed_records}",
|
32
|
+
"Invalid records: #{@invalid_records.count}",
|
33
|
+
"Errors:",
|
34
|
+
@invalid_records.map do |record|
|
35
|
+
["Row #{record[:row]}, Errors: #{record[:errors].count}",
|
36
|
+
record[:errors].map do |error|
|
37
|
+
"- #{error[0]} #{error[1]}"
|
38
|
+
end]
|
39
|
+
end
|
40
|
+
].flatten.join("\n"))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/importa.rb
ADDED
data/sig/importa.rbs
ADDED
data/transformer.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require_relative "lib/importa"
|
2
|
+
|
3
|
+
class Transformer < Importa::BaseTransformer
|
4
|
+
field :first_name
|
5
|
+
field :last_name
|
6
|
+
field :dob, :date
|
7
|
+
field :member_id
|
8
|
+
field :effective_date, :date
|
9
|
+
field :expiry_date, :date, optional: true
|
10
|
+
field :phone_number, :phone, optional: true
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: importa
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Morris
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-10-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
description: Importa provides an adaptable base with a developer-friendly DSL for
|
28
|
+
quickly building data transformation tools.
|
29
|
+
email:
|
30
|
+
- double.emms@gmail.com
|
31
|
+
executables: []
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".rspec"
|
36
|
+
- ".rspec_status"
|
37
|
+
- ".ruby-version"
|
38
|
+
- CHANGELOG.md
|
39
|
+
- CODE_OF_CONDUCT.md
|
40
|
+
- Gemfile
|
41
|
+
- Gemfile.lock
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- lib/importa.rb
|
45
|
+
- lib/importa/base_transformer.rb
|
46
|
+
- lib/importa/reporter.rb
|
47
|
+
- lib/importa/version.rb
|
48
|
+
- sig/importa.rbs
|
49
|
+
- transformer.rb
|
50
|
+
homepage: https://github.com/matt-morris/importa
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata:
|
54
|
+
homepage_uri: https://github.com/matt-morris/importa
|
55
|
+
source_code_uri: https://github.com/matt-morris/importa
|
56
|
+
changelog_uri: https://github.com/matt-morris/importa/blob/main/CHANGELOG.md
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 2.6.0
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubygems_version: 3.1.6
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: a toolkit to import and transform csv files in ruby
|
76
|
+
test_files: []
|