remote_table 3.3.0 → 3.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OWNjZTdhOTQ4ZTFlM2VhMGE4NjlhMTNjZjJkNjUxYjVjZGUwZWI0OQ==
5
- data.tar.gz: !binary |-
6
- MGU0MjNmMTc4MTAzOGUzOWJhZTQ3OWRiZjQxNjZjNDVkODMyMGY2ZA==
2
+ SHA1:
3
+ metadata.gz: 50af57458cfc9beb6a37a724f127267441351407
4
+ data.tar.gz: f9fdaa022aa12c22f4bebfbb8c62bda6f5fc78c3
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ODZkODJkMmI0MmIwMDA5ZmVlYTExYTI0NTEyY2I1ZDEwNDRjZWY2ZmVlZjY1
10
- OGVkNDI3NzdkMGVlYWM3YTg3ZjU5ZDM2MmU4ZmEyMzdjOGE1Y2U2YjRkYTUz
11
- ZDUxYzIxMTllYzM4YTk1MmRiZTU1MGJkZWNiYzgwYjMzODA1ZmI=
12
- data.tar.gz: !binary |-
13
- MGY3YmU5YjA2NWMwZTQyNzk4OTM4ZGFhM2JjZTM0ODFmMzM1NTc0ZWM4N2Mz
14
- OWQwYjhlNmJhZGQ2MDFlMGMzNzY3OWIyZTk5NDJjMDZhMjFhZGQ3YmUzMTk2
15
- MWVmODJlNzEwN2U5YjE4Nzc1ZTEzYmJkMWE4M2Q2ZTQ1NmIzZjk=
6
+ metadata.gz: ce9f84c1e533c92c7d77383aa948e489c77e542b51a7e6c6a79064b64eaf1ad38a71ba35662f24068e517918eb0405e1960afaeb0c9e8d5d45a2d0d0b783a4b9
7
+ data.tar.gz: 992797ec369a10179ad2ffa5cfe30fc0ca787b366f91cb6ea090eeaff772abe9564d3b19e7dbdabca37043878060489af4c508a3923cc1d8673a7af1bb02bae7
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - jruby-19mode # JRuby in 1.9 mode
6
+ - rbx-19mode
data/CHANGELOG CHANGED
@@ -1,3 +1,15 @@
1
+ 3.3.2 / 2015-10-01
2
+
3
+ * Bug fixes
4
+
5
+ * Correctly require ActiveSupport
6
+
7
+ 3.3.1 / 2014-08-01
8
+
9
+ * Enhancements
10
+
11
+ * Support for JSON endpoints support added to the library
12
+
1
13
  3.3.0 / 2014-01-14
2
14
 
3
15
  * Breaking changes
@@ -118,6 +118,11 @@ You can call <code>symbolize_keys</code> yourself, but we don't do it automatica
118
118
  <td>The idea is to set up a <code>:row_[xpath|css]</code> and (optionally) a <code>:column_[xpath|css]</code>.</td>
119
119
  <td><a href="http://nokogiri.org/">nokogiri</a></td>
120
120
  </tr>
121
+ <tr>
122
+ <td>JSON</td>
123
+ <td>Force JSON format using <code>format: :json</code> and define root nodes using <code>root_node: 'data'</code></td>
124
+ <td><a href="http://www.ruby-doc.org/stdlib-2.0.0/libdoc/json/rdoc/JSON.html">JSON</a></td>
125
+ </tr>
121
126
  </table>
122
127
 
123
128
  ## Compression and packing
@@ -336,6 +341,9 @@ Everything is forced into UTF-8. You can improve the quality of the conversion b
336
341
  RemoteTable.new('http://www.eia.doe.gov/emeu/recs/recspubuse05/datafiles/RECS05alldata.csv',
337
342
  :headers => :upcase)
338
343
 
344
+ # Public albums from the Facebook Engineering Team
345
+ RemoteTable.new('https://graph.facebook.com/Engineering/albums', format: :json, root_node: 'data')
346
+
339
347
  # ...and more from the tests...
