data_miner 0.4.29 → 0.4.30
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.
- data/VERSION +1 -1
- data/data_miner.gemspec +2 -2
- data/lib/data_miner/attribute.rb +1 -1
- data/lib/data_miner/import.rb +2 -1
- data/test/data_miner_test.rb +29 -0
- data/test/test_helper.rb +15 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.30
|
data/data_miner.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{data_miner}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.30"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Seamus Abshere", "Andy Rossmeissl"]
|
12
|
-
s.date = %q{2010-05-
|
12
|
+
s.date = %q{2010-05-18}
|
13
13
|
s.description = %q{Mine remote data into your ActiveRecord models. You can also perform associations and convert units.}
|
14
14
|
s.email = %q{seamus@abshere.net}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/data_miner/attribute.rb
CHANGED
@@ -224,7 +224,7 @@ module DataMiner
|
|
224
224
|
options[:static]
|
225
225
|
end
|
226
226
|
def dictionary
|
227
|
-
@_dictionary ||= Dictionary.new
|
227
|
+
@_dictionary ||= (options[:dictionary].is_a?(Dictionary) ? options[:dictionary] : Dictionary.new(options[:dictionary]))
|
228
228
|
end
|
229
229
|
def matcher
|
230
230
|
@_matcher ||= (options[:matcher].is_a?(String) ? options[:matcher].constantize.new : options[:matcher])
|
data/lib/data_miner/import.rb
CHANGED
@@ -49,6 +49,7 @@ module DataMiner
|
|
49
49
|
def run(run)
|
50
50
|
increment_counter = resource.column_names.include?('data_miner_touch_count')
|
51
51
|
log_run = resource.column_names.include?('data_miner_last_run_id')
|
52
|
+
primary_key = resource.primary_key
|
52
53
|
test_counter = 0
|
53
54
|
|
54
55
|
table.each_row do |row|
|
@@ -67,7 +68,7 @@ OUT: #{attributes.inject(Hash.new) { |memo, v| attr_name, attr = v; memo[attr_na
|
|
67
68
|
record.increment :data_miner_touch_count if increment_counter
|
68
69
|
record.data_miner_last_run = run if log_run
|
69
70
|
end
|
70
|
-
record.save!
|
71
|
+
record.save! if record.send(primary_key).present?
|
71
72
|
end
|
72
73
|
DataMiner.log_info "performed #{inspect}"
|
73
74
|
end
|
data/test/data_miner_test.rb
CHANGED
@@ -482,6 +482,19 @@ class CensusDivision < ActiveRecord::Base
|
|
482
482
|
end
|
483
483
|
end
|
484
484
|
|
485
|
+
class CensusDivisionDeux < ActiveRecord::Base
|
486
|
+
set_primary_key :number
|
487
|
+
|
488
|
+
data_miner do
|
489
|
+
import :url => 'http://www.census.gov/popest/geographic/codes02.csv', :skip => 9, :select => lambda { |row| row['Division'].to_s.strip != 'X' and row['FIPS CODE STATE'].to_s.strip == 'X'} do
|
490
|
+
key 'number', :field_name => 'Division'
|
491
|
+
store 'name', :field_name => 'Name'
|
492
|
+
store 'census_region_number', :field_name => 'Region'
|
493
|
+
store 'census_region_name', :field_name => 'Region', :dictionary => DataMiner::Dictionary.new(:input => 'number', :output => 'name', :url => 'http://data.brighterplanet.com/census_regions.csv')
|
494
|
+
end
|
495
|
+
end
|
496
|
+
end
|
497
|
+
|
485
498
|
class CrosscallingCensusRegion < ActiveRecord::Base
|
486
499
|
set_primary_key :number
|
487
500
|
|
@@ -1009,6 +1022,12 @@ class Aircraft < ActiveRecord::Base
|
|
1009
1022
|
store 'manufacturer_name', :field_name => 'Manufacturer'
|
1010
1023
|
store 'name', :field_name => 'Model'
|
1011
1024
|
end
|
1025
|
+
|
1026
|
+
import 'Brighter Planet aircraft class codes',
|
1027
|
+
:url => 'http://static.brighterplanet.com/science/data/transport/air/bts_aircraft_type/bts_aircraft_types-brighter_planet_aircraft_classes.csv' do
|
1028
|
+
key 'bts_aircraft_type_code', :field_name => 'bts_aircraft_type'
|
1029
|
+
store 'brighter_planet_aircraft_class_code'
|
1030
|
+
end
|
1012
1031
|
end
|
1013
1032
|
end
|
1014
1033
|
end
|
@@ -1110,6 +1129,16 @@ class DataMinerTest < Test::Unit::TestCase
|
|
1110
1129
|
end
|
1111
1130
|
|
1112
1131
|
if ENV['ALL'] == 'true' or ENV['FAST'] == 'true'
|
1132
|
+
should "allow specifying dictionaries explicitly" do
|
1133
|
+
CensusDivisionDeux.run_data_miner!
|
1134
|
+
assert_equal 'South Region', CensusDivisionDeux.find(5).census_region_name
|
1135
|
+
end
|
1136
|
+
|
1137
|
+
should "be able to key on things other than the primary key" do
|
1138
|
+
Aircraft.run_data_miner!
|
1139
|
+
assert_equal 'SP', Aircraft.find('DHC6').brighter_planet_aircraft_class_code
|
1140
|
+
end
|
1141
|
+
|
1113
1142
|
should "be able to synthesize rows without using a full parser class" do
|
1114
1143
|
AutomobileMakeFleetYear.run_data_miner!
|
1115
1144
|
assert AutomobileMakeFleetYear.exists?(:name => 'Alfa Romeo IP 1978')
|
data/test/test_helper.rb
CHANGED
@@ -15,7 +15,7 @@ ActiveRecord::Base.establish_connection(
|
|
15
15
|
)
|
16
16
|
|
17
17
|
ActiveSupport::Inflector.inflections do |inflect|
|
18
|
-
inflect.uncountable %w{ aircraft aircraft_deux }
|
18
|
+
inflect.uncountable %w{ aircraft aircraft_deux census_division_deux }
|
19
19
|
end
|
20
20
|
|
21
21
|
class Test::Unit::TestCase
|
@@ -138,6 +138,19 @@ ActiveRecord::Schema.define(:version => 20090819143429) do
|
|
138
138
|
end
|
139
139
|
execute 'ALTER TABLE census_divisions ADD PRIMARY KEY (number);'
|
140
140
|
|
141
|
+
create_table 'census_division_deux', :force => true, :options => 'ENGINE=InnoDB default charset=utf8', :id => false do |t|
|
142
|
+
t.integer 'number'
|
143
|
+
t.string 'name'
|
144
|
+
t.datetime 'updated_at'
|
145
|
+
t.datetime 'created_at'
|
146
|
+
t.string 'census_region_name'
|
147
|
+
t.integer 'census_region_number'
|
148
|
+
|
149
|
+
t.integer 'data_miner_touch_count'
|
150
|
+
t.integer 'data_miner_last_run_id'
|
151
|
+
end
|
152
|
+
execute 'ALTER TABLE census_division_deux ADD PRIMARY KEY (number);'
|
153
|
+
|
141
154
|
create_table 'crosscalling_census_divisions', :force => true, :options => 'ENGINE=InnoDB default charset=utf8', :id => false do |t|
|
142
155
|
t.integer 'number'
|
143
156
|
t.string 'name'
|
@@ -282,7 +295,7 @@ ActiveRecord::Schema.define(:version => 20090819143429) do
|
|
282
295
|
t.string "bts_name"
|
283
296
|
t.string "bts_aircraft_type_code"
|
284
297
|
|
285
|
-
|
298
|
+
t.string 'brighter_planet_aircraft_class_code'
|
286
299
|
# t.float 'm3'
|
287
300
|
# t.float 'm2'
|
288
301
|
# t.float 'm1'
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 30
|
9
|
+
version: 0.4.30
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Seamus Abshere
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-05-
|
18
|
+
date: 2010-05-18 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|