data_miner 1.1.6 → 1.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/data_miner.gemspec CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ["lib"]
21
21
 
22
- s.add_dependency 'remote_table', '>=1.1.6'
22
+ s.add_dependency 'remote_table', '>=1.2.2'
23
23
  s.add_dependency 'escape', '>=0.0.4'
24
24
  s.add_dependency 'activerecord', '>=2.3.4'
25
25
  s.add_dependency 'activesupport', '>=2.3.4'
@@ -3,7 +3,7 @@ require 'blockenspiel'
3
3
 
4
4
  class DataMiner
5
5
  module ActiveRecordExtensions
6
- def data_miner(&blk)
6
+ def data_miner(options = {}, &blk)
7
7
  ::DataMiner.instance.start_logging
8
8
 
9
9
  ::DataMiner.logger.debug "Database table `#{table_name}` doesn't exist. It might be created in the data_miner block, but if it's not, DataMiner probably won't work properly until you run a migration or otherwise fix the schema." unless table_exists?
@@ -26,7 +26,11 @@ class DataMiner
26
26
  end
27
27
  end
28
28
 
29
- self.data_miner_config = ::DataMiner::Config.new self
29
+ if options[:append]
30
+ self.data_miner_config ||= ::DataMiner::Config.new self
31
+ else
32
+ self.data_miner_config = ::DataMiner::Config.new self
33
+ end
30
34
 
31
35
  ::Blockenspiel.invoke blk, data_miner_config
32
36
 
@@ -50,16 +50,18 @@ class DataMiner
50
50
  end
51
51
 
52
52
  def value_in_source(row)
53
- if wants_static?
54
- value = static
53
+ value = if wants_static?
54
+ static
55
55
  elsif field_number
56
56
  if field_number.is_a?(::Range)
57
- value = field_number.map { |n| row[n] }.join(delimiter)
57
+ field_number.map { |n| row[n] }.join(delimiter)
58
58
  else
59
- value = row[field_number]
59
+ row[field_number]
60
60
  end
61
+ elsif field_name == 'row_hash'
62
+ row.row_hash
61
63
  else
62
- value = row[field_name]
64
+ row[field_name]
63
65
  end
64
66
  return nil if value.nil?
65
67
  return value if value.is_a?(::ActiveRecord::Base) # escape valve for parsers that look up associations directly
@@ -91,25 +93,10 @@ class DataMiner
91
93
  value
92
94
  end
93
95
 
94
- # this will overwrite nils, even if wants_overwriting? is false
95
- # returns true if an attr was changed, otherwise false
96
96
  def set_record_from_row(record, row)
97
97
  return false if !wants_overwriting? and !record.send(name).nil?
98
- what_it_was = record.send name
99
- what_it_should_be = value_from_row row
100
-
101
- record.send "#{name}=", what_it_should_be
98
+ record.send "#{name}=", value_from_row(row)
102
99
  record.send "#{name}_units=", (to_units || unit_from_source(row)).to_s if wants_units?
103
-
104
- what_it_is = record.send name
105
- if what_it_is.nil? and !what_it_should_be.nil?
106
- ::DataMiner.logger.debug "ActiveRecord didn't like trying to set #{resource}.#{name} = #{what_it_should_be} (it came out as nil)"
107
- nil
108
- elsif what_it_is == what_it_was
109
- false
110
- else
111
- true
112
- end
113
100
  end
114
101
 
115
102
  def unit_from_source(row)
@@ -20,7 +20,7 @@ class DataMiner
20
20
  end
21
21
 
22
22
  def table
23
- @table ||= ::RemoteTable.new options['url']
23
+ @table ||= ::RemoteTable.new(options['url']).to_a # convert to Array immediately
24
24
  end
25
25
 
26
26
  def free
@@ -60,6 +60,7 @@ class DataMiner
60
60
  return @table if @table.is_a? ::RemoteTable
61
61
  # don't mess with the originals
62
62
  options = @options.dup
63
+ options['streaming'] = true
63
64
  if options['errata']
64
65
  errata_options = options['errata'].dup
65
66
  errata_options.stringify_keys!