340
348
 
341
349
  RemoteTable.new 'http://spreadsheets.google.com/pub?key=t5HM1KbaRngmTUbntg8JwPA&single=true&gid=0'
@@ -5,6 +5,7 @@ end
5
5
 
6
6
  require 'thread'
7
7
  require 'hash_digest'
8
+ require 'active_support'
8
9
  require 'active_support/core_ext'
9
10
 
10
11
  require 'remote_table/local_copy'
@@ -20,6 +21,7 @@ require 'remote_table/fixed_width'
20
21
  require 'remote_table/html'
21
22
  require 'remote_table/xml'
22
23
  require 'remote_table/yaml'
24
+ require 'remote_table/json'
23
25
 
24
26
  class Hash
25
27
  # Added by remote_table to store a hash (think checksum) of the data with which a particular Hash is initialized.
@@ -90,6 +92,8 @@ class RemoteTable
90
92
  :xml
91
93
  when /yaml\z/, /yml\z/
92
94
  :yaml
95
+ when /json\z/
96
+ :json
93
97
  end
94
98
  end
95
99
 
@@ -141,7 +145,7 @@ class RemoteTable
141
145
  VALID = {
142
146
  :compression => [:gz, :zip, :bz2, :exe],
143
147
  :packing => [:tar],
144
- :format => [:xlsx, :xls, :delimited, :ods, :fixed_width, :html, :xml, :yaml, :csv],
148
+ :format => [:xlsx, :xls, :delimited, :ods, :fixed_width, :html, :xml, :yaml, :csv, :json],
145
149
  }
