remote_table 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +2 -0
- data/CHANGELOG +7 -0
- data/README.markdown +1 -3
- data/lib/remote_table/local_copy.rb +2 -1
- data/lib/remote_table/plaintext.rb +7 -2
- data/lib/remote_table/version.rb +1 -1
- data/lib/remote_table.rb +7 -16
- data/test/test_remote_table.rb +4 -0
- metadata +3 -2
data/.yardopts
ADDED
data/CHANGELOG
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
2.0.1 / 2012-05-16
|
2
|
+
|
3
|
+
* Enhancements
|
4
|
+
|
5
|
+
* For single-string transliteration to UTF-8, use ActiveSupport::Inflector.transliterate instead of Iconv - possibly a future-proof solution.
|
6
|
+
* For whole-file transliteration to UTF-8, warn users if iconv binary is not available in their $PATH.
|
7
|
+
|
1
8
|
2.0.0 / 2012-05-08
|
2
9
|
|
3
10
|
* Breaking changes
|
data/README.markdown
CHANGED
@@ -21,11 +21,9 @@ It's also a big part of
|
|
21
21
|
## Example
|
22
22
|
|
23
23
|
>> require 'remote_table'
|
24
|
-
remote_table.rb:8:in `<top (required)>': iconv will be deprecated in the future, use String#encode instead.
|
25
|
-
[remote_table] Apologies - using iconv because Ruby 1.9.x's String#encode doesn't have transliteration tables (yet)
|
26
24
|
=> true
|
27
25
|
>> t = RemoteTable.new 'http://www.fueleconomy.gov/FEG/epadata/98guide6.zip', :filename => '98guide6.csv'
|
28
|
-
=> #<RemoteTable:0x00000101b87390 @download_count_mutex=#<Mutex:0x00000101b87228>, @
|
26
|
+
=> #<RemoteTable:0x00000101b87390 @download_count_mutex=#<Mutex:0x00000101b87228>, @extend_bang_mutex=#<Mutex:0x00000101b871d8>, @errata_mutex=#<Mutex:0x00000101b871b0>, @cache=[], @download_count=0, @url="http://www.fueleconomy.gov/FEG/epadata/98guide6.zip", @format=nil, @headers=:first_row, @compression=:zip, @packing=nil, @streaming=false, @warn_on_multiple_downloads=true, @delimiter=",", @sheet=nil, @keep_blank_rows=false, @form_data=nil, @skip=0, @internal_encoding="UTF-8", @row_xpath=nil, @column_xpath=nil, @row_css=nil, @column_css=nil, @glob=nil, @filename="98guide6.csv", @transform_settings=nil, @cut=nil, @crop=nil, @schema=nil, @schema_name=nil, @pre_select=nil, @pre_reject=nil, @errata_settings=nil, @other_options={}, @transformer=#<RemoteTable::Transformer:0x00000101b8c2f0 @t=#<RemoteTable:0x00000101b87390 ...>, @legacy_transformer_mutex=#<Mutex:0x00000101b8c2a0>>, @local_copy=#<RemoteTable::LocalCopy:0x00000101b8bf58 @t=#<RemoteTable:0x00000101b87390 ...>, @encoded_io_mutex=#<Mutex:0x00000101b8be18>, @generate_mutex=#<Mutex:0x00000101b8bdc8>>>
|
29
27
|
>> t.rows.length
|
30
28
|
=> 806
|
31
29
|
>> t.rows.first.length
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'fileutils'
|
2
|
+
require 'unix_utils'
|
2
3
|
|
3
4
|
class RemoteTable
|
4
5
|
# Helper methods that act on plaintext files before they are parsed
|
@@ -15,12 +16,16 @@ class RemoteTable
|
|
15
16
|
local_copy.in_place :perl, "s/#{CONSIDERED_HARMFUL.join('//g; s/')}//g"
|
16
17
|
end
|
17
18
|
|
18
|
-
# No matter what the file encoding is SUPPOSED to be, run it through iconv to make sure it's UTF-8
|
19
|
+
# No matter what the file encoding is SUPPOSED to be, run it through the system iconv binary to make sure it's UTF-8
|
19
20
|
#
|
20
21
|
# @example
|
21
22
|
# iconv -c -t UTF-8//TRANSLIT -f WINDOWS-1252
|
22
23
|
def transliterate_whole_file_to_utf8!
|
23
|
-
|
24
|
+
if ::UnixUtils.available?('iconv')
|
25
|
+
local_copy.in_place :iconv, RemoteTable::EXTERNAL_ENCODING_ICONV, internal_encoding
|
26
|
+
else
|
27
|
+
::Kernel.warn %{[remote_table] iconv not available in your $PATH, not performing transliteration}
|
28
|
+
end
|
24
29
|
# now that we've force-transliterated to UTF-8, act as though this is what the user had specified
|
25
30
|
@internal_encoding = RemoteTable::EXTERNAL_ENCODING
|
26
31
|
end
|
data/lib/remote_table/version.rb
CHANGED
data/lib/remote_table.rb
CHANGED
@@ -5,16 +5,11 @@ end
|
|
5
5
|
|
6
6
|
require 'thread'
|
7
7
|
|
8
|
-
require 'iconv'
|
9
|
-
if RUBY_VERSION >= '1.9'
|
10
|
-
# for an excellent explanation see http://blog.segment7.net/2010/12/17/from-iconv-iconv-to-string-encode
|
11
|
-
Kernel.warn "[remote_table] Apologies - using iconv because Ruby 1.9.x's String#encode doesn't have transliteration tables (yet)"
|
12
|
-
end
|
13
|
-
|
14
8
|
require 'active_support'
|
15
9
|
require 'active_support/version'
|
16
10
|
if ::ActiveSupport::VERSION::MAJOR >= 3
|
17
11
|
require 'active_support/core_ext'
|
12
|
+
require 'active_support/inflector/transliterate'
|
18
13
|
end
|
19
14
|
require 'hash_digest'
|
20
15
|
|
@@ -149,8 +144,11 @@ class RemoteTable
|
|
149
144
|
|
150
145
|
# The URL of the local or remote file.
|
151
146
|
#
|
152
|
-
#
|
153
|
-
#
|
147
|
+
# @example Local
|
148
|
+
# file:///Users/myuser/Desktop/holidays.csv
|
149
|
+
#
|
150
|
+
# @example Remote
|
151
|
+
# http://data.brighterplanet.com/countries.csv
|
154
152
|
#
|
155
153
|
# @return [String]
|
156
154
|
attr_reader :url
|
@@ -347,7 +345,6 @@ class RemoteTable
|
|
347
345
|
# :pre_select => proc { |row| row['Vehicle Age'].strip =~ /^\d+$/ }
|
348
346
|
def initialize(*args)
|
349
347
|
@download_count_mutex = ::Mutex.new
|
350
|
-
@iconv_mutex = ::Mutex.new
|
351
348
|
@extend_bang_mutex = ::Mutex.new
|
352
349
|
@errata_mutex = ::Mutex.new
|
353
350
|
|
@@ -509,15 +506,9 @@ class RemoteTable
|
|
509
506
|
!!@fully_cached
|
510
507
|
end
|
511
508
|
|
512
|
-
def iconv
|
513
|
-
@iconv || @iconv_mutex.synchronize do
|
514
|
-
@iconv ||= ::Iconv.new(EXTERNAL_ENCODING_ICONV, internal_encoding)
|
515
|
-
end
|
516
|
-
end
|
517
|
-
|
518
509
|
def transliterate_to_utf8(str)
|
519
510
|
if str.is_a?(::String)
|
520
|
-
|
511
|
+
::ActiveSupport::Inflector.transliterate str
|
521
512
|
end
|
522
513
|
end
|
523
514
|
|
data/test/test_remote_table.rb
CHANGED
@@ -150,4 +150,8 @@ describe RemoteTable do
|
|
150
150
|
t[4]['col1'].must_equal "Manage Multiple Incentive Programs for Participants"
|
151
151
|
end
|
152
152
|
|
153
|
+
it "doesn't get confused by :format => nil" do
|
154
|
+
t = RemoteTable.new :url => 'http://www.fueleconomy.gov/FEG/epadata/00data.zip', :filename => 'G6080900.xls', :format => nil
|
155
|
+
t[0]['Class'].must_equal 'TWO SEATERS'
|
156
|
+
end
|
153
157
|
end
|
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: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-05-
|
13
|
+
date: 2012-05-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -135,6 +135,7 @@ extra_rdoc_files: []
|
|
135
135
|
files:
|
136
136
|
- .gitattributes
|
137
137
|
- .gitignore
|
138
|
+
- .yardopts
|
138
139
|
- CHANGELOG
|
139
140
|
- Gemfile
|
140
141
|
- LICENSE
|