flat_file 0.1.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 +7 -0
- data/.editorconfig +22 -0
- data/.gitignore +8 -0
- data/.rubocop.yml +217 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +58 -0
- data/LICENSE.txt +21 -0
- data/README.md +23 -0
- data/Rakefile +10 -0
- data/bin/console +7 -0
- data/bin/setup +8 -0
- data/flat_file.gemspec +37 -0
- data/lib/flat_file.rb +8 -0
- data/lib/flat_file/csv.rb +52 -0
- data/lib/flat_file/json.rb +19 -0
- data/lib/flat_file/qsv.rb +61 -0
- data/lib/flat_file/tsv.rb +21 -0
- data/lib/flat_file/version.rb +3 -0
- metadata +164 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d2ed36f67ce4b2e4dd652083303c3334c25fb75b38bac58556db7dcc35bae5ce
|
4
|
+
data.tar.gz: decdc753ea4c124ea579e712ade96264fe5cfe11d4d13d1e1b262bac60d794a1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4d0945ef8d97a589b7b8dbb246f9d5e216f3ae430e9789818f7bcd7dd3e11768b59a43658b208f05adcef7066bcb22613b867bda9b3ee4eb35c7c68bc0804347
|
7
|
+
data.tar.gz: 3ce275f2214d7395cfe716793be28870a2aa081bc92f6002cc615079e520ddd81e992984a0c3d2fda900835468744572c3d14035d6024202bcfbf7a508bd759a
|
data/.editorconfig
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# ╔═╗╔╦╗╦╔╦╗╔═╗╦═╗┌─┐┌─┐┌┐┌┌─┐┬┌─┐
|
2
|
+
# ║╣ ║║║ ║ ║ ║╠╦╝│ │ ││││├┤ ││ ┬
|
3
|
+
# o╚═╝═╩╝╩ ╩ ╚═╝╩╚═└─┘└─┘┘└┘└ ┴└─┘
|
4
|
+
#
|
5
|
+
# http://editorconfig.org/
|
6
|
+
root = true
|
7
|
+
|
8
|
+
[*]
|
9
|
+
charset = utf-8
|
10
|
+
end_of_line = lf
|
11
|
+
indent_size = 2
|
12
|
+
indent_style = space
|
13
|
+
insert_final_newline = true
|
14
|
+
max_line_length = 255
|
15
|
+
trim_trailing_whitespace = true
|
16
|
+
|
17
|
+
[*.{md,csv,tsv}]
|
18
|
+
trim_trailing_whitespace = false
|
19
|
+
insert_final_newline = false
|
20
|
+
|
21
|
+
[*.tsv]
|
22
|
+
indent_style = tab
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.5.0
|
3
|
+
|
4
|
+
Style/SingleLineMethods:
|
5
|
+
Exclude:
|
6
|
+
- 'test/**/*.rb'
|
7
|
+
|
8
|
+
# Don't leave calls to pry lying around.
|
9
|
+
Lint/Debugger:
|
10
|
+
Enabled: true
|
11
|
+
|
12
|
+
# ==============================================================================
|
13
|
+
# Documentation
|
14
|
+
# ==============================================================================
|
15
|
+
|
16
|
+
Style/Documentation:
|
17
|
+
Enabled: true
|
18
|
+
Exclude:
|
19
|
+
- 'test/**/*.rb'
|
20
|
+
|
21
|
+
Style/DocumentationMethod:
|
22
|
+
Enabled: true
|
23
|
+
Exclude:
|
24
|
+
- 'test/**/*.rb'
|
25
|
+
|
26
|
+
# ==============================================================================
|
27
|
+
# Naming
|
28
|
+
# ==============================================================================
|
29
|
+
|
30
|
+
Naming/MethodName:
|
31
|
+
Enabled: true
|
32
|
+
|
33
|
+
Naming/ClassAndModuleCamelCase:
|
34
|
+
Enabled: true
|
35
|
+
|
36
|
+
# ==============================================================================
|
37
|
+
# Layout
|
38
|
+
# ==============================================================================
|
39
|
+
|
40
|
+
Metrics/LineLength:
|
41
|
+
Max: 150
|
42
|
+
|
43
|
+
Layout/EmptyLineAfterGuardClause:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Layout/EmptyLinesAroundModuleBody:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Layout/EmptyLinesAroundClassBody:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
Layout/EmptyLinesAroundBlockBody:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
# https://unix.stackexchange.com/a/18789
|
56
|
+
Layout/TrailingEmptyLines:
|
57
|
+
EnforcedStyle: final_newline
|
58
|
+
|
59
|
+
# ==============================================================================
|
60
|
+
# Strings
|
61
|
+
# ==============================================================================
|
62
|
+
|
63
|
+
Style/StringLiterals:
|
64
|
+
EnforcedStyle: double_quotes
|
65
|
+
|
66
|
+
Style/FrozenStringLiteralComment:
|
67
|
+
Enabled: false
|
68
|
+
|
69
|
+
Naming/HeredocDelimiterNaming:
|
70
|
+
Enabled: false
|
71
|
+
|
72
|
+
Style/FormatString:
|
73
|
+
EnforcedStyle: sprintf
|
74
|
+
|
75
|
+
Style/FormatStringToken:
|
76
|
+
# EnforcedStyle: template
|
77
|
+
Enabled: false
|
78
|
+
|
79
|
+
# ==============================================================================
|
80
|
+
# Numbers
|
81
|
+
# ==============================================================================
|
82
|
+
|
83
|
+
Style/ZeroLengthPredicate:
|
84
|
+
Enabled: false
|
85
|
+
|
86
|
+
Style/NumericPredicate:
|
87
|
+
Enabled: false
|
88
|
+
|
89
|
+
# preferably `EnforcedStyle: snake_case`, but it varies.
|
90
|
+
Naming/VariableNumber:
|
91
|
+
Enabled: false
|
92
|
+
|
93
|
+
# ==============================================================================
|
94
|
+
# Braces, Brackets, and Parentheses
|
95
|
+
# ==============================================================================
|
96
|
+
|
97
|
+
Style/DefWithParentheses:
|
98
|
+
Enabled: false
|
99
|
+
|
100
|
+
Style/MethodCallWithoutArgsParentheses:
|
101
|
+
Enabled: false
|
102
|
+
|
103
|
+
Style/WordArray:
|
104
|
+
EnforcedStyle: brackets
|
105
|
+
|
106
|
+
Style/SymbolArray:
|
107
|
+
EnforcedStyle: brackets
|
108
|
+
|
109
|
+
# ==============================================================================
|
110
|
+
# Trailing Commas
|
111
|
+
# ==============================================================================
|
112
|
+
|
113
|
+
Style/TrailingCommaInArguments:
|
114
|
+
EnforcedStyleForMultiline: comma
|
115
|
+
|
116
|
+
Style/TrailingCommaInArrayLiteral:
|
117
|
+
EnforcedStyleForMultiline: comma
|
118
|
+
|
119
|
+
Style/TrailingCommaInHashLiteral:
|
120
|
+
EnforcedStyleForMultiline: comma
|
121
|
+
|
122
|
+
# ==============================================================================
|
123
|
+
# Fewer lines doesn't mean better code
|
124
|
+
# ==============================================================================
|
125
|
+
|
126
|
+
Metrics/ModuleLength:
|
127
|
+
Enabled: false
|
128
|
+
|
129
|
+
Metrics/ClassLength:
|
130
|
+
Enabled: false
|
131
|
+
|
132
|
+
Metrics/MethodLength:
|
133
|
+
Enabled: false
|
134
|
+
|
135
|
+
Metrics/BlockLength:
|
136
|
+
Enabled: false
|
137
|
+
|
138
|
+
# TODO: Look into adding an `EnforcedStyle` to not use guard clauses.
|
139
|
+
Style/GuardClause:
|
140
|
+
Enabled: false
|
141
|
+
|
142
|
+
# TODO: Look into adding an `EnforcedStyle` to not use if/unless modifiers.
|
143
|
+
Style/IfUnlessModifier:
|
144
|
+
Enabled: false
|
145
|
+
|
146
|
+
Style/Next:
|
147
|
+
Enabled: false
|
148
|
+
|
149
|
+
# ==============================================================================
|
150
|
+
# Explicit, not redundant
|
151
|
+
# ==============================================================================
|
152
|
+
|
153
|
+
Style/RedundantReturn:
|
154
|
+
Enabled: false
|
155
|
+
|
156
|
+
Style/RedundantSelf:
|
157
|
+
Enabled: false
|
158
|
+
|
159
|
+
# ==============================================================================
|
160
|
+
# Exceptions
|
161
|
+
# ==============================================================================
|
162
|
+
|
163
|
+
Lint/SuppressedException:
|
164
|
+
AllowComments: true
|
165
|
+
|
166
|
+
Style/RaiseArgs:
|
167
|
+
EnforcedStyle: exploded
|
168
|
+
|
169
|
+
# ==============================================================================
|
170
|
+
# Unsorted
|
171
|
+
# ==============================================================================
|
172
|
+
|
173
|
+
# Default value (special_inside_parentheses) is ridiculous.
|
174
|
+
# Look for yourself: https://www.rubydoc.info/gems/rubocop/0.69.0/RuboCop/Cop/Layout/IndentFirstHashElement
|
175
|
+
Layout/FirstHashElementIndentation:
|
176
|
+
EnforcedStyle: consistent
|
177
|
+
|
178
|
+
# Default value (special_inside_parentheses) is ridiculous.
|
179
|
+
# Look for yourself: https://www.rubydoc.info/gems/rubocop/0.69.0/RuboCop/Cop/Layout/IndentFirstArrayElement
|
180
|
+
Layout/FirstArrayElementIndentation:
|
181
|
+
EnforcedStyle: consistent
|
182
|
+
|
183
|
+
Layout/HashAlignment:
|
184
|
+
Enabled: false
|
185
|
+
|
186
|
+
# `x&.y&.[](:argument)` isn't what I'd call "readable".
|
187
|
+
# https://stackoverflow.com/questions/34794697/using-with-the-safe-navigation-operator-in-ruby
|
188
|
+
Style/SafeNavigation:
|
189
|
+
Enabled: false
|
190
|
+
|
191
|
+
Style/NegatedIf:
|
192
|
+
EnforcedStyle: postfix
|
193
|
+
|
194
|
+
# TODO: File issue to ignore enums when using `EnforcedStyle: assign_inside_condition`.
|
195
|
+
Style/ConditionalAssignment:
|
196
|
+
Enabled: false
|
197
|
+
|
198
|
+
Style/TernaryParentheses:
|
199
|
+
EnforcedStyle: require_parentheses_when_complex
|
200
|
+
|
201
|
+
Metrics/AbcSize:
|
202
|
+
Enabled: false
|
203
|
+
|
204
|
+
Metrics/CyclomaticComplexity:
|
205
|
+
Enabled: false
|
206
|
+
|
207
|
+
Metrics/PerceivedComplexity:
|
208
|
+
Enabled: false
|
209
|
+
|
210
|
+
Style/CommentedKeyword:
|
211
|
+
Enabled: False
|
212
|
+
|
213
|
+
Style/AsciiComments:
|
214
|
+
Enabled: false
|
215
|
+
|
216
|
+
Lint/EmptyWhen:
|
217
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
flat_file (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ansi (1.5.0)
|
10
|
+
builder (3.2.4)
|
11
|
+
coderay (1.1.3)
|
12
|
+
coveralls (0.8.23)
|
13
|
+
json (>= 1.8, < 3)
|
14
|
+
simplecov (~> 0.16.1)
|
15
|
+
term-ansicolor (~> 1.3)
|
16
|
+
thor (>= 0.19.4, < 2.0)
|
17
|
+
tins (~> 1.6)
|
18
|
+
docile (1.3.2)
|
19
|
+
json (2.3.1)
|
20
|
+
method_source (0.9.2)
|
21
|
+
minitest (5.14.2)
|
22
|
+
minitest-reporters (1.4.2)
|
23
|
+
ansi
|
24
|
+
builder
|
25
|
+
minitest (>= 5.0)
|
26
|
+
ruby-progressbar
|
27
|
+
pry (0.12.2)
|
28
|
+
coderay (~> 1.1.0)
|
29
|
+
method_source (~> 0.9.0)
|
30
|
+
rake (13.0.1)
|
31
|
+
ruby-progressbar (1.10.1)
|
32
|
+
simplecov (0.16.1)
|
33
|
+
docile (~> 1.1)
|
34
|
+
json (>= 1.8, < 3)
|
35
|
+
simplecov-html (~> 0.10.0)
|
36
|
+
simplecov-html (0.10.2)
|
37
|
+
sync (0.5.0)
|
38
|
+
term-ansicolor (1.7.1)
|
39
|
+
tins (~> 1.0)
|
40
|
+
thor (1.0.1)
|
41
|
+
tins (1.25.0)
|
42
|
+
sync
|
43
|
+
|
44
|
+
PLATFORMS
|
45
|
+
ruby
|
46
|
+
|
47
|
+
DEPENDENCIES
|
48
|
+
bundler (~> 2.0)
|
49
|
+
coveralls (~> 0.8.23)
|
50
|
+
flat_file!
|
51
|
+
minitest (~> 5.0)
|
52
|
+
minitest-reporters (~> 1.4)
|
53
|
+
pry (~> 0.12.2)
|
54
|
+
rake (~> 13.0)
|
55
|
+
simplecov (~> 0.16)
|
56
|
+
|
57
|
+
BUNDLED WITH
|
58
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Clay Dunston
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# FlatFile
|
2
|
+
|
3
|
+
Convenience methods for reading CSV, TSV, & JSON files.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'flat_file'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install flat_file
|
20
|
+
|
21
|
+
## License
|
22
|
+
|
23
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/flat_file.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative "lib/flat_file/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "flat_file"
|
5
|
+
spec.version = FlatFile::VERSION
|
6
|
+
spec.authors = ["Clay Dunston"]
|
7
|
+
spec.email = ["dunstontc@gmail.com"]
|
8
|
+
spec.summary = "Convenience methods for reading CSV, TSV, & JSON files"
|
9
|
+
spec.description = spec.summary
|
10
|
+
spec.homepage = "https://github.com/tcd/flat_file"
|
11
|
+
spec.license = "MIT"
|
12
|
+
|
13
|
+
spec.required_ruby_version = ">= 2.5.0"
|
14
|
+
|
15
|
+
spec.metadata = {
|
16
|
+
"homepage_uri" => spec.homepage,
|
17
|
+
"source_code_uri" => spec.homepage,
|
18
|
+
"changelog_uri" => "#{spec.homepage}/blob/master/CHANGELOG.md",
|
19
|
+
"documentation_uri" => "https://www.rubydoc.info/gems/#{spec.name}/#{spec.version}",
|
20
|
+
"yard.run" => "yri", # use "yard" to build full HTML docs.
|
21
|
+
}
|
22
|
+
|
23
|
+
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
31
|
+
spec.add_development_dependency "coveralls", "~> 0.8.23"
|
32
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
33
|
+
spec.add_development_dependency "minitest-reporters", "~> 1.4"
|
34
|
+
spec.add_development_dependency "pry", "~> 0.12.2"
|
35
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
36
|
+
spec.add_development_dependency "simplecov", "~> 0.16"
|
37
|
+
end
|
data/lib/flat_file.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "csv"
|
2
|
+
|
3
|
+
module FlatFile
|
4
|
+
module CSV
|
5
|
+
|
6
|
+
# Read a CSV file and return its contents as an array of hashes.
|
7
|
+
#
|
8
|
+
# @param filepath [String] Path to the CSV file.
|
9
|
+
# @return [Array<Hash>]
|
10
|
+
def self.from_file(filepath)
|
11
|
+
rows = []
|
12
|
+
begin
|
13
|
+
::CSV.foreach(filepath, headers: true) do |row|
|
14
|
+
rows.append(row)
|
15
|
+
end
|
16
|
+
return rows
|
17
|
+
rescue StandardError => e
|
18
|
+
# if defined?(Rails)
|
19
|
+
# Rails.logger.error({
|
20
|
+
# message: "Error reading CSV file",
|
21
|
+
# filepath: filepath,
|
22
|
+
# error: e,
|
23
|
+
# })
|
24
|
+
# end
|
25
|
+
return rows
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Read a CSV stream and return its contents as an array of hashes.
|
30
|
+
#
|
31
|
+
# @param data [String, IO] Stream of CSV data.
|
32
|
+
# @return [Array<Hash>]
|
33
|
+
def self.from_stream(data)
|
34
|
+
rows = []
|
35
|
+
begin
|
36
|
+
::CSV.new(data, headers: true).each do |row|
|
37
|
+
rows.append(row)
|
38
|
+
end
|
39
|
+
return rows
|
40
|
+
rescue StandardError => e
|
41
|
+
# if defined?(Rails)
|
42
|
+
# Rails.logger.error({
|
43
|
+
# message: "Error reading CSV data",
|
44
|
+
# error: e,
|
45
|
+
# })
|
46
|
+
# end
|
47
|
+
return rows
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module FlatFile
|
4
|
+
module JSON
|
5
|
+
|
6
|
+
# Return a hash parsed from a given JSON file.
|
7
|
+
#
|
8
|
+
# @param file [String]
|
9
|
+
# @return [Hash,ActiveSupport::HashWithIndifferentAccess]
|
10
|
+
def self.from_file(file)
|
11
|
+
data = ::JSON.parse(File.read(file))
|
12
|
+
if defined?(ActiveSupport::HashWithIndifferentAccess)
|
13
|
+
return data&.with_indifferent_access || data
|
14
|
+
end
|
15
|
+
return data
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require "csv"
|
2
|
+
|
3
|
+
module FlatFile
|
4
|
+
# Read data exports from Postico
|
5
|
+
module QSV
|
6
|
+
|
7
|
+
# https://ruby-doc.org/stdlib-2.6.1/libdoc/csv/rdoc/CSV.html#method-c-new
|
8
|
+
# @return [Hash]
|
9
|
+
OPTIONS = {
|
10
|
+
col_sep: ";",
|
11
|
+
headers: true,
|
12
|
+
quote_char: "'",
|
13
|
+
converters: ::CSV::Converters.keys + [:json],
|
14
|
+
}.freeze()
|
15
|
+
|
16
|
+
# @param filepath [String] Path to the file.
|
17
|
+
# @return [Array<Hash{String => String}>]
|
18
|
+
def self.from_file(filepath)
|
19
|
+
# ::CSV::Converters[:json] = ->(s) { self.parse_postico_json(s) }
|
20
|
+
return ::CSV.read(filepath, self.options).map(&:to_hash)
|
21
|
+
end
|
22
|
+
|
23
|
+
# @return [Hash]
|
24
|
+
def self.options()
|
25
|
+
custom_converter = ->(value, field_info) { self.parse_postico_json(value, field_info) }
|
26
|
+
return {
|
27
|
+
col_sep: ";",
|
28
|
+
headers: true,
|
29
|
+
quote_char: '"',
|
30
|
+
converters: [custom_converter],
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param value [Object]
|
35
|
+
# @param _field_info [Hash]
|
36
|
+
# @return [Object]
|
37
|
+
def self.parse_postico_json(value, _field_info)
|
38
|
+
return value if value.blank?()
|
39
|
+
return value if value.length == 0
|
40
|
+
return value unless value[0] == "{"
|
41
|
+
return ::JSON.parse(value)
|
42
|
+
rescue ::JSON::ParserError => e
|
43
|
+
# if defined?(Rails)
|
44
|
+
# Rails.logger.error({
|
45
|
+
# message: "Rescued from 'JSON::ParserError' in parse_postico_json",
|
46
|
+
# error: e,
|
47
|
+
# })
|
48
|
+
# end
|
49
|
+
return value
|
50
|
+
rescue StandardError => e
|
51
|
+
# if defined?(Rails)
|
52
|
+
# Rails.logger.error({
|
53
|
+
# message: "Rescued from 'StandardError' in parse_postico_json",
|
54
|
+
# error: e,
|
55
|
+
# })
|
56
|
+
# end
|
57
|
+
return value
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "csv"
|
2
|
+
|
3
|
+
module FlatFile
|
4
|
+
module TSV
|
5
|
+
|
6
|
+
# Read a TSV file and return its contents as an array of hashes.
|
7
|
+
#
|
8
|
+
# @param filepath [String] Path to the TSV file.
|
9
|
+
# @param delim [String]
|
10
|
+
# @return [Array<Hash{String => String}>]
|
11
|
+
def self.from_file(filepath, delim: "\t")
|
12
|
+
return ::CSV.read(
|
13
|
+
filepath,
|
14
|
+
col_sep: delim,
|
15
|
+
headers: true,
|
16
|
+
quote_char: "\x00",
|
17
|
+
).map(&:to_hash)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: flat_file
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Clay Dunston
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: coveralls
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.8.23
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.8.23
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest-reporters
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.4'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.4'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.12.2
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.12.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '13.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '13.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.16'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.16'
|
111
|
+
description: Convenience methods for reading CSV, TSV, & JSON files
|
112
|
+
email:
|
113
|
+
- dunstontc@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".editorconfig"
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rubocop.yml"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- flat_file.gemspec
|
130
|
+
- lib/flat_file.rb
|
131
|
+
- lib/flat_file/csv.rb
|
132
|
+
- lib/flat_file/json.rb
|
133
|
+
- lib/flat_file/qsv.rb
|
134
|
+
- lib/flat_file/tsv.rb
|
135
|
+
- lib/flat_file/version.rb
|
136
|
+
homepage: https://github.com/tcd/flat_file
|
137
|
+
licenses:
|
138
|
+
- MIT
|
139
|
+
metadata:
|
140
|
+
homepage_uri: https://github.com/tcd/flat_file
|
141
|
+
source_code_uri: https://github.com/tcd/flat_file
|
142
|
+
changelog_uri: https://github.com/tcd/flat_file/blob/master/CHANGELOG.md
|
143
|
+
documentation_uri: https://www.rubydoc.info/gems/flat_file/0.1.0
|
144
|
+
yard.run: yri
|
145
|
+
post_install_message:
|
146
|
+
rdoc_options: []
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: 2.5.0
|
154
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
requirements: []
|
160
|
+
rubygems_version: 3.0.3
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: Convenience methods for reading CSV, TSV, & JSON files
|
164
|
+
test_files: []
|