stream_lines 0.1.0 → 0.2.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/.rubocop.yml +1 -1
- data/.ruby-version +1 -1
- data/.travis.yml +1 -0
- data/Gemfile.lock +27 -27
- data/README.md +35 -0
- data/lib/stream_lines/reading/csv.rb +57 -0
- data/lib/stream_lines/version.rb +1 -1
- data/stream_lines.gemspec +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e013c9cf1743dc898ba15674efbd7580f8adb5c6a9e9c51f809aa909396d757c
|
4
|
+
data.tar.gz: fc035c2bf4443ff31ad72c0b4b49fa12c49249a9ac69dd497d5e693fa3e59c26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b90ff2f6d5e448a860acb2239d502c65bbbe5e42cf172b05ab13fb33dbbbe9128ddac072fffda287713d858d34723f2a210e741ce283d3978183ac9392dba24
|
7
|
+
data.tar.gz: 2fe851b3093d5c64b78f7e0112f132310f53ae2b6a254ec46d0bbdd35187dd1a4f26cd532fd51146fecfd88e11b8e33d1e0e4c817307b7e8c8a34aceed6d5362
|
data/.rubocop.yml
CHANGED
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.7.0
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stream_lines (0.
|
4
|
+
stream_lines (0.2.0)
|
5
5
|
httparty (~> 0.14)
|
6
6
|
|
7
7
|
GEM
|
@@ -16,7 +16,7 @@ GEM
|
|
16
16
|
bundler (>= 1.2.0, < 3)
|
17
17
|
thor (~> 0.18)
|
18
18
|
bundler-gem_version_tasks (0.2.1)
|
19
|
-
byebug (11.
|
19
|
+
byebug (11.1.1)
|
20
20
|
crack (0.4.3)
|
21
21
|
safe_yaml (~> 1.0.0)
|
22
22
|
diff-lcs (1.3)
|
@@ -25,24 +25,24 @@ GEM
|
|
25
25
|
get_process_mem (0.2.5)
|
26
26
|
ffi (~> 1.0)
|
27
27
|
hashdiff (1.0.0)
|
28
|
-
httparty (0.17.
|
28
|
+
httparty (0.17.3)
|
29
29
|
mime-types (~> 3.0)
|
30
30
|
multi_xml (>= 0.5.2)
|
31
31
|
jaro_winkler (1.5.4)
|
32
|
-
json (2.2.0)
|
33
32
|
memory_profiler (0.9.14)
|
34
|
-
mime-types (3.3)
|
33
|
+
mime-types (3.3.1)
|
35
34
|
mime-types-data (~> 3.2015)
|
36
35
|
mime-types-data (3.2019.1009)
|
37
36
|
multi_json (1.14.1)
|
38
37
|
multi_xml (0.6.0)
|
39
|
-
mustermann (1.
|
38
|
+
mustermann (1.1.1)
|
39
|
+
ruby2_keywords (~> 0.0.1)
|
40
40
|
parallel (1.19.1)
|
41
|
-
parser (2.
|
41
|
+
parser (2.7.0.2)
|
42
42
|
ast (~> 2.4.0)
|
43
|
-
public_suffix (4.0.
|
44
|
-
rack (2.0.
|
45
|
-
rack-protection (2.0.
|
43
|
+
public_suffix (4.0.3)
|
44
|
+
rack (2.0.8)
|
45
|
+
rack-protection (2.0.8.1)
|
46
46
|
rack
|
47
47
|
rainbow (3.0.0)
|
48
48
|
rake (13.0.1)
|
@@ -50,45 +50,45 @@ GEM
|
|
50
50
|
rspec-core (~> 3.9.0)
|
51
51
|
rspec-expectations (~> 3.9.0)
|
52
52
|
rspec-mocks (~> 3.9.0)
|
53
|
-
rspec-core (3.9.
|
54
|
-
rspec-support (~> 3.9.
|
53
|
+
rspec-core (3.9.1)
|
54
|
+
rspec-support (~> 3.9.1)
|
55
55
|
rspec-expectations (3.9.0)
|
56
56
|
diff-lcs (>= 1.2.0, < 2.0)
|
57
57
|
rspec-support (~> 3.9.0)
|
58
|
-
rspec-mocks (3.9.
|
58
|
+
rspec-mocks (3.9.1)
|
59
59
|
diff-lcs (>= 1.2.0, < 2.0)
|
60
60
|
rspec-support (~> 3.9.0)
|
61
|
-
rspec-support (3.9.
|
62
|
-
rubocop (0.
|
61
|
+
rspec-support (3.9.2)
|
62
|
+
rubocop (0.79.0)
|
63
63
|
jaro_winkler (~> 1.5.1)
|
64
64
|
parallel (~> 1.10)
|
65
|
-
parser (>= 2.
|
65
|
+
parser (>= 2.7.0.1)
|
66
66
|
rainbow (>= 2.2.2, < 4.0)
|
67
67
|
ruby-progressbar (~> 1.7)
|
68
68
|
unicode-display_width (>= 1.4.0, < 1.7)
|
69
69
|
ruby-progressbar (1.10.1)
|
70
|
+
ruby2_keywords (0.0.2)
|
70
71
|
safe_yaml (1.0.5)
|
71
|
-
simplecov (0.
|
72
|
+
simplecov (0.18.1)
|
72
73
|
docile (~> 1.1)
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
sinatra (2.0.7)
|
74
|
+
simplecov-html (~> 0.11.0)
|
75
|
+
simplecov-html (0.11.0)
|
76
|
+
sinatra (2.0.8.1)
|
77
77
|
mustermann (~> 1.0)
|
78
78
|
rack (~> 2.0)
|
79
|
-
rack-protection (= 2.0.
|
79
|
+
rack-protection (= 2.0.8.1)
|
80
80
|
tilt (~> 2.0)
|
81
|
-
sinatra-contrib (2.0.
|
81
|
+
sinatra-contrib (2.0.8.1)
|
82
82
|
backports (>= 2.8.2)
|
83
83
|
multi_json
|
84
84
|
mustermann (~> 1.0)
|
85
|
-
rack-protection (= 2.0.
|
86
|
-
sinatra (= 2.0.
|
85
|
+
rack-protection (= 2.0.8.1)
|
86
|
+
sinatra (= 2.0.8.1)
|
87
87
|
tilt (~> 2.0)
|
88
88
|
thor (0.20.3)
|
89
89
|
tilt (2.0.10)
|
90
90
|
unicode-display_width (1.6.0)
|
91
|
-
webmock (3.
|
91
|
+
webmock (3.8.1)
|
92
92
|
addressable (>= 2.3.6)
|
93
93
|
crack (>= 0.3.2)
|
94
94
|
hashdiff (>= 0.4.0, < 2.0.0)
|
@@ -106,7 +106,7 @@ DEPENDENCIES
|
|
106
106
|
memory_profiler
|
107
107
|
rake (~> 13.0)
|
108
108
|
rspec (~> 3.0)
|
109
|
-
rubocop (~> 0.
|
109
|
+
rubocop (~> 0.79.0)
|
110
110
|
simplecov (~> 0.17)
|
111
111
|
sinatra (~> 2.0)
|
112
112
|
sinatra-contrib (~> 2.0)
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# StreamLines
|
2
2
|
|
3
|
+
[](https://travis-ci.com/jdlubrano/stream_lines)
|
4
|
+
|
3
5
|
An API for streaming files from remote locations one line at a time.
|
4
6
|
|
5
7
|
## Background
|
@@ -50,6 +52,39 @@ stream.each_slice(100) do |lines|
|
|
50
52
|
end
|
51
53
|
```
|
52
54
|
|
55
|
+
##### CSVs
|
56
|
+
|
57
|
+
This gem provides first-class support for streaming CSVs from a remote URL.
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
url = 'https://my.remote.file/file.csv'
|
61
|
+
stream = StreamLines::Reading::CSV.new(url)
|
62
|
+
|
63
|
+
stream.each do |row|
|
64
|
+
# each row will be an array
|
65
|
+
end
|
66
|
+
|
67
|
+
# Supports most Ruby CSV options (see ignored options below)
|
68
|
+
stream = StreamLines::Reading::CSV.new(url, headers: true)
|
69
|
+
|
70
|
+
stream.each do |row|
|
71
|
+
# each row is a CSV::Row object that you can access like row['column_name']
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
Most options that you can pass to
|
76
|
+
[Ruby's CSV library](https://ruby-doc.org/stdlib-2.6.1/libdoc/csv/rdoc/CSV.html#method-c-new)
|
77
|
+
are supported; however, the following options are explicitly ignored:
|
78
|
+
|
79
|
+
* `return_headers`
|
80
|
+
* `header_converters`
|
81
|
+
* `skip_lines`
|
82
|
+
|
83
|
+
I suspect that these options are not used terribly frequently, and each would
|
84
|
+
require additional logic in the `StreamLines::Reading::CSV#each` method.
|
85
|
+
Rather than attempting to implement sensible solutions for these options, I am
|
86
|
+
choosing to explicitly ignore them until there is enough outcry to support them.
|
87
|
+
|
53
88
|
## Development
|
54
89
|
|
55
90
|
After checking out the repo, run `bin/setup` to install dependencies.
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'csv'
|
4
|
+
require 'stream_lines/error'
|
5
|
+
require 'stream_lines/reading/stream'
|
6
|
+
|
7
|
+
module StreamLines
|
8
|
+
module Reading
|
9
|
+
class CSV
|
10
|
+
# NOTE: (jdlubrano)
|
11
|
+
# I suspect that these options are not used terribly frequently, and each
|
12
|
+
# would require additional logic in the #each method. Rather than
|
13
|
+
# attempting to implement sensible solutions for these options, I am
|
14
|
+
# choosing to explicitly ignore them until there is enough outcry to
|
15
|
+
# support them.
|
16
|
+
IGNORED_CSV_OPTIONS = %i[
|
17
|
+
return_headers
|
18
|
+
header_converters
|
19
|
+
skip_lines
|
20
|
+
].freeze
|
21
|
+
|
22
|
+
include Enumerable
|
23
|
+
|
24
|
+
def initialize(url, **csv_options)
|
25
|
+
@url = url
|
26
|
+
@csv_options = accepted_csv_options(csv_options)
|
27
|
+
@stream = Stream.new(url)
|
28
|
+
end
|
29
|
+
|
30
|
+
def each(&block)
|
31
|
+
@stream.each_with_index do |line, i|
|
32
|
+
next assign_first_row_headers(line) if i.zero? && first_row_headers?
|
33
|
+
|
34
|
+
block.call(::CSV.parse_line(line, **@csv_options))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
attr_reader :url
|
41
|
+
|
42
|
+
def first_row_headers?
|
43
|
+
@csv_options[:headers] == true
|
44
|
+
end
|
45
|
+
|
46
|
+
def assign_first_row_headers(first_line)
|
47
|
+
header_row = ::CSV.parse_line(first_line)
|
48
|
+
@csv_options[:headers] = header_row
|
49
|
+
end
|
50
|
+
|
51
|
+
def accepted_csv_options(csv_options)
|
52
|
+
csv_options.transform_keys(&:to_sym)
|
53
|
+
.delete_if { |key, _value| IGNORED_CSV_OPTIONS.include?(key) }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/lib/stream_lines/version.rb
CHANGED
data/stream_lines.gemspec
CHANGED
@@ -37,7 +37,7 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.add_development_dependency 'memory_profiler'
|
38
38
|
spec.add_development_dependency 'rake', '~> 13.0'
|
39
39
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
40
|
-
spec.add_development_dependency 'rubocop', '~> 0.
|
40
|
+
spec.add_development_dependency 'rubocop', '~> 0.79.0'
|
41
41
|
spec.add_development_dependency 'simplecov', '~> 0.17'
|
42
42
|
spec.add_development_dependency 'sinatra', '~> 2.0'
|
43
43
|
spec.add_development_dependency 'sinatra-contrib', '~> 2.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stream_lines
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joel Lubrano
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -156,14 +156,14 @@ dependencies:
|
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: 0.
|
159
|
+
version: 0.79.0
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: 0.
|
166
|
+
version: 0.79.0
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: simplecov
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -244,6 +244,7 @@ files:
|
|
244
244
|
- lib/stream_lines.rb
|
245
245
|
- lib/stream_lines/error.rb
|
246
246
|
- lib/stream_lines/reading.rb
|
247
|
+
- lib/stream_lines/reading/csv.rb
|
247
248
|
- lib/stream_lines/reading/stream.rb
|
248
249
|
- lib/stream_lines/version.rb
|
249
250
|
- stream_lines.gemspec
|
@@ -269,7 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
269
270
|
- !ruby/object:Gem::Version
|
270
271
|
version: '0'
|
271
272
|
requirements: []
|
272
|
-
rubygems_version: 3.
|
273
|
+
rubygems_version: 3.1.2
|
273
274
|
signing_key:
|
274
275
|
specification_version: 4
|
275
276
|
summary: A utility to stream lines of a file over HTTP
|