data_miner 0.3.5 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.5
1
+ 0.3.6
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{data_miner}
8
- s.version = "0.3.5"
8
+ s.version = "0.3.6"
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"]
@@ -16,9 +16,9 @@ module DataMiner
16
16
  args.each { |arg| unique_indices.add arg }
17
17
  end
18
18
 
19
- def process(callback)
19
+ def process(method_name_or_block_description, &block)
20
20
  self.runnable_counter += 1
21
- runnables << DataMiner::Process.new(self, runnable_counter, callback)
21
+ runnables << DataMiner::Process.new(self, runnable_counter, method_name_or_block_description, &block)
22
22
  end
23
23
 
24
24
  def import(options = {}, &block)
@@ -1,20 +1,36 @@
1
1
  module DataMiner
2
2
  class Process
3
- attr_accessor :configuration, :position_in_run, :callback
3
+ attr_accessor :configuration, :position_in_run
4
+ attr_accessor :method_name
5
+ attr_accessor :block_description, :block
4
6
  delegate :klass, :to => :configuration
5
7
 
6
- def initialize(configuration, position_in_run, callback)
8
+ def initialize(configuration, position_in_run, method_name_or_block_description, &block)
7
9
  @configuration = configuration
8
10
  @position_in_run = position_in_run
9
- @callback = callback
11
+ if block_given?
12
+ @block_description = method_name_or_block_description
13
+ @block = block
14
+ else
15
+ @method_name = method_name
16
+ end
10
17
  end
11
18
 
12
19
  def inspect
13
- "Process(#{klass}) position #{position_in_run}"
20
+ str = "Process(#{klass}) position #{position_in_run}"
21
+ if block
22
+ str << " called :#{method_name}"
23
+ else
24
+ str << " ran block (#{block_description})"
25
+ end
14
26
  end
15
27
 
16
28
  def run(run)
17
- klass.send callback
29
+ if block
30
+ block.call
31
+ else
32
+ klass.send method_name
33
+ end
18
34
  DataMiner.logger.info "ran #{inspect}"
19
35
  end
20
36
  end
@@ -446,7 +446,11 @@ class AutomobileVariant < ActiveRecord::Base
446
446
  # derive :automobile_model_id # creates models by name
447
447
  # associate :model_year, :key => :original_automobile_model_year_year, :foreign_key => :year
448
448
  # associate :fuel_type, :key => :original_automobile_fuel_type_code, :foreign_key => :code
449
- process :set_adjusted_fuel_economy
449
+
450
+ process 'Set adjusted fuel economy' do
451
+ update_all 'fuel_efficiency_city = 1 / ((0.003259 / 0.425143707) + (1.1805 / raw_fuel_efficiency_city))'
452
+ update_all 'fuel_efficiency_highway = 1 / ((0.001376 / 0.425143707) + (1.3466 / raw_fuel_efficiency_highway))'
453
+ end
450
454
  end
451
455
 
452
456
  def name
@@ -466,11 +470,6 @@ class AutomobileVariant < ActiveRecord::Base
466
470
  end
467
471
 
468
472
  class << self
469
- def set_adjusted_fuel_economy
470
- update_all 'fuel_efficiency_city = 1 / ((0.003259 / 0.425143707) + (1.1805 / raw_fuel_efficiency_city))'
471
- update_all 'fuel_efficiency_highway = 1 / ((0.001376 / 0.425143707) + (1.3466 / raw_fuel_efficiency_highway))'
472
- end
473
-
474
473
  # the following matching methods are needed by the errata
475
474
  # per https://brighterplanet.sifterapp.com/projects/30/issues/750/comments
476
475
 
@@ -871,6 +870,14 @@ class DataMinerTest < Test::Unit::TestCase
871
870
  assert AutomobileVariant.first.row_hash.present?
872
871
  end
873
872
 
873
+ should "process a callback block instead of a method" do
874
+ AutomobileVariant.delete_all
875
+ AutomobileVariant.data_miner_config.runnables[0].run(nil)
876
+ assert !AutomobileVariant.first.fuel_efficiency_city.present?
877
+ AutomobileVariant.data_miner_config.runnables.last.run(nil)
878
+ assert AutomobileVariant.first.fuel_efficiency_city.present?
879
+ end
880
+
874
881
  # should "mine multiple classes in the correct order" do
875
882
  # DataMiner.run
876
883
  # uy = Country.find_by_iso_3166('UY')
@@ -917,7 +924,7 @@ class DataMinerTest < Test::Unit::TestCase
917
924
  assert a != b
918
925
  assert_equal b, Country.first.data_miner_last_run
919
926
  end
920
-
927
+
921
928
  unless ENV['FAST'] == 'true'
922
929
  should "import using a dictionary" do
923
930
  DataMiner.run :class_names => %w{ ResidentialEnergyConsumptionSurveyResponse }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: data_miner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere