truss_parser 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +11 -22
- data/exe/truss_parser +0 -0
- data/lib/truss_parser/parser.rb +8 -6
- data/lib/truss_parser/version.rb +1 -1
- data/normalized_data.csv +7 -0
- data/normalized_test_data.csv +7 -0
- data/scrubbed-sample.csv +8 -0
- data/truss_parser.gif +0 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 741e1cd26ecbea24962cdfa6a33f3648dd2a8ed0
|
4
|
+
data.tar.gz: 6af6e69c443d8fd61ef88fecc728a5ee68514cfb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7469ccf2351cebf6115b6089977cfc65e676470902b805549da4345ed09a5d1331585bb38e60d75fde9060b85c37cd6523c118378176f94177e25b05427d729
|
7
|
+
data.tar.gz: ff273c22994c7d99029422979a2a76d80b259f9e9c91d1fbd6e96a7821d6fa957e835fd5c127d6c85a5d2884710bc9db493fa702a1ae46df16d89131c7a538f4
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,38 +1,27 @@
|
|
1
|
-
#
|
1
|
+
# Truss 🚀
|
2
2
|
|
3
|
-
Welcome to
|
3
|
+
Welcome to TrussParser! This is a gem that parses and normalizes CSV data according to the specs in `challenge.md`
|
4
4
|
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
```ruby
|
12
|
-
gem 'truss_parser'
|
13
|
-
```
|
14
|
-
|
15
|
-
And then execute:
|
16
|
-
|
17
|
-
$ bundle
|
18
|
-
|
19
|
-
Or install it yourself as:
|
8
|
+
Assuming you have an environment set up for the Ruby ecosystem:
|
20
9
|
|
21
10
|
$ gem install truss_parser
|
22
11
|
|
23
12
|
## Usage
|
24
13
|
|
25
|
-
|
26
|
-
|
27
|
-
|
14
|
+
- After `gem install`ing the `truss` gem:
|
15
|
+
- Run `truss_parser sample.csv` to parse and normalize the `sample.csv` that is shipped along in this gem. Alternatively, you can also run `truss_parser sample-with-broken-utf8.csv` as well. The Truss takes in a CSV file as an argument, and outputs normalized CSV data in `normalized_data.csv`.
|
16
|
+
- Example:
|
28
17
|
|
29
|
-
|
18
|
+
![Example of gem usage](truss_parser.gif)
|
30
19
|
|
31
|
-
|
20
|
+
## Testing
|
32
21
|
|
33
|
-
|
22
|
+
- Run `rake spec` to run the RSpec tests.
|
23
|
+
- You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
34
24
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/truss_parser. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
25
|
|
37
26
|
## License
|
38
27
|
|
@@ -40,4 +29,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
40
29
|
|
41
30
|
## Code of Conduct
|
42
31
|
|
43
|
-
Everyone interacting in the
|
32
|
+
Everyone interacting in the Truss project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/arbonap/truss_parser/blob/master/CODE_OF_CONDUCT.md).
|
data/exe/truss_parser
CHANGED
File without changes
|
data/lib/truss_parser/parser.rb
CHANGED
@@ -4,10 +4,12 @@ require 'active_support/time_with_zone'
|
|
4
4
|
|
5
5
|
module Parser
|
6
6
|
class Normalization
|
7
|
-
attr_accessor :csv_file
|
7
|
+
attr_accessor :csv_file, :scrubbed_csv, :normalized_data
|
8
8
|
|
9
|
-
def initialize(argv)
|
9
|
+
def initialize(argv, normalized_data="normalized_data.csv", scrubbed_csv="scrubbed-sample.csv")
|
10
10
|
@csv_file = argv[0]
|
11
|
+
@normalized_data = normalized_data
|
12
|
+
@scrubbed_csv = scrubbed_csv
|
11
13
|
end
|
12
14
|
|
13
15
|
def self.ascii
|
@@ -43,7 +45,7 @@ module Parser
|
|
43
45
|
end
|
44
46
|
|
45
47
|
def normalize
|
46
|
-
CSV.foreach("
|
48
|
+
CSV.foreach("#{scrubbed_csv}", headers: true, encoding: "utf-8") do |row|
|
47
49
|
# convert PST to EST && format timestamps in iso8601
|
48
50
|
update_timezone(row, 'Pacific Time (US & Canada)', 'Eastern Time (US & Canada)')
|
49
51
|
|
@@ -63,15 +65,15 @@ module Parser
|
|
63
65
|
|
64
66
|
unicode_notes_validation(row['notes'])
|
65
67
|
|
66
|
-
CSV.open(
|
68
|
+
CSV.open("#{normalized_data}", 'a') do |csv|
|
67
69
|
csv << row.fields
|
68
70
|
end
|
69
71
|
end
|
70
|
-
File.open(
|
72
|
+
File.open("#{normalized_data}").map { |row| puts row if ENV['GEM_ENV'] != 'TEST' }
|
71
73
|
end
|
72
74
|
|
73
75
|
def truncate
|
74
|
-
File.truncate(
|
76
|
+
File.truncate("#{normalized_data}", 0)
|
75
77
|
end
|
76
78
|
|
77
79
|
def generate_scrubbed_csv(arrays)
|
data/lib/truss_parser/version.rb
CHANGED
data/normalized_data.csv
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
2011-04-01T07:00:00-04:00,"123 4th St, Anywhere, AA",94121,MONKEY ALBERTO,1:23:32.123,1:32:33.123,10565.246,I am the very model of a modern major general
|
2
|
+
2010-12-31T19:00:01-05:00,"This Is Not An Address, BusyTown, BT",94121,MARY 1,1:23:32.123,0:00:00.000,5012.123,I like Emoji! 🍏🍎😍
|
3
|
+
2016-12-31T18:59:59-05:00,"123 Gangnam Style Lives Here, Gangnam Town",31403,ANTICIPATION OF UNICODE FAILURE,1:23:32.123,1:32:33.123,10565.246,I like Math Symbols! ≱≰⨌⊚
|
4
|
+
2011-11-11T06:11:11-05:00,überTown,10001,PROMPT NEGOTIATOR,1:23:32.123,1:32:33.123,10565.246,"I’m just gonna say, this is AMAZING. WHAT NEGOTIATIONS."
|
5
|
+
2010-05-12T12:48:12-04:00,Høøük¡,01231,SLEEPER SERVICE,1:23:32.123,1:32:33.123,10565.246,2/1/22
|
6
|
+
2012-10-05T18:31:11-04:00,"Test Pattern Town, Test Pattern, TP",00121,株式会社スタジオジブリ,1:23:32.123,1:32:33.123,10565.246,1:11:11.123
|
7
|
+
2004-10-02T04:44:11-04:00,The Moon,00011,HERE WE GO,1:23:32.123,1:32:33.123,10565.246,
|
@@ -0,0 +1,7 @@
|
|
1
|
+
2011-04-01T07:00:00-04:00,"123 4th St, Anywhere, AA",94121,MONKEY ALBERTO,1:23:32.123,1:32:33.123,10565.246,I am the very model of a modern major general
|
2
|
+
2010-12-31T19:00:01-05:00,"This Is Not An Address, BusyTown, BT",94121,MARY 1,1:23:32.123,0:00:00.000,5012.123,I like Emoji! 🍏🍎😍
|
3
|
+
2016-12-31T18:59:59-05:00,"123 Gangnam Style Lives Here, Gangnam Town",31403,ANTICIPATION OF UNICODE FAILURE,1:23:32.123,1:32:33.123,10565.246,I like Math Symbols! ≱≰⨌⊚
|
4
|
+
2011-11-11T06:11:11-05:00,überTown,10001,PROMPT NEGOTIATOR,1:23:32.123,1:32:33.123,10565.246,"I’m just gonna say, this is AMAZING. WHAT NEGOTIATIONS."
|
5
|
+
2010-05-12T12:48:12-04:00,Høøük¡,01231,SLEEPER SERVICE,1:23:32.123,1:32:33.123,10565.246,2/1/22
|
6
|
+
2012-10-05T18:31:11-04:00,"Test Pattern Town, Test Pattern, TP",00121,株式会社スタジオジブリ,1:23:32.123,1:32:33.123,10565.246,1:11:11.123
|
7
|
+
2004-10-02T04:44:11-04:00,The Moon,00011,HERE WE GO,1:23:32.123,1:32:33.123,10565.246,
|
data/scrubbed-sample.csv
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
timestamp,address,zip,fullname,fooduration,barduration,totalduration,notes
|
2
|
+
4/1/11 11:00:00 AM,"123 4th St, Anywhere, AA",94121,Monkey Alberto,1:23:32.123,1:32:33.123,zzsasdfa,I am the very model of a modern major general
|
3
|
+
1/1/11 12:00:01 AM,"This Is Not An Address, BusyTown, BT",94121,Mary 1,1:23:32.123,0:00:00.000,zzsasdfa,I like Emoji! 🍏🍎😍
|
4
|
+
12/31/16 11:59:59 PM,"123 Gangnam Style Lives Here, Gangnam Town",31403,Anticipation of Unicode Failure,1:23:32.123,1:32:33.123,zzsasdfa,I like Math Symbols! ≱≰⨌⊚
|
5
|
+
11/11/11 11:11:11 AM,überTown,10001,Prompt Negotiator,1:23:32.123,1:32:33.123,zzsasdfa,"I’m just gonna say, this is AMAZING. WHAT NEGOTIATIONS."
|
6
|
+
5/12/10 4:48:12 PM,Høøük¡,1231,Sleeper Service,1:23:32.123,1:32:33.123,zzsasdfa,2/1/22
|
7
|
+
10/5/12 10:31:11 PM,"Test Pattern Town, Test Pattern, TP",121,株式会社スタジオジブリ,1:23:32.123,1:32:33.123,zzsasdfa,1:11:11.123
|
8
|
+
10/2/04 8:44:11 AM,The Moon,11,HERE WE GO,1:23:32.123,1:32:33.123,zzsasdfa,
|
data/truss_parser.gif
ADDED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: truss_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patricia Arbona
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -133,9 +133,13 @@ files:
|
|
133
133
|
- lib/truss_parser/cli.rb
|
134
134
|
- lib/truss_parser/parser.rb
|
135
135
|
- lib/truss_parser/version.rb
|
136
|
+
- normalized_data.csv
|
137
|
+
- normalized_test_data.csv
|
136
138
|
- sample-with-broken-utf8.csv
|
137
139
|
- sample.csv
|
140
|
+
- scrubbed-sample.csv
|
138
141
|
- truss_parser.gemspec
|
142
|
+
- truss_parser.gif
|
139
143
|
homepage: https://www.github.com/arbonap/truss
|
140
144
|
licenses:
|
141
145
|
- MIT
|