simple_csv_reader 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/simple_csv_reader/reader.rb +7 -6
- data/lib/simple_csv_reader/version.rb +1 -1
- data/lib/simple_csv_reader.rb +2 -2
- 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: 85db951fc28b9b5dce4660386480f9f2c2bcf445031559c5240d10bde37baec0
|
4
|
+
data.tar.gz: f192937261995849810277db919abfd15698723bf8cf5e51be66c1dadfc4ba75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93ead315b6c1848242c057717007fa7082914c7267f80bdd0b734b3fbf7b5b19be7e915acfe8b084271a85dd031a55dab99330638dd406b5acc9868c1bf7a395
|
7
|
+
data.tar.gz: c31551dd5a57e944d49b93716c6a2a06b0b206fad6b8f49cfdb55be9fd8e810b28bd9d870e749281171e7ae375440cedcf6fda0a4c6c0200ab1d1bcea86cffbb
|
data/Gemfile.lock
CHANGED
@@ -9,21 +9,22 @@ module SimpleCsvReader
|
|
9
9
|
@path = path
|
10
10
|
end
|
11
11
|
|
12
|
-
def read(headers, &block)
|
12
|
+
def read(headers, **options, &block)
|
13
13
|
# NOTE: The first line is a header
|
14
|
-
csv(headers).each.with_index(2) do |row, row_number|
|
14
|
+
csv(headers, **options.slice(:converters)).each.with_index(2) do |row, row_number|
|
15
15
|
hash = row.to_h
|
16
16
|
next if hash.compact.empty? # NOTE: blank row
|
17
17
|
|
18
|
-
|
18
|
+
filtered_hash = options[:include_unspecified_headers] ? hash : hash.slice(*headers.keys)
|
19
|
+
yield(filtered_hash, row_number: row_number)
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
23
|
private
|
23
24
|
|
24
|
-
def csv(headers)
|
25
|
-
header_converter = ->
|
26
|
-
CSV.parse(content, headers: :first_row, header_converters: header_converter, converters:
|
25
|
+
def csv(headers, converters: :numeric)
|
26
|
+
header_converter = -> { headers.invert.fetch(_1, _1) }
|
27
|
+
CSV.parse(content, headers: :first_row, header_converters: header_converter, converters: converters)
|
27
28
|
end
|
28
29
|
|
29
30
|
def content
|
data/lib/simple_csv_reader.rb
CHANGED
@@ -4,8 +4,8 @@ require_relative "simple_csv_reader/reader"
|
|
4
4
|
require_relative "simple_csv_reader/version"
|
5
5
|
|
6
6
|
module SimpleCsvReader
|
7
|
-
def read(path, headers, &block)
|
8
|
-
Reader.new(path).read(headers, &block)
|
7
|
+
def read(path, headers, **options, &block)
|
8
|
+
Reader.new(path).read(headers, **options, &block)
|
9
9
|
end
|
10
10
|
|
11
11
|
module_function :read
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_csv_reader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aki77
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A simple CSV reader.
|
14
14
|
email:
|