146
150
  DEFAULT = {
147
151
  :streaming => false,
@@ -247,7 +251,7 @@ class RemoteTable
247
251
  # @return [String]
248
252
  attr_reader :column_css
249
253
 
250
- # The format of the source file. Can be +:xlsx+, +:xls+, +:delimited+, +:ods+, +:fixed_width+, +:html+, +:xml+, +:yaml+.
254
+ # The format of the source file. Can be +:xlsx+, +:xls+, +:delimited+, +:ods+, +:fixed_width+, +:html+, +:xml+, +:yaml+, +:json+.
251
255
  # @return [Symbol]
252
256
  attr_reader :format
253
257
 
@@ -333,7 +337,7 @@ class RemoteTable
333
337
  # @return [Hash]
334
338
  attr_reader :errata
335
339
 
336
- # The format of the source file. Can be specified as: :xlsx, :xls, :delimited (aka :csv), :ods, :fixed_width, :html, :xml, :yaml
340
+ # The format of the source file. Can be specified as: :xlsx, :xls, :delimited (aka :csv), :ods, :fixed_width, :html, :xml, :yaml :json
337
341
  #
338
342
  # Note: treats all +docs.google.com+ and +spreadsheets.google.com+ URLs as +:delimited+.
339
343
  #
@@ -342,6 +346,13 @@ class RemoteTable
342
346
  # @return [Hash]
343
347
  attr_reader :format
344
348
 
349
+ # The root node of the json document. Specified as a string.
350
+ #
351
+ # Default: nil; no root node.
352
+ #
353
+ # @return [String]
354
+ attr_reader :root_node
355
+
345
356
  # @private
346
357
  class NullParser
347
358
  def call(row)
@@ -431,6 +442,7 @@ class RemoteTable
431
442
  @pre_select = grab settings, :pre_select
432
443
  @pre_reject = grab settings, :pre_reject
433
444
  @errata = grab settings, :errata
445
+ @root_node = grab settings, :root_node
434
446
  @parser = grab settings, :parser
435
447
 
436
448
  @other_options = settings
@@ -0,0 +1,27 @@
1
+ class RemoteTable
2
+ module Json
3
+ def _each
4
+ require 'json'
5
+
6
+ data.each do |row|
7
+ yield row
8
+ end
9
+ ensure
10
+ local_copy.cleanup
11
+ end
12
+
13
+ private
14
+
15
+ def json_string
16
+ local_copy.encoded_io.read
17
+ end
18
+
19
+ def parsed_json
20
+ ::JSON.parse(json_string)
21
+ end
22
+
23
+ def data
24
+ root_node.nil? ? parsed_json : parsed_json[root_node]
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  class RemoteTable
2
- VERSION = '3.3.0'
2
+ VERSION = '3.3.2'
3
3
  end
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.summary = %{Open local or remote XLSX, XLS, ODS, CSV (comma separated), TSV (tab separated), other delimited, fixed-width files, and Google Docs. Returns an enumerator of Arrays or Hashes, depending on whether there are headers.}
11
11
  s.description = %{Open local or remote XLSX, XLS, ODS, CSV (comma separated), TSV (tab separated), other delimited, fixed-width files, and Google Docs. Returns an enumerator of Arrays or Hashes, depending on whether there are headers.}
12
12
 
13
+ s.license = "MIT"
13
14
  s.rubyforge_project = "remotetable"
14
15
 
15
16
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
@@ -0,0 +1,10 @@
1
+ [
2
+ {
3
+ "name": "Seamus Abshere",
4
+ "city": "Madison"
5
+ },
6
+ {
7
+ "name": "Derek Kastner",
8
+ "city": "Lansing"
9
+ }
10
+ ]
@@ -0,0 +1,12 @@
1
+ {
2
+ "data": [
3
+ {
4
+ "name": "Seamus Abshere",
5
+ "city": "Madison"
6
+ },
7
+ {
8
+ "name": "Derek Kastner",
9
+ "city": "Lansing"
10
+ }
11
+ ]
12
+ }
@@ -3,6 +3,22 @@ require 'helper'
3
3
  require 'tempfile'
4
4
 
5
5
  describe RemoteTable do
6
+ it "opens a json without root" do
7
+ t = RemoteTable.new "file://#{File.expand_path('../data/data_no_root.json', __FILE__)}"
8
+ t[0]['name'].must_equal 'Seamus Abshere'
9
+ t[0]['city'].must_equal 'Madison'
10
+ t[1]['name'].must_equal 'Derek Kastner'
11
+ t[1]['city'].must_equal 'Lansing'
12
+ end
13
+
14
+ it "opens a json with root" do
15
+ t = RemoteTable.new "file://#{File.expand_path('../data/data_with_root.json', __FILE__)}", root_node: 'data'
16
+ t[0]['name'].must_equal 'Seamus Abshere'
17
+ t[0]['city'].must_equal 'Madison'
18
+ t[1]['name'].must_equal 'Derek Kastner'
19
+ t[1]['city'].must_equal 'Lansing'
20
+ end
21
+
6
22
  it "doesn't screw up UTF-8" do
7
23
  t = RemoteTable.new "file://#{File.expand_path('../data/airports.utf8.csv', __FILE__)}"
8
24
  t[3]['city'].must_equal "Puerto Inírida"
@@ -111,7 +127,8 @@ describe RemoteTable do
111
127
  'foo.html' => :html,
112
128
  'foo.xml' => :xml,
113
129
  'foo.yaml' => :yaml,
114
- 'foo.yml' => :yaml
130
+ 'foo.yml' => :yaml,
131
+ 'foo.json' => :json
115
132
  }.each do |basename, format|
116
133
  it "detects the #{format} format from the filename #{basename}" do
117
134
  RemoteTable.guess_format(basename).must_equal format
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remote_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere
@@ -9,202 +9,202 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-14 00:00:00.000000000 Z
12
+ date: 2015-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ! '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: 2.3.4
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ! '>='
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: 2.3.4
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: roo
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ! '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: '1.11'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ! '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: '1.11'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: fixed_width-multibyte
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ! '>='
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: 0.2.3
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ! '>='
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: 0.2.3
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: i18n
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ! '>='
60
+ - - ">="
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0'
63
63
  type: :runtime
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ! '>='
67
+ - - ">="
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: unix_utils
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ! '>='
74
+ - - ">="
75
75
  - !ruby/object:Gem::Version
