errata-ruby19 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +31 -0
- data/Rakefile +66 -0
- data/VERSION +1 -0
- data/errata.gemspec +65 -0
- data/lib/errata.rb +61 -0
- data/lib/erratum.rb +78 -0
- data/lib/erratum/delete.rb +24 -0
- data/lib/erratum/reject.rb +20 -0
- data/lib/erratum/replace.rb +27 -0
- data/lib/erratum/simplify.rb +31 -0
- data/lib/erratum/transform.rb +25 -0
- data/lib/erratum/truncate.rb +24 -0
- data/test/errata_test.rb +94 -0
- data/test/test_helper.rb +10 -0
- metadata +119 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Brighter Planet
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
=errata
|
2
|
+
|
3
|
+
Correct strings based on remote errata files.
|
4
|
+
|
5
|
+
==Real-life usage
|
6
|
+
|
7
|
+
Used by data_miner (http://github.com/seamusabshere/data_miner)
|
8
|
+
|
9
|
+
==Example
|
10
|
+
|
11
|
+
Taken from <tt>#{GEMDIR}/test/errata_test.rb</tt>:
|
12
|
+
|
13
|
+
errata = Errata.new(:url => 'http://static.brighterplanet.com/science/data/transport/automobiles/make_fleet_years/errata.csv')
|
14
|
+
rover = { 'manufacturer_name' => 'foobar Austin Rover foobar' }
|
15
|
+
mercedes = { 'manufacturer_name' => 'MERCEDES' }
|
16
|
+
errata.correct!(mercedes)
|
17
|
+
errata.correct!(rover)
|
18
|
+
|
19
|
+
Now you will have
|
20
|
+
|
21
|
+
rover['manufacturer_name'] #=> 'Rover' (used to be 'foobar Austin Rover foobar')
|
22
|
+
mercedes['manufacturer_name'] #=> 'Mercedes-Benz' (used to be 'MERCEDES')
|
23
|
+
|
24
|
+
==Authors
|
25
|
+
|
26
|
+
* Seamus Abshere <seamus@abshere.net>
|
27
|
+
* Andy Rossmeissl <andy@rossmeissl.net>
|
28
|
+
|
29
|
+
==Copyright
|
30
|
+
|
31
|
+
Copyright (c) 2009 Brighter Planet. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "errata-ruby19"
|
8
|
+
gem.summary = %Q{Correct strings based on remote errata files}
|
9
|
+
gem.description = %Q{Correct strings based on remote errata files}
|
10
|
+
gem.email = "seamus@abshere.net"
|
11
|
+
gem.homepage = "http://github.com/seamusabshere/errata"
|
12
|
+
gem.authors = ["Seamus Abshere", "Andy Rossmeissl"]
|
13
|
+
gem.add_dependency 'activesupport', '>=2.3.4'
|
14
|
+
gem.add_dependency 'remote_table-ruby19', '>=0.2.20'
|
15
|
+
gem.require_path = "lib"
|
16
|
+
gem.files.include %w(lib/erratum) unless gem.files.empty? # seems to fail once it's in the wild
|
17
|
+
gem.rdoc_options << '--line-numbers' << '--inline-source'
|
18
|
+
gem.rubyforge_project = "errata"
|
19
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
20
|
+
end
|
21
|
+
Jeweler::GemcutterTasks.new
|
22
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
23
|
+
rubyforge.doc_task = "rdoc"
|
24
|
+
end
|
25
|
+
rescue LoadError
|
26
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/*_test.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
begin
|
37
|
+
require 'rcov/rcovtask'
|
38
|
+
Rcov::RcovTask.new do |test|
|
39
|
+
test.libs << 'test'
|
40
|
+
test.pattern = 'test/**/*_test.rb'
|
41
|
+
test.verbose = true
|
42
|
+
end
|
43
|
+
rescue LoadError
|
44
|
+
task :rcov do
|
45
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
task :default => :test
|
53
|
+
|
54
|
+
require 'rake/rdoctask'
|
55
|
+
Rake::RDocTask.new do |rdoc|
|
56
|
+
if File.exist?('VERSION')
|
57
|
+
version = File.read('VERSION')
|
58
|
+
else
|
59
|
+
version = ""
|
60
|
+
end
|
61
|
+
|
62
|
+
rdoc.rdoc_dir = 'rdoc'
|
63
|
+
rdoc.title = "errata #{version}"
|
64
|
+
rdoc.rdoc_files.include('README*')
|
65
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
66
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.3
|
data/errata.gemspec
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{errata-ruby19}
|
8
|
+
s.version = "0.2.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Seamus Abshere", "Andy Rossmeissl"]
|
12
|
+
s.date = %q{2010-05-26}
|
13
|
+
s.description = %q{Correct strings based on remote errata files}
|
14
|
+
s.email = %q{seamus@abshere.net}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"errata.gemspec",
|
27
|
+
"lib/errata.rb",
|
28
|
+
"lib/erratum.rb",
|
29
|
+
"lib/erratum/delete.rb",
|
30
|
+
"lib/erratum/reject.rb",
|
31
|
+
"lib/erratum/replace.rb",
|
32
|
+
"lib/erratum/simplify.rb",
|
33
|
+
"lib/erratum/transform.rb",
|
34
|
+
"lib/erratum/truncate.rb",
|
35
|
+
"test/errata_test.rb",
|
36
|
+
"test/test_helper.rb"
|
37
|
+
]
|
38
|
+
s.homepage = %q{http://github.com/seamusabshere/errata}
|
39
|
+
s.rdoc_options = ["--charset=UTF-8", "--line-numbers", "--inline-source"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubyforge_project = %q{errata}
|
42
|
+
s.rubygems_version = %q{1.3.6}
|
43
|
+
s.summary = %q{Correct strings based on remote errata files}
|
44
|
+
s.test_files = [
|
45
|
+
"test/errata_test.rb",
|
46
|
+
"test/test_helper.rb"
|
47
|
+
]
|
48
|
+
|
49
|
+
if s.respond_to? :specification_version then
|
50
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
51
|
+
s.specification_version = 3
|
52
|
+
|
53
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
54
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 2.3.4"])
|
55
|
+
s.add_runtime_dependency(%q<remote_table-ruby19>, [">= 0.2.20"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.4"])
|
58
|
+
s.add_dependency(%q<remote_table-ruby19>, [">= 0.2.20"])
|
59
|
+
end
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<activesupport>, [">= 2.3.4"])
|
62
|
+
s.add_dependency(%q<remote_table-ruby19>, [">= 0.2.20"])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
data/lib/errata.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/version'
|
3
|
+
%w{
|
4
|
+
active_support/core_ext/module/delegation
|
5
|
+
active_support/core_ext/hash/keys
|
6
|
+
active_support/core_ext/hash/slice
|
7
|
+
}.each do |active_support_3_requirement|
|
8
|
+
require active_support_3_requirement
|
9
|
+
end if ActiveSupport::VERSION::MAJOR == 3
|
10
|
+
require 'remote_table'
|
11
|
+
require 'erratum'
|
12
|
+
require 'erratum/delete'
|
13
|
+
require 'erratum/reject'
|
14
|
+
require 'erratum/replace'
|
15
|
+
require 'erratum/simplify'
|
16
|
+
require 'erratum/transform'
|
17
|
+
require 'erratum/truncate'
|
18
|
+
|
19
|
+
class Errata
|
20
|
+
ERRATUM_TYPES = %w{delete replace simplify transform truncate}
|
21
|
+
|
22
|
+
attr_reader :options
|
23
|
+
|
24
|
+
# Arguments
|
25
|
+
# * <tt>:responder</tt> (required) - normally you pass this something like Guru.new, which should respond to questions like #is_a_bentley?. If you pass a string, it will be lazily constantized and a new object initialized from it; for example, 'Guru' will lead to 'Guru'.constantize.new.
|
26
|
+
# * <tt>:table</tt> - takes something that acts like a RemoteTable
|
27
|
+
# If and only if you don't pass <tt>:table</tt>, all other options will be passed to a new RemoteTable (for example, <tt>:url</tt>, etc.)
|
28
|
+
def initialize(options = {})
|
29
|
+
options.symbolize_keys!
|
30
|
+
@options = options
|
31
|
+
end
|
32
|
+
|
33
|
+
def table
|
34
|
+
@_table ||= if options[:table].present?
|
35
|
+
options[:table]
|
36
|
+
else
|
37
|
+
RemoteTable.new options.except(:responder)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def responder
|
42
|
+
@_responder ||= (options[:responder].is_a?(String) ? options[:responder].constantize.new : options[:responder])
|
43
|
+
end
|
44
|
+
|
45
|
+
def rejects?(row)
|
46
|
+
rejections.any? { |erratum| erratum.targets?(row) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def correct!(row)
|
50
|
+
corrections.each { |erratum| erratum.correct!(row) }
|
51
|
+
nil
|
52
|
+
end
|
53
|
+
|
54
|
+
def rejections
|
55
|
+
@_rejections ||= table.rows.map { |hash| hash.symbolize_keys!; ::Errata::Erratum::Reject.new(self, hash) if hash[:action] == 'reject' }.compact
|
56
|
+
end
|
57
|
+
|
58
|
+
def corrections
|
59
|
+
@_corrections ||= table.rows.map { |hash| hash.symbolize_keys!; "::Errata::Erratum::#{hash[:action].camelcase}".constantize.new(self, hash) if ERRATUM_TYPES.include?(hash[:action]) }.compact
|
60
|
+
end
|
61
|
+
end
|
data/lib/erratum.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
class Errata
|
2
|
+
class Erratum
|
3
|
+
attr_accessor :errata, :column, :options
|
4
|
+
delegate :responder, :to => :errata
|
5
|
+
|
6
|
+
def initialize(errata, options = {})
|
7
|
+
raise "you can't set this from outside" if options[:prefix].present?
|
8
|
+
@errata = errata
|
9
|
+
@column = options[:section]
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
def matching_methods
|
14
|
+
@_matching_methods ||= options[:condition].split(/\s*;\s*/).map do |method_id|
|
15
|
+
"#{method_id.strip.gsub(/[^a-z0-9]/i, '_').downcase}?"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def inspect
|
20
|
+
"<#{self.class.name}:#{object_id} responder=#{responder.to_s} column=#{column} matching_methods=#{matching_methods.inspect}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def targets?(row)
|
24
|
+
!!(conditions_match?(row) and expression_matches?(row))
|
25
|
+
end
|
26
|
+
|
27
|
+
def correct!(row, &block)
|
28
|
+
return :skipped unless targets?(row)
|
29
|
+
# old_value = row[column].to_s.dup
|
30
|
+
yield if block_given?
|
31
|
+
# unless name.demodulize.underscore == 'truncate' or name.demodulize.underscore == 'simplify'
|
32
|
+
# puts "-" * 64
|
33
|
+
# puts inspect
|
34
|
+
# puts row.inspect
|
35
|
+
# if row[column] != old_value
|
36
|
+
# puts "#{old_value} -> #{row[column]}"
|
37
|
+
# else
|
38
|
+
# puts "no change"
|
39
|
+
# end
|
40
|
+
# puts
|
41
|
+
# end
|
42
|
+
:corrected
|
43
|
+
end
|
44
|
+
|
45
|
+
def expression_matches?(row)
|
46
|
+
return true if matching_expression.blank? or column.blank?
|
47
|
+
if matching_expression.is_a?(Regexp)
|
48
|
+
matching_expression.match(row[column].to_s)
|
49
|
+
else
|
50
|
+
row[column].to_s.include?(matching_expression)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def conditions_match?(row)
|
55
|
+
matching_methods.all? { |method_id| responder.send method_id, row }
|
56
|
+
end
|
57
|
+
|
58
|
+
def set_matching_expression(options = {})
|
59
|
+
if options[:x].blank?
|
60
|
+
@matching_expression = nil
|
61
|
+
elsif options[:x].start_with?('/')
|
62
|
+
if options[:x].end_with?('i')
|
63
|
+
ci = true
|
64
|
+
options[:x] = options[:x].chop
|
65
|
+
else
|
66
|
+
ci = false
|
67
|
+
end
|
68
|
+
@matching_expression = Regexp.new(options[:x].gsub(/\A\/|\/\z/, ''), ci)
|
69
|
+
elsif /\Aabbr\((.*)\)\z/.match(options[:x])
|
70
|
+
@matching_expression = Regexp.new('(\A|\s)' + $1.split(/(\w\??)/).reject { |a| a == '' }.join('\.?\s?') + '\.?([^\w\.]|\z)', true)
|
71
|
+
elsif options[:prefix] == true
|
72
|
+
@matching_expression = Regexp.new('\A\s*' + Regexp.escape(options[:x]), true)
|
73
|
+
else
|
74
|
+
@matching_expression = options[:x]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Errata
|
2
|
+
class Erratum
|
3
|
+
class Delete < Erratum
|
4
|
+
attr_accessor :matching_expression, :backfill
|
5
|
+
|
6
|
+
def initialize(errata, options = {})
|
7
|
+
super
|
8
|
+
set_matching_expression(options)
|
9
|
+
# otherwise abbr(X) will kill the characters before and after the match
|
10
|
+
@backfill = /\Aabbr\((.*)\)\z/.match(options[:x]) ? '\1\2' : ''
|
11
|
+
end
|
12
|
+
|
13
|
+
def inspect
|
14
|
+
super + " matching_expression=#{matching_expression}>"
|
15
|
+
end
|
16
|
+
|
17
|
+
def correct!(row)
|
18
|
+
super(row) do
|
19
|
+
row[column].gsub!(matching_expression, backfill)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class Errata
|
2
|
+
class Erratum
|
3
|
+
class Reject < Erratum
|
4
|
+
attr_accessor :matching_expression
|
5
|
+
|
6
|
+
def initialize(errata, options = {})
|
7
|
+
super
|
8
|
+
set_matching_expression(options.merge(:prefix => true))
|
9
|
+
end
|
10
|
+
|
11
|
+
def inspect
|
12
|
+
super + " matching_expression=#{matching_expression}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def correct!
|
16
|
+
raise "rejections don't correct"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Errata
|
2
|
+
class Erratum
|
3
|
+
class Replace < Erratum
|
4
|
+
attr_accessor :matching_expression, :correction
|
5
|
+
|
6
|
+
def initialize(errata, options = {})
|
7
|
+
super
|
8
|
+
set_matching_expression(options)
|
9
|
+
@correction = /\Aabbr\((.*)\)\z/.match(options[:x]) ? '\1' + options[:y].to_s + '\2' : options[:y].to_s
|
10
|
+
end
|
11
|
+
|
12
|
+
def inspect
|
13
|
+
super + " matching_expression=#{matching_expression} correction=#{correction}>"
|
14
|
+
end
|
15
|
+
|
16
|
+
def correct!(row)
|
17
|
+
super(row) do
|
18
|
+
if matching_expression.blank?
|
19
|
+
row[column] = correction
|
20
|
+
else
|
21
|
+
row[column].gsub!(matching_expression, correction)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class Errata
|
2
|
+
class Erratum
|
3
|
+
class Simplify < Erratum
|
4
|
+
attr_accessor :second_column
|
5
|
+
|
6
|
+
def initialize(errata, options = {})
|
7
|
+
super
|
8
|
+
@second_column = options[:x]
|
9
|
+
end
|
10
|
+
|
11
|
+
def inspect
|
12
|
+
super + " second_column=#{second_column}>"
|
13
|
+
end
|
14
|
+
|
15
|
+
def targets?(row)
|
16
|
+
!row[column].blank? and !row[second_column].blank? and conditions_match?(row) and matching_expression(row).match(row[column])
|
17
|
+
end
|
18
|
+
|
19
|
+
def correct!(row)
|
20
|
+
super(row) do
|
21
|
+
row[column].gsub!(matching_expression(row), '')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def matching_expression(row)
|
26
|
+
@_matching_expressions ||= {}
|
27
|
+
@_matching_expressions[row[second_column]] ||= /[\s\(\[\'\"]*#{Regexp.escape(row[second_column])}[\s\)\]\'\"]*/
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Errata
|
2
|
+
class Erratum
|
3
|
+
class Transform < Erratum
|
4
|
+
ALLOWED_METHODS = %w{upcase downcase}
|
5
|
+
attr_accessor :matching_expression, :string_method
|
6
|
+
|
7
|
+
def initialize(errata, options = {})
|
8
|
+
super
|
9
|
+
set_matching_expression(options)
|
10
|
+
@string_method = options[:y]
|
11
|
+
raise "string method (#{@string_method}) needs to be in (#{ALLOWED_METHODS.join(', ')})" unless ALLOWED_METHODS.include?(@string_method)
|
12
|
+
end
|
13
|
+
|
14
|
+
def inspect
|
15
|
+
super + " matching_expression=#{matching_expression} string_method=#{string_method}>"
|
16
|
+
end
|
17
|
+
|
18
|
+
def correct!(row)
|
19
|
+
super(row) do
|
20
|
+
row[column].gsub!(matching_expression) { |match| match.send(string_method) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Errata
|
2
|
+
class Erratum
|
3
|
+
class Truncate < Erratum
|
4
|
+
attr_accessor :matching_expression, :necessary_and_sufficient_prefix
|
5
|
+
|
6
|
+
def initialize(errata, options = {})
|
7
|
+
super
|
8
|
+
@necessary_and_sufficient_prefix = options[:x]
|
9
|
+
raise "necessary_and_sufficient_prefix cannot be blank" if @necessary_and_sufficient_prefix.blank?
|
10
|
+
set_matching_expression(options.merge(:prefix => true))
|
11
|
+
end
|
12
|
+
|
13
|
+
def inspect
|
14
|
+
super + " matching_expression=#{matching_expression} necessary_and_sufficient_prefix=#{necessary_and_sufficient_prefix}>"
|
15
|
+
end
|
16
|
+
|
17
|
+
def correct!(row)
|
18
|
+
super(row) do
|
19
|
+
row[column] = necessary_and_sufficient_prefix
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/test/errata_test.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class AutomobileVariantGuru
|
4
|
+
def transmission_is_blank?(row)
|
5
|
+
row['transmission'].blank?
|
6
|
+
end
|
7
|
+
|
8
|
+
def is_a_2007_gmc_or_chevrolet?(row)
|
9
|
+
row['year'] == 2007 and %w(GMC CHEVROLET).include? row['MFR'].upcase
|
10
|
+
end
|
11
|
+
|
12
|
+
def is_a_porsche?(row)
|
13
|
+
row.slice('MFR', 'Manufacturer', 'carline_mfr_name').any? { |k, v| v.upcase == 'PORSCHE' }
|
14
|
+
end
|
15
|
+
|
16
|
+
def is_not_a_porsche?(row)
|
17
|
+
!is_a_porsche? row
|
18
|
+
end
|
19
|
+
|
20
|
+
def is_a_mercedes_benz?(row)
|
21
|
+
row.slice('MFR', 'Manufacturer', 'carline_mfr_name').any? { |k, v| v =~ /MERCEDES/i }
|
22
|
+
end
|
23
|
+
|
24
|
+
def is_a_lexus?(row)
|
25
|
+
row.slice('MFR', 'Manufacturer', 'carline_mfr_name').any? { |k, v| v.upcase == 'LEXUS' }
|
26
|
+
end
|
27
|
+
|
28
|
+
def is_a_bmw?(row)
|
29
|
+
row.slice('MFR', 'Manufacturer', 'carline_mfr_name').any? { |k, v| v.upcase == 'BMW' }
|
30
|
+
end
|
31
|
+
|
32
|
+
def is_a_ford?(row)
|
33
|
+
row.slice('MFR', 'Manufacturer', 'carline_mfr_name').any? { |k, v| v.upcase == 'FORD' }
|
34
|
+
end
|
35
|
+
|
36
|
+
def is_a_bentley?(row)
|
37
|
+
row.slice('MFR', 'Manufacturer', 'carline_mfr_name').any? { |k, v| v.upcase == 'BENTLEY' }
|
38
|
+
end
|
39
|
+
|
40
|
+
def is_a_rolls_royce?(row)
|
41
|
+
row.slice('MFR', 'Manufacturer', 'carline_mfr_name').any? { |k, v| v =~ /ROLLS/i }
|
42
|
+
end
|
43
|
+
|
44
|
+
def is_a_turbo_brooklands?(row)
|
45
|
+
row.slice('CAR LINE', 'carline name', 'carline_name').any? { |k, v| v =~ /TURBO R\/RL BKLDS/i }
|
46
|
+
end
|
47
|
+
|
48
|
+
def model_contains_maybach?(row)
|
49
|
+
row.slice('CAR LINE', 'carline name', 'carline_name').any? { |k, v| v =~ /MAYBACH/i }
|
50
|
+
end
|
51
|
+
|
52
|
+
def model_contains_bentley?(row)
|
53
|
+
row.slice('CAR LINE', 'carline name', 'carline_name').any? { |k, v| v =~ /BENTLEY/i }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class ErrataTest < Test::Unit::TestCase
|
58
|
+
def setup
|
59
|
+
@e = Errata.new :table => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=t9WkYT39zjrStx7ruCFrZJg'),
|
60
|
+
:responder => AutomobileVariantGuru.new
|
61
|
+
end
|
62
|
+
|
63
|
+
should "correct rows" do
|
64
|
+
alfa = { "carline_mfr_name"=>"ALFA ROMEO" }
|
65
|
+
@e.correct!(alfa)
|
66
|
+
assert_equal 'Alfa Romeo', alfa['carline_mfr_name']
|
67
|
+
end
|
68
|
+
|
69
|
+
should "reject rows" do
|
70
|
+
assert @e.rejects?('carline_mfr_name' => 'AURORA CARS')
|
71
|
+
end
|
72
|
+
|
73
|
+
should "lazily constantize and initialize responder" do
|
74
|
+
e = Errata.new :table => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=t9WkYT39zjrStx7ruCFrZJg'),
|
75
|
+
:responder => 'AutomobileVariantGuru'
|
76
|
+
alfa = { "carline_mfr_name"=>"ALFA ROMEO" }
|
77
|
+
e.correct!(alfa)
|
78
|
+
assert_equal 'Alfa Romeo', alfa['carline_mfr_name']
|
79
|
+
end
|
80
|
+
|
81
|
+
should "pass options to RemoteTable if no :table is specified" do
|
82
|
+
e = Errata.new :url => 'http://spreadsheets.google.com/pub?key=t9WkYT39zjrStx7ruCFrZJg',
|
83
|
+
:responder => AutomobileVariantGuru.new
|
84
|
+
alfa = { "carline_mfr_name"=>"ALFA ROMEO" }
|
85
|
+
e.correct!(alfa)
|
86
|
+
assert_equal 'Alfa Romeo', alfa['carline_mfr_name']
|
87
|
+
end
|
88
|
+
|
89
|
+
should "try multiple conditions" do
|
90
|
+
bentley = { 'carline_mfr_name' => 'ROLLS-ROYCE BENTLEY', "carline name" => 'Super Bentley' }
|
91
|
+
@e.correct!(bentley)
|
92
|
+
assert_equal 'Bentley', bentley['carline_mfr_name']
|
93
|
+
end
|
94
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: errata-ruby19
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Seamus Abshere
|
14
|
+
- Andy Rossmeissl
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-05-26 00:00:00 -05:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: activesupport
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 11
|
31
|
+
segments:
|
32
|
+
- 2
|
33
|
+
- 3
|
34
|
+
- 4
|
35
|
+
version: 2.3.4
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: remote_table-ruby19
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 63
|
47
|
+
segments:
|
48
|
+
- 0
|
49
|
+
- 2
|
50
|
+
- 20
|
51
|
+
version: 0.2.20
|
52
|
+
type: :runtime
|
53
|
+
version_requirements: *id002
|
54
|
+
description: Correct strings based on remote errata files
|
55
|
+
email: seamus@abshere.net
|
56
|
+
executables: []
|
57
|
+
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files:
|
61
|
+
- LICENSE
|
62
|
+
- README.rdoc
|
63
|
+
files:
|
64
|
+
- .document
|
65
|
+
- .gitignore
|
66
|
+
- LICENSE
|
67
|
+
- README.rdoc
|
68
|
+
- Rakefile
|
69
|
+
- VERSION
|
70
|
+
- errata.gemspec
|
71
|
+
- lib/errata.rb
|
72
|
+
- lib/erratum.rb
|
73
|
+
- lib/erratum/delete.rb
|
74
|
+
- lib/erratum/reject.rb
|
75
|
+
- lib/erratum/replace.rb
|
76
|
+
- lib/erratum/simplify.rb
|
77
|
+
- lib/erratum/transform.rb
|
78
|
+
- lib/erratum/truncate.rb
|
79
|
+
- test/errata_test.rb
|
80
|
+
- test/test_helper.rb
|
81
|
+
has_rdoc: true
|
82
|
+
homepage: http://github.com/seamusabshere/errata
|
83
|
+
licenses: []
|
84
|
+
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options:
|
87
|
+
- --charset=UTF-8
|
88
|
+
- --line-numbers
|
89
|
+
- --inline-source
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
hash: 3
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
version: "0"
|
110
|
+
requirements: []
|
111
|
+
|
112
|
+
rubyforge_project: errata
|
113
|
+
rubygems_version: 1.3.7
|
114
|
+
signing_key:
|
115
|
+
specification_version: 3
|
116
|
+
summary: Correct strings based on remote errata files
|
117
|
+
test_files:
|
118
|
+
- test/errata_test.rb
|
119
|
+
- test/test_helper.rb
|