csvh 0.5.1 → 0.8.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 +4 -4
- data/lib/csvh/reader.rb +151 -6
- data/lib/csvh/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6323cad1ddf79e484199f5830eb10076b61d04f
|
4
|
+
data.tar.gz: 779978ad240f9f0a2b1a46f3e316aad5d460f167
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9bc569b2cb0d5008214c42c43fb2f897d67ad44278da745636797cd369bb88ff0e15bc7d60bf5551dead5bd57d5ed414c39cba7d7a1dab35dadd9fed366b05ff
|
7
|
+
data.tar.gz: ea02ecde2fe229c2551654ff898c02128aff2bbed72796f28712de20664eda7247e42ea329255de28a70f2d6074aafaa263519e7837fed8109593ff9d26f9af3
|
data/lib/csvh/reader.rb
CHANGED
@@ -30,6 +30,38 @@ module CSVH
|
|
30
30
|
# return the header row. Any oadditional options you supply
|
31
31
|
# will be added to those defaults or override them.
|
32
32
|
#
|
33
|
+
# A [Reader] created using this method will delegate all
|
34
|
+
# of the same IO methods that a `CSV` created using
|
35
|
+
# `CSV#open` does except `close_write`, `flush`, `fsync`,
|
36
|
+
# `sync`, `sync=`, and `truncate`. You may call:
|
37
|
+
#
|
38
|
+
# * binmode()
|
39
|
+
# * binmode?()
|
40
|
+
# * close()
|
41
|
+
# * close_read()
|
42
|
+
# * closed?()
|
43
|
+
# * eof()
|
44
|
+
# * eof?()
|
45
|
+
# * external_encoding()
|
46
|
+
# * fcntl()
|
47
|
+
# * fileno()
|
48
|
+
# * flock()
|
49
|
+
# * flush()
|
50
|
+
# * internal_encoding()
|
51
|
+
# * ioctl()
|
52
|
+
# * isatty()
|
53
|
+
# * path()
|
54
|
+
# * pid()
|
55
|
+
# * pos()
|
56
|
+
# * pos=()
|
57
|
+
# * reopen()
|
58
|
+
# * seek()
|
59
|
+
# * fstat()
|
60
|
+
# * tell()
|
61
|
+
# * to_i()
|
62
|
+
# * to_io()
|
63
|
+
# * tty?()
|
64
|
+
#
|
33
65
|
# @param file_path [String] the path of the file to read.
|
34
66
|
# @param opts options for `CSV.new`.
|
35
67
|
# @yieldparam [Reader] the new reader.
|
@@ -119,17 +151,60 @@ module CSVH
|
|
119
151
|
end
|
120
152
|
end
|
121
153
|
|
154
|
+
# These methods always delegate to CSV, which may or may not
|
155
|
+
# futher delegate them to its underlying file IO object,
|
156
|
+
# depending on how it was created.
|
157
|
+
|
122
158
|
def_delegators \
|
123
159
|
:@csv,
|
160
|
+
:binmode,
|
161
|
+
:binmode?,
|
162
|
+
:close_read,
|
124
163
|
:close,
|
125
|
-
:closed
|
164
|
+
:closed?,
|
165
|
+
:eof,
|
166
|
+
:eof?,
|
167
|
+
:external_encoding,
|
168
|
+
:fcntl,
|
169
|
+
:fileno,
|
170
|
+
:flock,
|
171
|
+
:flush,
|
172
|
+
:internal_encoding,
|
173
|
+
:ioctl,
|
174
|
+
:isatty,
|
175
|
+
:path,
|
176
|
+
:pid,
|
177
|
+
:pos,
|
178
|
+
:pos=,
|
179
|
+
:reopen,
|
180
|
+
:seek,
|
181
|
+
:fstat,
|
182
|
+
:tell,
|
183
|
+
:to_i,
|
184
|
+
:to_io,
|
185
|
+
:tty?
|
186
|
+
|
187
|
+
# You can use this method to install a `CSV::Converters`
|
188
|
+
# built-in, or provide a block that handles a custom
|
189
|
+
# conversion.
|
190
|
+
#
|
191
|
+
# See the documentation for `CSV` in the Ruby standard
|
192
|
+
# library for more details.
|
193
|
+
def_delegator :@csv, :convert
|
194
|
+
|
195
|
+
# Returns the current list of converters in effect.
|
196
|
+
#
|
197
|
+
# See the documentation for `CSV` in the Ruby standard
|
198
|
+
# library for more details.
|
199
|
+
def_delegator :@csv, :converters
|
126
200
|
|
127
|
-
# When given a block, yields each data row of the
|
128
|
-
# in turn as `CSV::Row`
|
129
|
-
# block, returns an Enumerator over those rows.
|
201
|
+
# When given a block, yields each remaining data row of the
|
202
|
+
# data source in turn as a `CSV::Row` instance. When called
|
203
|
+
# without a block, returns an Enumerator over those rows.
|
130
204
|
#
|
131
|
-
#
|
132
|
-
# available via the #headers method of the reader or
|
205
|
+
# Will never yield the header row, however, the headers are
|
206
|
+
# available via the #headers method of either the reader or
|
207
|
+
# the row object.
|
133
208
|
#
|
134
209
|
# @yieldparam [CSV::Row]
|
135
210
|
def each
|
@@ -141,6 +216,76 @@ module CSVH
|
|
141
216
|
end
|
142
217
|
end
|
143
218
|
|
219
|
+
# Returns `true` if all output fields are quoted.
|
220
|
+
#
|
221
|
+
# See the documentation for `CSV` in the Ruby standard
|
222
|
+
# library for more details.
|
223
|
+
def_delegator :@csv, :force_quotes?
|
224
|
+
|
225
|
+
# Identical to #convert, but for header rows.
|
226
|
+
#
|
227
|
+
# Note that this must be called before reading any rows or
|
228
|
+
# calling #headers to have any effect.
|
229
|
+
#
|
230
|
+
# See the documentation for `CSV` in the Ruby standard
|
231
|
+
# library for more details.
|
232
|
+
def_delegator :@csv, :header_convert
|
233
|
+
|
234
|
+
# Returns the current list of converters in effect for
|
235
|
+
# headers.
|
236
|
+
#
|
237
|
+
# See the documentation for `CSV` in the Ruby standard
|
238
|
+
# library for more details.
|
239
|
+
def_delegator :@csv, :header_converters
|
240
|
+
|
241
|
+
# Slurps the remaining data rows and returns a `CSV::Table`.
|
242
|
+
#
|
243
|
+
# This is essentially the same behavior as `CSV#read`, but
|
244
|
+
# ensures that the header info has been fetched first, and the
|
245
|
+
# resulting table will never include the header row.
|
246
|
+
#
|
247
|
+
# Note that the Ruby documentation (at least as of 2.2.2) is
|
248
|
+
# for `CSV#read` is incomplete and simply says that it
|
249
|
+
# returns "an Array of Arrays", but it actually returns a
|
250
|
+
# table if a truthy `:headers` option was used when creating
|
251
|
+
# the `CSV` object.
|
252
|
+
#
|
253
|
+
# @return [CSV::Table] a table of remaining unread rows
|
254
|
+
def read
|
255
|
+
headers
|
256
|
+
@csv.read
|
257
|
+
end
|
258
|
+
|
259
|
+
alias readlines read
|
260
|
+
|
261
|
+
# A single data row is pulled from the data source, parsed
|
262
|
+
# and returned as a CSV::Row.
|
263
|
+
#
|
264
|
+
# This is essentially the same behavior as `CSV#shift`, but
|
265
|
+
# ensures that the header info has been fetched first, and
|
266
|
+
# #shift will never return the header row.
|
267
|
+
#
|
268
|
+
# @return [CSV::Row] the next previously unread row
|
269
|
+
def shift
|
270
|
+
headers
|
271
|
+
@csv.shift
|
272
|
+
end
|
273
|
+
|
274
|
+
alias gets shift
|
275
|
+
alias readline shift
|
276
|
+
|
277
|
+
# Returns `true` if blank lines are skipped by the parser.
|
278
|
+
#
|
279
|
+
# See the documentation for `CSV` in the Ruby standard
|
280
|
+
# library for more details.
|
281
|
+
def_delegator :@csv, :skip_blanks?
|
282
|
+
|
283
|
+
# Returns `true` if `unconverted_fields()` to parsed results.
|
284
|
+
#
|
285
|
+
# See the documentation for `CSV` in the Ruby standard
|
286
|
+
# library for more details.
|
287
|
+
def_delegator :@csv, :unconverted_fields?
|
288
|
+
|
144
289
|
end
|
145
290
|
|
146
291
|
end
|
data/lib/csvh/version.rb
CHANGED