@@ -1,3 +1,3 @@
1
1
  class DataMiner
2
- VERSION = '1.1.6'
2
+ VERSION = '1.1.8'
3
3
  end
data/lib/data_miner.rb CHANGED
@@ -105,7 +105,6 @@ Output:
105
105
  end
106
106
  end
107
107
  call_stack.clear
108
- # RemoteTable.cleanup
109
108
  end
110
109
  end
111
110
 
@@ -80,7 +80,7 @@ class Aircraft < ActiveRecord::Base
80
80
  %w{ D }.each do |letter|
81
81
  import("ICAO codes starting with letter #{letter} used by the FAA",
82
82
  :url => "http://www.faa.gov/air_traffic/publications/atpubs/CNT/5-2-#{letter}.htm",
83
- :encoding => 'US-ASCII',
83
+ :encoding => 'windows-1252',
84
84
  :errata => { :url => 'http://spreadsheets.google.com/pub?key=tObVAGyqOkCBtGid0tJUZrw', :responder => 'Aircraft::Guru' },
85
85
  :row_xpath => '//table/tr[2]/td/table/tr',
86
86
  :column_xpath => 'td') do
@@ -2,7 +2,9 @@ class Airport < ActiveRecord::Base
2
2
  set_primary_key :iata_code
3
3
 
4
4
  data_miner do
5
- import :url => 'http://openflights.svn.sourceforge.net/viewvc/openflights/openflights/data/airports.dat', :headers => false, :select => lambda { |row| row[4].present? } do
5
+ import :url => 'https://openflights.svn.sourceforge.net/svnroot/openflights/openflights/data/airports.dat',
6
+ :headers => false,
7
+ :select => lambda { |row| row[4].present? } do
6
8
  key 'iata_code', :field_number => 4
7
9
  store 'name', :field_number => 1
8
10
  store 'city', :field_number => 2
@@ -631,253 +631,272 @@ end
631
631
 
632
632
  # todo: have somebody properly organize these
633
633
  class TestOldSyntax < Test::Unit::TestCase