76
76
  version: 0.0.8
77
77
  type: :runtime
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ! '>='
81
+ - - ">="
82
82
  - !ruby/object:Gem::Version
83
83
  version: 0.0.8
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: fastercsv
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - ! '>='
88
+ - - ">="
89
89
  - !ruby/object:Gem::Version
90
90
  version: 1.5.0
91
91
  type: :runtime
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - ! '>='
95
+ - - ">="
96
96
  - !ruby/object:Gem::Version
97
97
  version: 1.5.0
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: hash_digest
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ! '>='
102
+ - - ">="
103
103
  - !ruby/object:Gem::Version
104
104
  version: 1.1.3
105
105
  type: :runtime
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - ! '>='
109
+ - - ">="
110
110
  - !ruby/object:Gem::Version
111
111
  version: 1.1.3
112
112
  - !ruby/object:Gem::Dependency
113
113
  name: errata
114
114
  requirement: !ruby/object:Gem::Requirement
115
115
  requirements:
116
- - - ! '>='
116
+ - - ">="
117
117
  - !ruby/object:Gem::Version
118
118
  version: 0.2.0
119
119
  type: :development
120
120
  prerelease: false
121
121
  version_requirements: !ruby/object:Gem::Requirement
122
122
  requirements:
123
- - - ! '>='
123
+ - - ">="
124
124
  - !ruby/object:Gem::Version
125
125
  version: 0.2.0
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: minitest
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  requirements:
130
- - - ! '>='
130
+ - - ">="
131
131
  - !ruby/object:Gem::Version
132
132
  version: '0'
133
133
  type: :development
134
134
  prerelease: false
135
135
  version_requirements: !ruby/object:Gem::Requirement
136
136
  requirements:
137
- - - ! '>='
137
+ - - ">="
138
138
  - !ruby/object:Gem::Version
139
139
  version: '0'
140
140
  - !ruby/object:Gem::Dependency
141
141
  name: rake
142
142
  requirement: !ruby/object:Gem::Requirement
143
143
  requirements:
144
- - - ! '>='
144
+ - - ">="
145
145
  - !ruby/object:Gem::Version
146
146
  version: '0'
147
147
  type: :development
148
148
  prerelease: false
149
149
  version_requirements: !ruby/object:Gem::Requirement
150
150
  requirements:
151
- - - ! '>='
151
+ - - ">="
152
152
  - !ruby/object:Gem::Version
153
153
  version: '0'
154
154
  - !ruby/object:Gem::Dependency
155
155
  name: yard
156
156
  requirement: !ruby/object:Gem::Requirement
157
157
  requirements:
158
- - - ! '>='
158
+ - - ">="
159
159
  - !ruby/object:Gem::Version
160
160
  version: '0'
161
161
  type: :development
162
162
  prerelease: false
163
163
  version_requirements: !ruby/object:Gem::Requirement
164
164
  requirements:
165
- - - ! '>='
165
+ - - ">="
166
166
  - !ruby/object:Gem::Version
167
167
  version: '0'
168
168
  - !ruby/object:Gem::Dependency
169
169
  name: pry
170
170
  requirement: !ruby/object:Gem::Requirement
171
171
  requirements:
172
- - - ! '>='
172
+ - - ">="
173
173
  - !ruby/object:Gem::Version
174
174
  version: '0'
175
175
  type: :development
176
176
  prerelease: false
177
177
  version_requirements: !ruby/object:Gem::Requirement
178
178
  requirements:
179
- - - ! '>='
179
+ - - ">="
180
180
  - !ruby/object:Gem::Version
181
181
  version: '0'
182
182
  - !ruby/object:Gem::Dependency
183
183
  name: pry-rescue
184
184
  requirement: !ruby/object:Gem::Requirement
185
185
  requirements:
186
- - - ! '>='
186
+ - - ">="
187
187
  - !ruby/object:Gem::Version
188
188
  version: '0'
189
189
  type: :development
190
190
  prerelease: false
191
191
  version_requirements: !ruby/object:Gem::Requirement
192
192
  requirements:
193
- - - ! '>='
193
+ - - ">="
194
194
  - !ruby/object:Gem::Version
195
195
  version: '0'
196
196
  - !ruby/object:Gem::Dependency
197
197
  name: pry-stack_explorer
198
198
  requirement: !ruby/object:Gem::Requirement
199
199
  requirements:
200
- - - ! '>='
200
+ - - ">="
201
201
  - !ruby/object:Gem::Version
202
202
  version: '0'
203
203
  type: :development
204
204
  prerelease: false
205
205
  version_requirements: !ruby/object:Gem::Requirement
206
206
  requirements:
207
- - - ! '>='
207
+ - - ">="
208
208
  - !ruby/object:Gem::Version
209
209
  version: '0'
210
210
  description: Open local or remote XLSX, XLS, ODS, CSV (comma separated), TSV (tab
@@ -216,9 +216,10 @@ executables: []
216
216
  extensions: []
217
217
  extra_rdoc_files: []
218
218
  files:
219
- - .gitattributes
220
- - .gitignore
221
- - .yardopts
219
+ - ".gitattributes"
220
+ - ".gitignore"
221
+ - ".travis.yml"
222
+ - ".yardopts"
222
223
  - CHANGELOG
223
224
  - Gemfile
224
225
  - LICENSE
@@ -228,6 +229,7 @@ files:
228
229
  - lib/remote_table/delimited.rb
229
230
  - lib/remote_table/fixed_width.rb
230
231
  - lib/remote_table/html.rb
232
+ - lib/remote_table/json.rb
231
233
  - lib/remote_table/local_copy.rb
232
234
  - lib/remote_table/ods.rb
233
235
  - lib/remote_table/plaintext.rb
@@ -247,6 +249,8 @@ files:
247
249
  - test/data/cm.txt
248
250
  - test/data/color.csv
249
251
  - test/data/data.yml
252
+ - test/data/data_no_root.json
253
+ - test/data/data_with_root.json
250
254
  - test/data/faa-aircraft.html.bz2
251
255
  - test/data/list-en1-semic-3.neooffice.binary.ods
252
256
  - test/data/list-en1-semic-3.neooffice.iso-8859-1.csv
@@ -275,7 +279,8 @@ files:
275
279
  - test/test_remote_table.rb
276
280
  - test/test_transpose.rb
277
281
  homepage: https://github.com/seamusabshere/remote_table
278
- licenses: []
282
+ licenses:
283
+ - MIT
279
284
  metadata: {}
280
285
  post_install_message:
281
286
  rdoc_options: []
@@ -283,17 +288,17 @@ require_paths:
283
288
  - lib
284
289
  required_ruby_version: !ruby/object:Gem::Requirement
285
290
  requirements:
286
- - - ! '>='
291
+ - - ">="
287
292
  - !ruby/object:Gem::Version
288
293
  version: '0'
289
294
  required_rubygems_version: !ruby/object:Gem::Requirement
290
295
  requirements:
291
- - - ! '>='
296
+ - - ">="
292
297
  - !ruby/object:Gem::Version
293
298
  version: '0'
294
299
  requirements: []
295
300
  rubyforge_project: remotetable
296
- rubygems_version: 2.1.11
301
+ rubygems_version: 2.2.2
297
302
  signing_key:
298
303
  specification_version: 4
299
304
  summary: Open local or remote XLSX, XLS, ODS, CSV (comma separated), TSV (tab separated),
@@ -308,6 +313,8 @@ test_files:
308
313
  - test/data/cm.txt
309
314
  - test/data/color.csv
310
315
  - test/data/data.yml
316
+ - test/data/data_no_root.json
317
+ - test/data/data_with_root.json
311
318
  - test/data/faa-aircraft.html.bz2
312
319
  - test/data/list-en1-semic-3.neooffice.binary.ods
313
320
  - test/data/list-en1-semic-3.neooffice.iso-8859-1.csv