errata 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -10,7 +10,8 @@ begin
10
10
  gem.email = "seamus@abshere.net"
11
11
  gem.homepage = "http://github.com/seamusabshere/errata"
12
12
  gem.authors = ["Seamus Abshere", "Andy Rossmeissl"]
13
- %w{ activesupport remote_table }.each { |name| gem.add_dependency name }
13
+ gem.add_dependency 'activesupport', '~>2.3.4'
14
+ gem.add_dependency 'remote_table', '~>0.2.1'
14
15
  gem.require_path = "lib"
15
16
  gem.files.include %w(lib/erratum) unless gem.files.empty? # seems to fail once it's in the wild
16
17
  gem.rdoc_options << '--line-numbers' << '--inline-source'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
data/errata.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{errata}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
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{2009-11-02}
12
+ s.date = %q{2010-02-25}
13
13
  s.description = %q{Correct strings based on remote errata files}
14
14
  s.email = %q{seamus@abshere.net}
15
15
  s.extra_rdoc_files = [
@@ -51,15 +51,15 @@ Gem::Specification.new do |s|
51
51
  s.specification_version = 3
52
52
 
53
53
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
54
- s.add_runtime_dependency(%q<activesupport>, [">= 0"])
55
- s.add_runtime_dependency(%q<remote_table>, [">= 0"])
54
+ s.add_runtime_dependency(%q<activesupport>, ["~> 2.3.4"])
55
+ s.add_runtime_dependency(%q<remote_table>, ["~> 0.2.1"])
56
56
  else
57
- s.add_dependency(%q<activesupport>, [">= 0"])
58
- s.add_dependency(%q<remote_table>, [">= 0"])
57
+ s.add_dependency(%q<activesupport>, ["~> 2.3.4"])
58
+ s.add_dependency(%q<remote_table>, ["~> 0.2.1"])
59
59
  end
60
60
  else
61
- s.add_dependency(%q<activesupport>, [">= 0"])
62
- s.add_dependency(%q<remote_table>, [">= 0"])
61
+ s.add_dependency(%q<activesupport>, ["~> 2.3.4"])
62
+ s.add_dependency(%q<remote_table>, ["~> 0.2.1"])
63
63
  end
64
64
  end
65
65
 
data/lib/errata.rb CHANGED
@@ -1,5 +1,4 @@
1
- require 'rubygems'
2
- require 'activesupport'
1
+ require 'active_support'
3
2
  require 'remote_table'
4
3
  require 'erratum'
5
4
  require 'erratum/delete'
@@ -10,6 +9,8 @@ require 'erratum/transform'
10
9
  require 'erratum/truncate'
11
10
 
12
11
  class Errata
12
+ ERRATUM_TYPES = %w{delete replace simplify transform truncate}
13
+
13
14
  attr_reader :klass
14
15
 
15
16
  def initialize(options = {})
@@ -33,10 +34,10 @@ class Errata
33
34
  private
34
35
 
35
36
  def rejections
36
- @_rejections ||= @_table.rows.map { |erratum| ::Errata::Erratum::Reject.new(self, erratum) if erratum[:action] == 'reject' }.compact
37
+ @_rejections ||= @_table.rows.map { |hash| hash.symbolize_keys!; ::Errata::Erratum::Reject.new(self, hash) if hash[:action] == 'reject' }.compact
37
38
  end
38
39
 
39
40
  def corrections
40
- @_corrections ||= @_table.rows.map { |erratum| "::Errata::Erratum::#{erratum[:action].camelcase}".constantize.new(self, erratum) if %w{delete replace simplify transform truncate}.include?(erratum[:action]) }.compact
41
+ @_corrections ||= @_table.rows.map { |hash| hash.symbolize_keys!; "::Errata::Erratum::#{hash[:action].camelcase}".constantize.new(self, hash) if ERRATUM_TYPES.include?(hash[:action]) }.compact
41
42
  end
42
43
  end
data/lib/erratum.rb CHANGED
@@ -4,10 +4,10 @@ class Errata
4
4
  delegate :klass, :to => :errata
5
5
 
6
6
  def initialize(errata, options = {})
7
- raise "you can't set this from outside" if options.has_key?(:prefix)
7
+ raise "you can't set this from outside" if options[:prefix].present?
8
8
  @errata = errata
9
9
  @column = options[:section]
10
- @matching_method = "#{options[:condition].gsub(/[^a-z0-9]/i, '_').downcase}?".to_sym if options[:condition]
10
+ @matching_method = "#{options[:condition].gsub(/[^a-z0-9]/i, '_').downcase}?".to_sym if options[:condition].present?
11
11
  end
12
12
 
13
13
  def inspect
data/test/errata_test.rb CHANGED
@@ -1,34 +1,77 @@
1
1
  require 'test_helper'
2
2
 
3
- class Brewery
4
- def self.is_microbrew?(row)
5
- row[:volume] < 500
3
+ class AutomobileVariant
4
+ class << self
5
+ def transmission_is_blank?(row)
6
+ row['transmission'].blank?
7
+ end
8
+
9
+ def is_a_2007_gmc_or_chevrolet?(row)
10
+ row['year'] == 2007 and %w(GMC CHEVROLET).include? row['MFR'].upcase
11
+ end
12
+
13
+ def is_a_porsche?(row)
14
+ row.slice('MFR', 'Manufacturer', 'carline_mfr_name').any? { |k, v| v.upcase == 'PORSCHE' }
15
+ end
16
+
17
+ def is_not_a_porsche?(row)
18
+ !is_a_porsche? row
19
+ end
20
+
21
+ def is_a_mercedes_benz?(row)
22
+ row.slice('MFR', 'Manufacturer', 'carline_mfr_name').any? { |k, v| v =~ /MERCEDES/i }
23
+ end
24
+
25
+ def is_a_lexus?(row)
26
+ row.slice('MFR', 'Manufacturer', 'carline_mfr_name').any? { |k, v| v.upcase == 'LEXUS' }
27
+ end
28
+
29
+ def is_a_bmw?(row)
30
+ row.slice('MFR', 'Manufacturer', 'carline_mfr_name').any? { |k, v| v.upcase == 'BMW' }
31
+ end
32
+
33
+ def is_a_ford?(row)
34
+ row.slice('MFR', 'Manufacturer', 'carline_mfr_name').any? { |k, v| v.upcase == 'FORD' }
35
+ end
36
+
37
+ def is_a_rolls_royce_and_model_contains_bentley?(row)
38
+ is_a_rolls_royce?(row) and model_contains_bentley?(row)
39
+ end
40
+
41
+ def is_a_bentley?(row)
42
+ row.slice('MFR', 'Manufacturer', 'carline_mfr_name').any? { |k, v| v.upcase == 'BENTLEY' }
43
+ end
44
+
45
+ def is_a_rolls_royce?(row)
46
+ row.slice('MFR', 'Manufacturer', 'carline_mfr_name').any? { |k, v| v =~ /ROLLS/i }
47
+ end
48
+
49
+ def is_a_turbo_brooklands?(row)
50
+ row.slice('CAR LINE', 'carline name', 'carline_name').any? { |k, v| v =~ /TURBO R\/RL BKLDS/i }
51
+ end
52
+
53
+ def model_contains_maybach?(row)
54
+ row.slice('CAR LINE', 'carline name', 'carline_name').any? { |k, v| v =~ /MAYBACH/i }
55
+ end
56
+
57
+ def model_contains_bentley?(row)
58
+ row.slice('CAR LINE', 'carline name', 'carline_name').any? { |k, v| v =~ /BENTLEY/i }
59
+ end
6
60
  end
7
61
  end
8
62
 
9
63
  class ErrataTest < Test::Unit::TestCase
10
64
  def setup
11
- @e = Errata.new(:url => 'http://static.brighterplanet.com/science/data/transport/automobiles/make_fleet_years/errata.csv')
12
- end
13
-
14
- should "return implied matching methods" do
15
- flunk "create a fake errata for Brewery"
16
- end
17
-
18
- should "use matching methods" do
19
- flunk "create a fake errata for Brewery"
65
+ @e = Errata.new(:url => 'http://spreadsheets.google.com/pub?key=t9WkYT39zjrStx7ruCFrZJg', :klass => AutomobileVariant)
20
66
  end
21
-
67
+
22
68
  should "correct rows" do
23
- rover = { 'manufacturer_name' => 'foobar Austin Rover foobar' }
24
- mercedes = { 'manufacturer_name' => 'MERCEDES' }
25
- @e.correct!(mercedes)
26
- @e.correct!(rover)
27
- assert_equal 'Mercedes-Benz', mercedes['manufacturer_name']
28
- assert_equal 'Rover', rover['manufacturer_name']
69
+ alfa = { "carline_mfr_name"=>"ALFA ROMEO" }
70
+ @e.correct!(alfa)
71
+ assert_equal 'Alfa Romeo', alfa['carline_mfr_name']
29
72
  end
30
73
 
31
74
  should "reject rows" do
32
- assert @e.rejects?('manufacturer_name' => 'AURORA CARS')
75
+ assert @e.rejects?('carline_mfr_name' => 'AURORA CARS')
33
76
  end
34
77
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: errata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-11-02 00:00:00 -05:00
13
+ date: 2010-02-25 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -19,9 +19,9 @@ dependencies:
19
19
  version_requirement:
20
20
  version_requirements: !ruby/object:Gem::Requirement
21
21
  requirements:
22
- - - ">="
22
+ - - ~>
23
23
  - !ruby/object:Gem::Version
24
- version: "0"
24
+ version: 2.3.4
25
25
  version:
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: remote_table
@@ -29,9 +29,9 @@ dependencies:
29
29
  version_requirement:
30
30
  version_requirements: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ">="
32
+ - - ~>
33
33
  - !ruby/object:Gem::Version
34
- version: "0"
34
+ version: 0.2.1
35
35
  version:
36
36
  description: Correct strings based on remote errata files
37
37
  email: seamus@abshere.net