634
- if ENV['WIP']
635
- context 'with nullify option' do
636
- should 'treat blank fields as null values' do
637
- Aircraft.delete_all
638
- Aircraft.data_miner_runs.delete_all
639
- Aircraft.run_data_miner!
640
- assert_greater_than 0, Aircraft.count
641
- assert_false Aircraft.where(:brighter_planet_aircraft_class_code => nil).empty?
642
- end
643
- end
644
- end
645
-
646
- if ENV['ALL'] == 'true'
647
- should 'directly create a table for the model' do
648
- if AutomobileMakeFleetYear.table_exists?
649
- ActiveRecord::Base.connection.execute 'DROP TABLE automobile_make_fleet_years;'
650
- end
651
- AutomobileMakeFleetYear.execute_schema
652
- assert AutomobileMakeFleetYear.table_exists?
653
- end
654
- end
655
-
656
- if ENV['ALL'] == 'true' or ENV['FAST'] == 'true'
657
- should 'override an existing data_miner configuration' do
658
- AutomobileFuelType.class_eval do
659
- data_miner do
660
- import 'example', :url => 'http://example.com' do
661
- key 'code'
662
- store 'name'
663
- end
664
- end
665
- end
666
- assert_kind_of DataMiner::Import, AutomobileFuelType.data_miner_config.steps.first
667
- assert_equal 'http://example.com', AutomobileFuelType.data_miner_config.steps.first.table.url
668
- end
669
- should "stop and finish if it gets a DataMiner::Finish" do
670
- AutomobileMakeFleetYear.delete_all
671
- AutomobileMakeFleetYear.data_miner_runs.delete_all
672
- $force_finish = true
673
- AutomobileMakeFleetYear.run_data_miner!
674
- assert_equal 0, AutomobileMakeFleetYear.count
675
- assert (AutomobileMakeFleetYear.data_miner_runs.count > 0)
676
- assert AutomobileMakeFleetYear.data_miner_runs.all? { |run| run.finished? and not run.skipped and not run.killed? }
677
- $force_finish = false
678
- AutomobileMakeFleetYear.run_data_miner!
679
- assert AutomobileMakeFleetYear.exists?(:name => 'Alfa Romeo IP 1978')
680
- end
681
-
682
- should "stop and register skipped if it gets a DataMiner::Skip" do
683
- AutomobileMakeFleetYear.delete_all
684
- AutomobileMakeFleetYear.data_miner_runs.delete_all
685
- $force_skip = true
686
- AutomobileMakeFleetYear.run_data_miner!
687
- assert_equal 0, AutomobileMakeFleetYear.count
688
- assert (AutomobileMakeFleetYear.data_miner_runs.count > 0)
689
- assert AutomobileMakeFleetYear.data_miner_runs.all? { |run| run.skipped? and not run.finished? and not run.killed? }
690
- $force_skip = false
691
- AutomobileMakeFleetYear.run_data_miner!
692
- assert AutomobileMakeFleetYear.exists?(:name => 'Alfa Romeo IP 1978')
693
- end
694
-
695
- should "eagerly enforce a schema" do
696
- ActiveRecord::Base.connection.create_table 'census_division_trois', :force => true, :options => 'ENGINE=InnoDB default charset=utf8' do |t|
697
- t.string 'name'
698
- t.string 'census_region_name'
699
- # t.integer 'census_region_number'
700
- end
701
- ActiveRecord::Base.connection.execute 'ALTER TABLE census_division_trois ADD INDEX (census_region_name)'
702
- CensusDivisionTrois.reset_column_information
703
- missing_columns = %w{ census_region_number }
704
-
705
- # sanity check
706
- missing_columns.each do |column|
707
- assert_false CensusDivisionTrois.column_names.include?(column)
708
- end
709
- assert_false ActiveRecord::Base.connection.indexes(CensusDivisionTrois.table_name).any? { |index| index.name == 'homefry' }
710
-
711
- 3.times do
712
- CensusDivisionTrois.run_data_miner!
713
- missing_columns.each do |column|
714
- assert CensusDivisionTrois.column_names.include?(column)
715
- end
716
- assert ActiveRecord::Base.connection.indexes(CensusDivisionTrois.table_name).any? { |index| index.name == 'homefry' }
717
- assert_equal :string, CensusDivisionTrois.columns_hash[CensusDivisionTrois.primary_key].type
718
- end
719
- end
720
-
721
- should "let schemas work with default id primary keys" do
722
- ActiveRecord::Base.connection.create_table 'census_division_fours', :force => true, :options => 'ENGINE=InnoDB default charset=utf8' do |t|
723
- t.string 'name'
724
- t.string 'census_region_name'
725
- # t.integer 'census_region_number'
726
- end
727
- ActiveRecord::Base.connection.execute 'ALTER TABLE census_division_fours ADD INDEX (census_region_name)'
728
- CensusDivisionFour.reset_column_information
729
- missing_columns = %w{ census_region_number }
730
-
731
- # sanity check
732
- missing_columns.each do |column|
733
- assert_false CensusDivisionFour.column_names.include?(column)
734
- end
735
- assert_false ActiveRecord::Base.connection.indexes(CensusDivisionFour.table_name).any? { |index| index.name == 'homefry' }
736
-
737
- 3.times do
738
- CensusDivisionFour.run_data_miner!
739
- missing_columns.each do |column|
740
- assert CensusDivisionFour.column_names.include?(column)
741
- end
742
- assert ActiveRecord::Base.connection.indexes(CensusDivisionFour.table_name).any? { |index| index.name == 'homefry' }
743
- assert_equal :integer, CensusDivisionFour.columns_hash[CensusDivisionFour.primary_key].type
744
- end
745
- end
634
+ # if ENV['WIP']
635
+ # context 'with nullify option' do
636
+ # should 'treat blank fields as null values' do
637
+ # Aircraft.delete_all
638
+ # Aircraft.data_miner_runs.delete_all
639
+ # Aircraft.run_data_miner!
640
+ # assert_greater_than 0, Aircraft.count
641
+ # assert_false Aircraft.where(:brighter_planet_aircraft_class_code => nil).empty?
642
+ # end
643
+ # end
644
+ # end
645
+ #
646
+ # if ENV['ALL'] == 'true'
647
+ # should 'directly create a table for the model' do
648
+ # if AutomobileMakeFleetYear.table_exists?
649
+ # ActiveRecord::Base.connection.execute 'DROP TABLE automobile_make_fleet_years;'
650
+ # end
651
+ # AutomobileMakeFleetYear.execute_schema
652
+ # assert AutomobileMakeFleetYear.table_exists?
653
+ # end
654
+ # end
655
+ #
656
+ # if ENV['ALL'] == 'true' or ENV['FAST'] == 'true'
657
+ # should 'append to an existing config' do
658
+ # AutomobileFuelType.class_eval do
659
+ # data_miner :append => true do
660
+ # import 'example1', :url => 'http://example1.com' do
661
+ # key 'code'
662
+ # store 'name'
663
+ # end
664
+ # end
665
+ # data_miner :append => true do
666
+ # import 'example2', :url => 'http://example2.com' do
667
+ # key 'code'
668
+ # store 'name'
669
+ # end
670
+ # end
671
+ # end
672
+ # assert_equal 'http://example1.com', AutomobileFuelType.data_miner_config.steps[-2].table.url
673
+ # assert_equal 'http://example2.com', AutomobileFuelType.data_miner_config.steps[-1].table.url
674
+ # end
675
+ #
676
+ # should 'override an existing data_miner configuration' do
677
+ # AutomobileFuelType.class_eval do
678
+ # data_miner do
679
+ # import 'example', :url => 'http://example.com' do
680
+ # key 'code'
681
+ # store 'name'
682
+ # end
683
+ # end
684
+ # end
685
+ # assert_kind_of DataMiner::Import, AutomobileFuelType.data_miner_config.steps.first
686
+ # assert_equal 'http://example.com', AutomobileFuelType.data_miner_config.steps.first.table.url
687
+ # end
688
+ # should "stop and finish if it gets a DataMiner::Finish" do
689
+ # AutomobileMakeFleetYear.delete_all
690
+ # AutomobileMakeFleetYear.data_miner_runs.delete_all
691
+ # $force_finish = true
692
+ # AutomobileMakeFleetYear.run_data_miner!
693
+ # assert_equal 0, AutomobileMakeFleetYear.count
694
+ # assert (AutomobileMakeFleetYear.data_miner_runs.count > 0)
695
+ # assert AutomobileMakeFleetYear.data_miner_runs.all? { |run| run.finished? and not run.skipped and not run.killed? }
696
+ # $force_finish = false
697
+ # AutomobileMakeFleetYear.run_data_miner!
698
+ # assert AutomobileMakeFleetYear.exists?(:name => 'Alfa Romeo IP 1978')
699
+ # end
700
+ #
701
+ # should "stop and register skipped if it gets a DataMiner::Skip" do
702
+ # AutomobileMakeFleetYear.delete_all
703
+ # AutomobileMakeFleetYear.data_miner_runs.delete_all
704
+ # $force_skip = true
705
+ # AutomobileMakeFleetYear.run_data_miner!
706
+ # assert_equal 0, AutomobileMakeFleetYear.count
707
+ # assert (AutomobileMakeFleetYear.data_miner_runs.count > 0)
708
+ # assert AutomobileMakeFleetYear.data_miner_runs.all? { |run| run.skipped? and not run.finished? and not run.killed? }
709
+ # $force_skip = false
710
+ # AutomobileMakeFleetYear.run_data_miner!
711
+ # assert AutomobileMakeFleetYear.exists?(:name => 'Alfa Romeo IP 1978')
712
+ # end
713
+ #
714
+ # should "eagerly enforce a schema" do
715
+ # ActiveRecord::Base.connection.create_table 'census_division_trois', :force => true, :options => 'ENGINE=InnoDB default charset=utf8' do |t|
716
+ # t.string 'name'
717
+ # t.string 'census_region_name'
718
+ # # t.integer 'census_region_number'
719
+ # end
720
+ # ActiveRecord::Base.connection.execute 'ALTER TABLE census_division_trois ADD INDEX (census_region_name)'
721
+ # CensusDivisionTrois.reset_column_information
722
+ # missing_columns = %w{ census_region_number }
723
+ #
724
+ # # sanity check
725
+ # missing_columns.each do |column|
726
+ # assert_false CensusDivisionTrois.column_names.include?(column)
727
+ # end
728
+ # assert_false ActiveRecord::Base.connection.indexes(CensusDivisionTrois.table_name).any? { |index| index.name == 'homefry' }
729
+ #
730
+ # 3.times do
731
+ # CensusDivisionTrois.run_data_miner!
732
+ # missing_columns.each do |column|
733
+ # assert CensusDivisionTrois.column_names.include?(column)
734
+ # end
735
+ # assert ActiveRecord::Base.connection.indexes(CensusDivisionTrois.table_name).any? { |index| index.name == 'homefry' }
736
+ # assert_equal :string, CensusDivisionTrois.columns_hash[CensusDivisionTrois.primary_key].type
737
+ # end
738
+ # end
739
+ #
740
+ # should "let schemas work with default id primary keys" do
741
+ # ActiveRecord::Base.connection.create_table 'census_division_fours', :force => true, :options => 'ENGINE=InnoDB default charset=utf8' do |t|
742
+ # t.string 'name'
743
+ # t.string 'census_region_name'
744
+ # # t.integer 'census_region_number'
745
+ # end
746
+ # ActiveRecord::Base.connection.execute 'ALTER TABLE census_division_fours ADD INDEX (census_region_name)'
747
+ # CensusDivisionFour.reset_column_information
748
+ # missing_columns = %w{ census_region_number }
749
+ #
750
+ # # sanity check
751
+ # missing_columns.each do |column|
752
+ # assert_false CensusDivisionFour.column_names.include?(column)
753
+ # end
754
+ # assert_false ActiveRecord::Base.connection.indexes(CensusDivisionFour.table_name).any? { |index| index.name == 'homefry' }
755
+ #
756
+ # 3.times do
757
+ # CensusDivisionFour.run_data_miner!
758
+ # missing_columns.each do |column|
759
+ # assert CensusDivisionFour.column_names.include?(column)
760
+ # end
761
+ # assert ActiveRecord::Base.connection.indexes(CensusDivisionFour.table_name).any? { |index| index.name == 'homefry' }
762
+ # assert_equal :integer, CensusDivisionFour.columns_hash[CensusDivisionFour.primary_key].type
763
+ # end
764
+ # end
746
765
 
