simple_csv_reader 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 883360d0ae6bc78d60f7e0bd78ac3538ee10a59f9503643e5caccac99c2a6fd2
4
- data.tar.gz: ae7699c0bf22496cd6ad38f8c0708cd0f9410c820ec0154c589b3cb1e60bbb74
3
+ metadata.gz: 464241d327186f58aa17c95eaff8b93b0ca53d73bdbf42b97802109548942d39
4
+ data.tar.gz: 94144bdfcff87e98a177c4a6563a562c9a11cac0d37b1ba0e700beebe74db631
5
5
  SHA512:
6
- metadata.gz: ce58851fee8d188e927a4a4b7641bbc682d9aa977b46cc1c59588d3caedfb783dc925bc3a325f2df009c1736a46b3f6efb7f97991708c7e4e73e29a5dca5e595
7
- data.tar.gz: 267b80334c10df56ff74feecced840684c190eaf1942389b59057860a3bcfdaeaed9dfc9b49464c06f4eaf0aecd7d67b06e34b3e97319fc4db9062eefb06f1f5
6
+ metadata.gz: e78ff8c6d8e0c21417461a83b4238850f4ab9ffffc953563f9afb75066374d453d6e9b5b7e15a0a55563a35dbf8d90fa23a5ac678e68099588f6888c77f09fb6
7
+ data.tar.gz: da60653a2af7b3b6ce3d131ebabbe2059b69b8f7b39e592a4697f4099ae528a38d776da1239b5354c8f8d9068b132997f47b9c085c1e82289e041021a7c5bce0
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_csv_reader (0.1.0)
4
+ simple_csv_reader (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -9,20 +9,21 @@ 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
14
  csv(headers).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
- yield(hash.slice(*headers.keys), row_number: row_number)
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
25
  def csv(headers)
25
- header_converter = ->(h) { headers.invert[h] }
26
+ header_converter = -> { headers.invert.fetch(_1, _1) }
26
27
  CSV.parse(content, headers: :first_row, header_converters: header_converter, converters: :integer)
27
28
  end
28
29
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SimpleCsvReader
4
- VERSION = "0.1.0"
4
+ VERSION = '0.2.0'
5
5
  end
@@ -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.1.0
4
+ version: 0.2.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-06-29 00:00:00.000000000 Z
11
+ date: 2022-07-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple CSV reader.
14
14
  email: