remote_table 2.1.2 → 3.0.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +12 -3
- data/README.markdown +1 -8
- data/lib/remote_table.rb +72 -87
- data/lib/remote_table/fixed_width.rb +5 -5
- data/lib/remote_table/local_copy.rb +1 -1
- data/lib/remote_table/plaintext.rb +3 -3
- data/lib/remote_table/processed_by_roo.rb +6 -4
- data/lib/remote_table/version.rb +1 -1
- data/remote_table.gemspec +3 -4
- data/test/{support → data}/airports.utf8.csv +0 -0
- data/test/data/color.csv +3 -0
- data/test/{fixtures → data}/data.yml +0 -0
- data/test/{support → data}/list-en1-semic-3.neooffice.binary.ods +0 -0
- data/test/{support → data}/list-en1-semic-3.neooffice.iso-8859-1.csv +0 -0
- data/test/{support → data}/list-en1-semic-3.neooffice.iso-8859-1.fixed_width-64 +0 -0
- data/test/{support → data}/list-en1-semic-3.neooffice.utf-8.csv +0 -0
- data/test/{support → data}/list-en1-semic-3.neooffice.utf-8.fixed_width-62 +0 -0
- data/test/{support → data}/list-en1-semic-3.neooffice.utf-8.html +0 -0
- data/test/{support → data}/list-en1-semic-3.neooffice.utf-8.xml +0 -0
- data/test/{support → data}/list-en1-semic-3.office-2011-for-mac-sp1-excel-95.binary.xls +0 -0
- data/test/{support → data}/list-en1-semic-3.office-2011-for-mac-sp1.binary.xls +0 -0
- data/test/{support → data}/list-en1-semic-3.office-2011-for-mac-sp1.binary.xlsx +0 -0
- data/test/{support → data}/list-en1-semic-3.office-2011-for-mac-sp1.iso-8859-1.html +0 -0
- data/test/{support → data}/list-en1-semic-3.office-2011-for-mac-sp1.mac.csv-comma +0 -0
- data/test/{support → data}/list-en1-semic-3.office-2011-for-mac-sp1.utf-8.html +0 -0
- data/test/{support → data}/list-en1-semic-3.original.iso-8859-1.csv +0 -0
- data/test/data/ranges.csv +4 -0
- data/test/test_errata.rb +2 -2
- data/test/test_local.rb +10 -0
- data/test/test_old_syntax.rb +0 -13
- data/test/test_parser.rb +24 -0
- data/test/test_remote.rb +113 -0
- data/test/test_remote_table.rb +30 -165
- data/test/test_transpose.rb +11 -0
- metadata +86 -66
- checksums.yaml +0 -15
- data/lib/remote_table/shp.rb +0 -30
- data/lib/remote_table/transformer.rb +0 -29
- data/test/test_old_transform.rb +0 -47
- data/test/test_shapefile.rb +0 -13
data/test/test_old_transform.rb
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class NaturalGasParser
|
4
|
-
def initialize(options = {})
|
5
|
-
# nothing
|
6
|
-
end
|
7
|
-
def apply(row)
|
8
|
-
virtual_rows = []
|
9
|
-
row.keys.grep(/\A(.*) Natural Gas/) do |location_column_name|
|
10
|
-
match_1 = $1
|
11
|
-
next if (price = row[location_column_name]).blank? or (date = row['Date']).blank?
|
12
|
-
if match_1 == 'U.S.'
|
13
|
-
locatable_id = 'US'
|
14
|
-
locatable_type = 'Country'
|
15
|
-
else
|
16
|
-
locatable_id = match_1 # name
|
17
|
-
locatable_type = 'State'
|
18
|
-
end
|
19
|
-
date = Time.parse(date)
|
20
|
-
new_row = ActiveSupport::OrderedHash.new
|
21
|
-
new_row['locatable_id'] = locatable_id
|
22
|
-
new_row['locatable_type'] = locatable_type
|
23
|
-
new_row['price'] = price
|
24
|
-
new_row['year'] = date.year
|
25
|
-
new_row['month'] = date.month
|
26
|
-
row_hash = RemoteTable::Transform.row_hash new_row
|
27
|
-
new_row['row_hash'] = row_hash
|
28
|
-
virtual_rows << new_row
|
29
|
-
end
|
30
|
-
virtual_rows
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe RemoteTable do
|
35
|
-
describe "when using old-style parser" do
|
36
|
-
it "open an XLS with a parser" do
|
37
|
-
t = RemoteTable.new(:url => 'http://www.eia.gov/dnav/ng/xls/ng_pri_sum_a_EPG0_FWA_DMcf_a.xls',
|
38
|
-
:sheet => 'Data 1',
|
39
|
-
:skip => 2,
|
40
|
-
:select => proc { |row| row['year'].to_i > 1989 },
|
41
|
-
:transform => { :class => NaturalGasParser })
|
42
|
-
t[0]['locatable_type'].must_equal 'Country'
|
43
|
-
t[0]['locatable_id'].must_equal 'US'
|
44
|
-
t[0].row_hash.must_be :present?
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
data/test/test_shapefile.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe RemoteTable do
|
4
|
-
it "opens a shapefile" do
|
5
|
-
t = RemoteTable.new 'http://www.nrel.gov/gis/cfm/data/GIS_Data_Technology_Specific/United_States/Solar/High_Resolution/Lower_48_DNI_High_Resolution.zip', :format => :shp, :crop => [5,5]
|
6
|
-
t[0]['upper_corner_x'].must_equal -94.89999999999999
|
7
|
-
t[0]['upper_corner_y'].must_equal 49.7
|
8
|
-
t[0]['lower_corner_x'].must_equal -94.99999999999999
|
9
|
-
t[0]['lower_corner_y'].must_equal 49.6
|
10
|
-
t[0]['DNI01'].must_equal 1269.0
|
11
|
-
t[0]['DNIANN'].must_equal 3315.0
|
12
|
-
end
|
13
|
-
end
|