data_collector 0.35.0 → 0.36.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +7 -0
- data/lib/data_collector/input.rb +11 -4
- data/lib/data_collector/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 649b618a7676b2153451b2bc3053726dd332ccc95a58ce0fe7115f4c9cc5a7eb
|
4
|
+
data.tar.gz: 625ca0e9da4e6b986d7ead973c80fc04a87a5539f0f7263efc672ee0f3ef7eb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2372b50b9fc9e6f5a17575c1755e169f0ddbaef44ed96847d8f5c87b28a3e30e46276cf47f6e506fe843a2293190b54fd556978ea175f937693abd4f83a637dd
|
7
|
+
data.tar.gz: 7a417a9ee3a70140a3601d20613159222f6c2d6d0d7feaa99c447c7e31306f14c6f08c50543cb8fda85315b5fe62abde202e2b3bda51ac421f6a517f7b6be740
|
data/README.md
CHANGED
@@ -403,6 +403,13 @@ Should give as output
|
|
403
403
|
</data>
|
404
404
|
```
|
405
405
|
|
406
|
+
You can provide options to input.from_uri for better reading CSV formats these
|
407
|
+
are the same the Ruby [CSV](https://docs.ruby-lang.org/en/master/CSV.html#class-CSV-label-Options) class
|
408
|
+
|
409
|
+
Loading a CSV file with **;** as the row seperator
|
410
|
+
```ruby
|
411
|
+
i = input.from_uri('https://support.staffbase.com/hc/en-us/article_attachments/360009197031/username.csv', col_sep: ';')
|
412
|
+
```
|
406
413
|
|
407
414
|
## Installation
|
408
415
|
|
data/lib/data_collector/input.rb
CHANGED
@@ -161,7 +161,7 @@ module DataCollector
|
|
161
161
|
when 'application/atom+xml'
|
162
162
|
data = xml_to_hash(data, options)
|
163
163
|
when 'text/csv'
|
164
|
-
data = csv_to_hash(data)
|
164
|
+
data = csv_to_hash(data, options)
|
165
165
|
when 'application/xml'
|
166
166
|
data = xml_to_hash(data, options)
|
167
167
|
when 'text/xml'
|
@@ -231,7 +231,7 @@ module DataCollector
|
|
231
231
|
end #entry
|
232
232
|
end #tar
|
233
233
|
when '.csv'
|
234
|
-
data = csv_to_hash(data)
|
234
|
+
data = csv_to_hash(data, options)
|
235
235
|
else
|
236
236
|
raise "Do not know how to process #{uri.to_s}"
|
237
237
|
end
|
@@ -264,8 +264,15 @@ module DataCollector
|
|
264
264
|
nori.parse(data)
|
265
265
|
end
|
266
266
|
|
267
|
-
def csv_to_hash(data)
|
268
|
-
|
267
|
+
def csv_to_hash(data, options = {})
|
268
|
+
csv_option_keys = options.keys & CSV::DEFAULT_OPTIONS.keys
|
269
|
+
all_cvs_options = {headers: true, header_converters: [:downcase, :symbol]}
|
270
|
+
|
271
|
+
csv_option_keys.each do |k|
|
272
|
+
all_cvs_options[k] = options[k]
|
273
|
+
end
|
274
|
+
|
275
|
+
csv = CSV.parse(data, **all_cvs_options)
|
269
276
|
|
270
277
|
csv.collect do |record|
|
271
278
|
record.to_hash
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_collector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.36.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mehmet Celik
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-11-
|
11
|
+
date: 2023-11-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|