recite_csv 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +0 -0
- data/.rspec +0 -0
- data/.rubocop.yml +0 -0
- data/.travis.yml +4 -4
- data/CHANGELOG.md +14 -0
- data/Gemfile +0 -0
- data/LICENSE.txt +1 -1
- data/README.md +29 -3
- data/Rakefile +0 -0
- data/bin/console +1 -8
- data/bin/setup +0 -0
- data/lib/recite_csv.rb +0 -0
- data/lib/recite_csv/header.rb +0 -0
- data/lib/recite_csv/header/definition.rb +9 -4
- data/lib/recite_csv/module.rb +0 -0
- data/lib/recite_csv/reader.rb +0 -0
- data/lib/recite_csv/reader/builder.rb +2 -1
- data/lib/recite_csv/reader/core.rb +28 -7
- data/lib/recite_csv/reader/dsl.rb +0 -0
- data/lib/recite_csv/row.rb +0 -0
- data/lib/recite_csv/row/base.rb +8 -0
- data/lib/recite_csv/version.rb +1 -1
- data/recite_csv.gemspec +0 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7a4537328a0288a5ab2128f56327322eee068031d5afaab03706734bb179041e
|
4
|
+
data.tar.gz: 0b5a4fce48b66f8e93225952c042d21aba89e90fcad4144ffc1e466c7e1c352c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b7f88122616980eacfc4a859aeb6fff0c3e801b96594318992653142b630e597fa41eed2926650898b5020432173219e721c2e10cbbba71a8816e65f4d98924
|
7
|
+
data.tar.gz: a85827717185419d59cb08a23fa22f847a8ec9e0a3049b410e0972d22beb1deaa67133dd24d32675e304ef49ecbf45e9dc889e43a3d62d03f1e68f0245c089da
|
data/.gitignore
CHANGED
File without changes
|
data/.rspec
CHANGED
File without changes
|
data/.rubocop.yml
CHANGED
File without changes
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
## Unreleased
|
2
2
|
|
3
|
+
|
4
|
+
## 0.1.2 (2018-02-23)
|
5
|
+
|
6
|
+
### Changes
|
7
|
+
|
8
|
+
* Change `Row::Base` to an abstract class
|
9
|
+
* Add support Ruby v2.5
|
10
|
+
* Add file options to `Reader::Core#each`
|
11
|
+
|
12
|
+
### Misc
|
13
|
+
|
14
|
+
* Change to use `Hash#each_pair` instead of `Hash#each`
|
15
|
+
|
16
|
+
|
3
17
|
## 0.1.1 (2017-12-03)
|
4
18
|
|
5
19
|
### Changes
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,7 @@ ReciteCSV helps to build a class for CSV reader.
|
|
4
4
|
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/recite_csv.svg)](https://badge.fury.io/rb/recite_csv)
|
6
6
|
[![Build Status](https://travis-ci.org/yujideveloper/recite_csv.svg?branch=master)](https://travis-ci.org/yujideveloper/recite_csv)
|
7
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/eb04cab6d55b0c7a1f7f/maintainability)](https://codeclimate.com/github/yujideveloper/recite_csv/maintainability)
|
7
8
|
|
8
9
|
## Installation
|
9
10
|
|
@@ -88,7 +89,7 @@ end
|
|
88
89
|
Define custom methods of row object using `row_methods`.
|
89
90
|
|
90
91
|
``` ruby
|
91
|
-
class
|
92
|
+
class Qux
|
92
93
|
include ReciteCSV::Reader::Builder.new(col1: "COL1", col2: "COL2")
|
93
94
|
|
94
95
|
row_methods do
|
@@ -102,14 +103,39 @@ class Quz
|
|
102
103
|
end
|
103
104
|
end
|
104
105
|
|
105
|
-
|
106
|
-
row.class # =>
|
106
|
+
Qux.new("./example.csv").each do |row|
|
107
|
+
row.class # => Qux::Row
|
107
108
|
row.col1
|
108
109
|
row.col2
|
109
110
|
row.custom_method
|
110
111
|
end
|
111
112
|
```
|
112
113
|
|
114
|
+
Specify file mode and encoding.
|
115
|
+
|
116
|
+
``` ruby
|
117
|
+
class Quux
|
118
|
+
include ReciteCSV::Reader::Builder.new(col1: "COL1", col2: "COL2")
|
119
|
+
end
|
120
|
+
|
121
|
+
Quux.new("./example.csv", file_options: "rb:UTF-8").each do |row|
|
122
|
+
# do something
|
123
|
+
end
|
124
|
+
```
|
125
|
+
|
126
|
+
Convert encoding.
|
127
|
+
|
128
|
+
``` ruby
|
129
|
+
class Corge
|
130
|
+
include ReciteCSV::Reader::Builder.new(col1: "COL1", col2: "COL2")
|
131
|
+
end
|
132
|
+
|
133
|
+
Corge.new("./example.csv", file_options: ["rb:Shift_JIS:UTF-8", invalid: :replace, undef: :replace]).each do |row|
|
134
|
+
# do something
|
135
|
+
end
|
136
|
+
```
|
137
|
+
|
138
|
+
|
113
139
|
## Development
|
114
140
|
|
115
141
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
File without changes
|
data/bin/console
CHANGED
@@ -3,13 +3,6 @@
|
|
3
3
|
|
4
4
|
require "bundler/setup"
|
5
5
|
require "recite_csv"
|
6
|
-
|
7
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
-
# with your gem easier. You can also use a different console, if you like.
|
9
|
-
|
10
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
-
# require "pry"
|
12
|
-
# Pry.start
|
13
|
-
|
14
6
|
require "pry"
|
7
|
+
|
15
8
|
Pry.start
|
data/bin/setup
CHANGED
File without changes
|
data/lib/recite_csv.rb
CHANGED
File without changes
|
data/lib/recite_csv/header.rb
CHANGED
File without changes
|
@@ -20,7 +20,8 @@ module ReciteCSV
|
|
20
20
|
|
21
21
|
def self.new(*)
|
22
22
|
if self == Base
|
23
|
-
raise ::NotImplementedError,
|
23
|
+
raise ::NotImplementedError,
|
24
|
+
"#{self} is an abstract class and cannot be instantiated."
|
24
25
|
end
|
25
26
|
super
|
26
27
|
end
|
@@ -31,7 +32,7 @@ module ReciteCSV
|
|
31
32
|
|
32
33
|
class ColumnMethodsBuilder < ::Module
|
33
34
|
def initialize(raw_definition)
|
34
|
-
raw_definition.
|
35
|
+
raw_definition.each_pair do |method_name, header_name|
|
35
36
|
define_method method_name do
|
36
37
|
self[header_name]
|
37
38
|
end
|
@@ -65,8 +66,12 @@ module ReciteCSV
|
|
65
66
|
module_function
|
66
67
|
|
67
68
|
def dispatch(header_definition)
|
68
|
-
_, definition_class = DEFINITIONS.find
|
69
|
-
|
69
|
+
_, definition_class = DEFINITIONS.find do |klass, _|
|
70
|
+
header_definition.is_a? klass
|
71
|
+
end
|
72
|
+
unless definition_class
|
73
|
+
raise ::ArgumentError, "Unexpected header definition type"
|
74
|
+
end
|
70
75
|
definition_class.new(header_definition)
|
71
76
|
end
|
72
77
|
end
|
data/lib/recite_csv/module.rb
CHANGED
File without changes
|
data/lib/recite_csv/reader.rb
CHANGED
File without changes
|
@@ -20,7 +20,8 @@ module ReciteCSV
|
|
20
20
|
def included(class_or_module)
|
21
21
|
class_or_module.include Core
|
22
22
|
class_or_module.const_set(:Row, @row_class)
|
23
|
-
class_or_module.const_set(:DEFAULT_CSV_OPTIONS,
|
23
|
+
class_or_module.const_set(:DEFAULT_CSV_OPTIONS,
|
24
|
+
@definition.default_csv_options)
|
24
25
|
class_or_module.extend DSL
|
25
26
|
end
|
26
27
|
end
|
@@ -7,22 +7,43 @@ module ReciteCSV
|
|
7
7
|
module Core
|
8
8
|
include Enumerable
|
9
9
|
|
10
|
-
attr_reader :file, :csv_options
|
10
|
+
attr_reader :file, :file_options, :csv_options
|
11
11
|
|
12
|
-
def initialize(file,
|
12
|
+
def initialize(file, options = {})
|
13
13
|
@file = file
|
14
|
-
@
|
14
|
+
@file_options = options.delete(:file_options) || {}
|
15
|
+
@csv_options =
|
16
|
+
(options || {}).merge(self.class::DEFAULT_CSV_OPTIONS)
|
15
17
|
end
|
16
18
|
|
17
|
-
def each
|
19
|
+
def each(&block)
|
18
20
|
if block_given?
|
19
|
-
|
20
|
-
yield self.class::Row.new(raw_row)
|
21
|
-
end
|
21
|
+
_each(&block)
|
22
22
|
else
|
23
23
|
self.to_enum
|
24
24
|
end
|
25
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def _each(&block)
|
30
|
+
f = if self.file.is_a?(::String)
|
31
|
+
::File.open(self.file, *Array(self.file_options))
|
32
|
+
else
|
33
|
+
self.file
|
34
|
+
end
|
35
|
+
begin
|
36
|
+
_foreach(f, &block)
|
37
|
+
ensure
|
38
|
+
f.close if self.file.is_a?(::String)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def _foreach(f)
|
43
|
+
::CSV.new(f, self.csv_options).each do |raw_row|
|
44
|
+
yield self.class::Row.new(raw_row)
|
45
|
+
end
|
46
|
+
end
|
26
47
|
end
|
27
48
|
end
|
28
49
|
end
|
File without changes
|
data/lib/recite_csv/row.rb
CHANGED
File without changes
|
data/lib/recite_csv/row/base.rb
CHANGED
data/lib/recite_csv/version.rb
CHANGED
data/recite_csv.gemspec
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recite_csv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuji Hanamura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
130
|
version: '0'
|
131
131
|
requirements: []
|
132
132
|
rubyforge_project:
|
133
|
-
rubygems_version: 2.
|
133
|
+
rubygems_version: 2.7.3
|
134
134
|
signing_key:
|
135
135
|
specification_version: 4
|
136
136
|
summary: ReciteCSV helps to build a class for CSV reader.
|