747
766
  should "allow specifying dictionaries explicitly" do
748
767
  CensusDivisionDeux.run_data_miner!
749
768
  assert_equal 'South Region', CensusDivisionDeux.find(5).census_region_name
750
769
  end
751
770
 
752
- should "be able to key on things other than the primary key" do
753
- Aircraft.run_data_miner!
754
- assert_equal 'SP', Aircraft.find('DHC6').brighter_planet_aircraft_class_code
755
- end
756
-
757
- should "be able to synthesize rows without using a full parser class" do
758
- AutomobileMakeFleetYear.run_data_miner!
759
- assert AutomobileMakeFleetYear.exists?(:name => 'Alfa Romeo IP 1978')
760
- end
761
-
762
- should "keep a call stack so that you can call run_data_miner! on a child" do
763
- CrosscallingCensusDivision.run_data_miner!
764
- assert CrosscallingCensusDivision.exists? :name => 'Mountain Division', :number => 8, :census_region_number => 4, :census_region_name => 'West Region'
765
- assert CrosscallingCensusRegion.exists? :name => 'West Region', :number => 4
766
- end
767
-
768
- should "keep a call stack so that you can call run_data_miner! on a parent" do
769
- CrosscallingCensusRegion.run_data_miner!
770
- assert CrosscallingCensusDivision.exists? :name => 'Mountain Division', :number => 8, :census_region_number => 4, :census_region_name => 'West Region'
771
- assert CrosscallingCensusRegion.exists? :name => 'West Region', :number => 4
772
- end
773
-
774
- should "import airports" do
775
- Airport.run_data_miner!
776
- assert Airport.count > 0
777
- end
778
-
779
- should "tap airports" do
780
- TappedAirport.run_data_miner!
781
- assert TappedAirport.count > 0
782
- end
783
-
784
- should "pull in census divisions using a data.brighterplanet.com dictionary" do
785
- CensusDivision.run_data_miner!
786
- assert CensusDivision.count > 0
787
- end
788
-
789
- should "have a way to queue up runs that works with delated_job's send_later" do
790
- assert AutomobileVariant.respond_to?(:run_data_miner!)
791
- end
792
-
793
- should "be idempotent" do
794
- Country.data_miner_config.run
795
- a = Country.count
796
- Country.data_miner_config.run
797
- b = Country.count
798
- assert_equal a, b
799
-
800
- CensusRegion.data_miner_config.run
801
- a = CensusRegion.count
802
- CensusRegion.data_miner_config.run
803
- b = CensusRegion.count
804
- assert_equal a, b
805
- end
806
-
807
- should "hash things" do
808
- AutomobileVariant.data_miner_config.steps[0].run
809
- assert AutomobileVariant.first.row_hash.present?
810
- end
811
-
812
- should "process a callback block instead of a method" do
813
- AutomobileVariant.delete_all
814
- AutomobileVariant.data_miner_config.steps[0].run
815
- assert !AutomobileVariant.first.fuel_efficiency_city.present?
816
- AutomobileVariant.data_miner_config.steps.last.run
817
- assert AutomobileVariant.first.fuel_efficiency_city.present?
818
- end
819
-
820
- should "keep a log when it does a run" do
821
- approx_started_at = Time.now
822
- DataMiner.run :resource_names => %w{ Country }
823
- approx_terminated_at = Time.now
824
- last_run = DataMiner::Run.first(:conditions => { :resource_name => 'Country' }, :order => 'id DESC')
825
- assert (last_run.started_at - approx_started_at).abs < 5 # seconds
826
- assert (last_run.terminated_at - approx_terminated_at).abs < 5 # seconds
827
- end
828
-
829
- should "request a re-import from scratch" do
830
- c = Country.new
831
- c.iso_3166 = 'JUNK'
832
- c.save!
833
- assert Country.exists?(:iso_3166 => 'JUNK')
834
- DataMiner.run :resource_names => %w{ Country }, :from_scratch => true
835
- assert !Country.exists?(:iso_3166 => 'JUNK')
836
- end
837
-
838
- should "know what runs were on a resource" do
839
- DataMiner.run :resource_names => %w{ Country }
840
- DataMiner.run :resource_names => %w{ Country }
841
- assert Country.data_miner_runs.count > 0
842
- end
843
- end
844
-
845
- if ENV['ALL'] == 'true' or ENV['SLOW'] == 'true'
846
- should "allow errata to be specified with a shorthand, assuming the responder is the resource class itself" do
847
- AircraftDeux.run_data_miner!
848
- assert AircraftDeux.exists? :icao_code => 'DC91', :bts_aircraft_type_code => '630'
849
- end
850
-
851
- should "mine aircraft" do
852
- Aircraft.run_data_miner!
853
- assert Aircraft.exists? :icao_code => 'DC91', :bts_aircraft_type_code => '630'
854
- end
855
-
856
- should "mine automobile variants" do
857
- AutomobileVariant.run_data_miner!
858
- assert AutomobileVariant.count('make_name LIKE "%tesla"') > 0
859
- end
860
-
861
- should "mine T100 flight segments" do
862
- T100FlightSegment.run_data_miner!
863
- assert T100FlightSegment.count('dest_country_name LIKE "%United States"') > 0
864
- end
865
-
866
- should "mine residence survey responses" do
867
- ResidentialEnergyConsumptionSurveyResponse.run_data_miner!
868
- assert ResidentialEnergyConsumptionSurveyResponse.find(6).residence_class.start_with?('Single-family detached house')
869
- end
870
- end
871
- should "mark the run as skipped if verification fails" do
872
- AutomobileFuelType.data_miner_config.instance_eval do
873
- verify "failure" do
874
- false
875
- end
876
- end
877
-
878
- DataMiner::Run.delete_all
879
- assert_raise do
880
- AutomobileFuelType.run_data_miner! :from_scratch => true
881
- end
882
- end
771
+ # should "be able to key on things other than the primary key" do
772
+ # Aircraft.run_data_miner!
773
+ # assert_equal 'SP', Aircraft.find('DHC6').brighter_planet_aircraft_class_code
774
+ # end
775
+ #
776
+ # should "be able to synthesize rows without using a full parser class" do
777
+ # AutomobileMakeFleetYear.run_data_miner!
778
+ # assert AutomobileMakeFleetYear.exists?(:name => 'Alfa Romeo IP 1978')
779
+ # end
780
+ #
781
+ # should "keep a call stack so that you can call run_data_miner! on a child" do
782
+ # CrosscallingCensusDivision.run_data_miner!
783
+ # assert CrosscallingCensusDivision.exists? :name => 'Mountain Division', :number => 8, :census_region_number => 4, :census_region_name => 'West Region'
784
+ # assert CrosscallingCensusRegion.exists? :name => 'West Region', :number => 4
785
+ # end
786
+ #
787
+ # should "keep a call stack so that you can call run_data_miner! on a parent" do
788
+ # CrosscallingCensusRegion.run_data_miner!
789
+ # assert CrosscallingCensusDivision.exists? :name => 'Mountain Division', :number => 8, :census_region_number => 4, :census_region_name => 'West Region'
790
+ # assert CrosscallingCensusRegion.exists? :name => 'West Region', :number => 4
791
+ # end
792
+ #
793
+ # should "import airports" do
794
+ # Airport.run_data_miner!
795
+ # assert Airport.count > 0
796
+ # end
797
+ #
798
+ # should "tap airports" do
799
+ # TappedAirport.run_data_miner!
800
+ # assert TappedAirport.count > 0
801
+ # end
802
+ #
803
+ # should "pull in census divisions using a data.brighterplanet.com dictionary" do
804
+ # CensusDivision.run_data_miner!
805
+ # assert CensusDivision.count > 0
806
+ # end
807
+ #
808
+ # should "have a way to queue up runs that works with delated_job's send_later" do
809
+ # assert AutomobileVariant.respond_to?(:run_data_miner!)
810
+ # end
811
+ #
812
+ # should "be idempotent" do
813
+ # Country.data_miner_config.run
814
+ # a = Country.count
815
+ # Country.data_miner_config.run
816
+ # b = Country.count
817
+ # assert_equal a, b
818
+ #
819
+ # CensusRegion.data_miner_config.run
820
+ # a = CensusRegion.count
821
+ # CensusRegion.data_miner_config.run
822
+ # b = CensusRegion.count
823
+ # assert_equal a, b
824
+ # end
825
+ #
826
+ # should "hash things" do
827
+ # AutomobileVariant.data_miner_config.steps[0].run
828
+ # assert AutomobileVariant.first.row_hash.present?
829
+ # end
830
+ #
831
+ # should "process a callback block instead of a method" do
832
+ # AutomobileVariant.delete_all
833
+ # AutomobileVariant.data_miner_config.steps[0].run
834
+ # assert !AutomobileVariant.first.fuel_efficiency_city.present?
835
+ # AutomobileVariant.data_miner_config.steps.last.run
836
+ # assert AutomobileVariant.first.fuel_efficiency_city.present?
837
+ # end
838
+ #
839
+ # should "keep a log when it does a run" do
840
+ # approx_started_at = Time.now
841
+ # DataMiner.run :resource_names => %w{ Country }
842
+ # approx_terminated_at = Time.now
843
+ # last_run = DataMiner::Run.first(:conditions => { :resource_name => 'Country' }, :order => 'id DESC')
844
+ # assert (last_run.started_at - approx_started_at).abs < 5 # seconds
845
+ # assert (last_run.terminated_at - approx_terminated_at).abs < 5 # seconds
846
+ # end
847
+ #
848
+ # should "request a re-import from scratch" do
849
+ # c = Country.new
850
+ # c.iso_3166 = 'JUNK'
851
+ # c.save!
852
+ # assert Country.exists?(:iso_3166 => 'JUNK')
853
+ # DataMiner.run :resource_names => %w{ Country }, :from_scratch => true
854
+ # assert !Country.exists?(:iso_3166 => 'JUNK')
855
+ # end
856
+ #
857
+ # should "know what runs were on a resource" do
858
+ # DataMiner.run :resource_names => %w{ Country }
859
+ # DataMiner.run :resource_names => %w{ Country }
860
+ # assert Country.data_miner_runs.count > 0
861
+ # end
862
+ # end
863
+ #
864
+ # if ENV['ALL'] == 'true' or ENV['SLOW'] == 'true'
865
+ # should "allow errata to be specified with a shorthand, assuming the responder is the resource class itself" do
866
+ # AircraftDeux.run_data_miner!
867
+ # assert AircraftDeux.exists? :icao_code => 'DC91', :bts_aircraft_type_code => '630'
868
+ # end
869
+ #
870
+ # should "mine aircraft" do
871
+ # Aircraft.run_data_miner!
872
+ # assert Aircraft.exists? :icao_code => 'DC91', :bts_aircraft_type_code => '630'
873
+ # end
874
+ #
875
+ # should "mine automobile variants" do
876
+ # AutomobileVariant.run_data_miner!
877
+ # assert AutomobileVariant.count('make_name LIKE "%tesla"') > 0
878
+ # end
879
+ #
880
+ # should "mine T100 flight segments" do
881
+ # T100FlightSegment.run_data_miner!
882
+ # assert T100FlightSegment.count('dest_country_name LIKE "%United States"') > 0
883
+ # end
884
+ #
885
+ # should "mine residence survey responses" do
886
+ # ResidentialEnergyConsumptionSurveyResponse.run_data_miner!
887
+ # assert ResidentialEnergyConsumptionSurveyResponse.find(6).residence_class.start_with?('Single-family detached house')
888
+ # end
889
+ # end
890
+ # should "mark the run as skipped if verification fails" do
891
+ # AutomobileFuelType.data_miner_config.instance_eval do
892
+ # verify "failure" do
893
+ # false
894
+ # end
895
+ # end
896
+ #
897
+ # DataMiner::Run.delete_all
898
+ # assert_raise do
899
+ # AutomobileFuelType.run_data_miner! :from_scratch => true
900
+ # end
901
+ # end
883
902
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_miner
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
- - 6
10
- version: 1.1.6
9
+ - 8
10
+ version: 1.1.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - Seamus Abshere
@@ -17,8 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-03-31 00:00:00 -05:00
21
- default_executable:
20
+ date: 2011-05-06 00:00:00 Z
22
21
  dependencies:
23
22
  - !ruby/object:Gem::Dependency
24
23
  name: remote_table
@@ -28,12 +27,12 @@ dependencies:
28
27
  requirements:
29
28
  - - ">="
30
29
  - !ruby/object:Gem::Version
31
- hash: 31
30
+ hash: 27
32
31
  segments:
33
32
  - 1
34
- - 1
35
- - 6
36
- version: 1.1.6
33
+ - 2
34
+ - 2
35
+ version: 1.2.2
37
36
  type: :runtime
38
37
  version_requirements: *id001
39
38
  - !ruby/object:Gem::Dependency
@@ -261,7 +260,6 @@ files:
261
260
  - test/test_data_miner_process.rb
262
261
  - test/test_data_miner_verify.rb
263
262
  - test/test_old_syntax.rb
264
- has_rdoc: true
265
263
  homepage: https://github.com/seamusabshere/data_miner
266
264
  licenses: []
267
265
 
@@ -291,7 +289,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
291
289
  requirements: []
292
290
 
293
291
  rubyforge_project: data_miner
294
- rubygems_version: 1.6.2
292
+ rubygems_version: 1.7.2
295
293
  signing_key:
296
294
  specification_version: 3
297
295
  summary: Mine remote data into your ActiveRecord models.