errata 0.2.4 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/LICENSE +1 -1
- data/README.rdoc +4 -4
- data/Rakefile +12 -55
- data/errata.gemspec +21 -58
- data/lib/errata/erratum/delete.rb +16 -0
- data/lib/errata/erratum/reject.rb +9 -0
- data/lib/errata/erratum/replace.rb +19 -0
- data/lib/errata/erratum/simplify.rb +23 -0
- data/lib/errata/erratum/transform.rb +18 -0
- data/lib/errata/erratum/truncate.rb +15 -0
- data/lib/errata/erratum.rb +83 -0
- data/lib/errata/version.rb +3 -0
- data/lib/errata.rb +20 -27
- data/test/{test_helper.rb → helper.rb} +11 -4
- data/test/{errata_test.rb → test_old_syntax.rb} +2 -2
- metadata +73 -34
- data/VERSION +0 -1
- data/lib/erratum/delete.rb +0 -24
- data/lib/erratum/reject.rb +0 -20
- data/lib/erratum/replace.rb +0 -27
- data/lib/erratum/simplify.rb +0 -31
- data/lib/erratum/transform.rb +0 -25
- data/lib/erratum/truncate.rb +0 -24
- data/lib/erratum.rb +0 -78
data/.gitignore
CHANGED
data/Gemfile
ADDED
data/LICENSE
CHANGED
data/README.rdoc
CHANGED
@@ -8,13 +8,13 @@ Used by data_miner (http://github.com/seamusabshere/data_miner)
|
|
8
8
|
|
9
9
|
==Example
|
10
10
|
|
11
|
-
Taken from <tt>#{GEMDIR}/test/
|
11
|
+
Taken from <tt>#{GEMDIR}/test/test_old_syntax.rb</tt>:
|
12
12
|
|
13
13
|
errata = Errata.new(:url => 'http://static.brighterplanet.com/science/data/transport/automobiles/make_fleet_years/errata.csv')
|
14
14
|
rover = { 'manufacturer_name' => 'foobar Austin Rover foobar' }
|
15
15
|
mercedes = { 'manufacturer_name' => 'MERCEDES' }
|
16
|
-
errata.correct!
|
17
|
-
errata.correct!
|
16
|
+
errata.correct! mercedes
|
17
|
+
errata.correct! rover
|
18
18
|
|
19
19
|
Now you will have
|
20
20
|
|
@@ -28,4 +28,4 @@ Now you will have
|
|
28
28
|
|
29
29
|
==Copyright
|
30
30
|
|
31
|
-
Copyright (c)
|
31
|
+
Copyright (c) 2011 Brighter Planet. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,66 +1,23 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "errata"
|
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', '>=0.2.31'
|
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
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
28
3
|
|
4
|
+
require 'rake'
|
29
5
|
require 'rake/testtask'
|
30
6
|
Rake::TestTask.new(:test) do |test|
|
31
7
|
test.libs << 'lib' << 'test'
|
32
|
-
test.pattern = 'test
|
8
|
+
test.pattern = 'test/**/test_*.rb'
|
33
9
|
test.verbose = true
|
34
10
|
end
|
35
11
|
|
36
12
|
begin
|
37
|
-
require '
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
13
|
+
require 'rake/rdoctask'
|
14
|
+
Rake::RDocTask.new do |rdoc|
|
15
|
+
rdoc.rdoc_dir = 'rdoc'
|
16
|
+
rdoc.title = 'errata'
|
17
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
18
|
+
rdoc.rdoc_files.include('README*')
|
19
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
42
20
|
end
|
43
21
|
rescue LoadError
|
44
|
-
|
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')
|
22
|
+
puts "Rdoc is not available"
|
66
23
|
end
|
data/errata.gemspec
CHANGED
@@ -1,64 +1,27 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
1
|
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "errata/version"
|
5
4
|
|
6
5
|
Gem::Specification.new do |s|
|
7
|
-
s.name
|
8
|
-
s.version
|
6
|
+
s.name = "errata"
|
7
|
+
s.version = Errata::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Seamus Abshere", "Andy Rossmeissl"]
|
10
|
+
s.email = ["seamus@abshere.net"]
|
11
|
+
s.homepage = "https://github.com/seamusabshere/errata"
|
12
|
+
s.summary = "Correct strings based on remote errata files"
|
13
|
+
s.description = %q{Correct strings based on remote errata files.}
|
9
14
|
|
10
|
-
s.
|
11
|
-
s.authors = ["Seamus Abshere", "Andy Rossmeissl"]
|
12
|
-
s.date = %q{2010-09-30}
|
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.rubygems_version = %q{1.3.7}
|
42
|
-
s.summary = %q{Correct strings based on remote errata files}
|
43
|
-
s.test_files = [
|
44
|
-
"test/errata_test.rb",
|
45
|
-
"test/test_helper.rb"
|
46
|
-
]
|
47
|
-
|
48
|
-
if s.respond_to? :specification_version then
|
49
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
|
-
s.specification_version = 3
|
15
|
+
s.rubyforge_project = "errata"
|
51
16
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency 'activesupport', '>=2.3.4'
|
23
|
+
s.add_dependency 'remote_table', '~>1'
|
24
|
+
s.add_development_dependency 'test-unit'
|
25
|
+
s.add_development_dependency 'shoulda'
|
26
|
+
s.add_development_dependency 'ruby-debug'
|
63
27
|
end
|
64
|
-
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Errata
|
2
|
+
class Erratum
|
3
|
+
class Delete < Erratum
|
4
|
+
def backfill
|
5
|
+
# otherwise abbr(X) will kill the characters before and after the match
|
6
|
+
@backfill ||= /\Aabbr\((.*)\)\z/.match(options['x']) ? '\1\2' : ''
|
7
|
+
end
|
8
|
+
|
9
|
+
def correct!(row)
|
10
|
+
super(row) do
|
11
|
+
row[section].gsub! matching_expression, backfill
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Errata
|
2
|
+
class Erratum
|
3
|
+
class Replace < Erratum
|
4
|
+
def correction
|
5
|
+
@correction ||= /\Aabbr\((.*)\)\z/.match(options['x']) ? '\1' + options['y'].to_s + '\2' : options['y'].to_s
|
6
|
+
end
|
7
|
+
|
8
|
+
def correct!(row)
|
9
|
+
super(row) do
|
10
|
+
if matching_expression.blank?
|
11
|
+
row[section] = correction.dup
|
12
|
+
else
|
13
|
+
row[section].gsub! matching_expression, correction
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Errata
|
2
|
+
class Erratum
|
3
|
+
class Simplify < Erratum
|
4
|
+
def second_section
|
5
|
+
options['x']
|
6
|
+
end
|
7
|
+
|
8
|
+
def targets?(row)
|
9
|
+
!row[section].blank? and !row[second_section].blank? and conditions_match?(row) and special_matcher(row).match(row[section])
|
10
|
+
end
|
11
|
+
|
12
|
+
def correct!(row)
|
13
|
+
super(row) do
|
14
|
+
row[section].gsub! special_matcher(row), ''
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def special_matcher(row)
|
19
|
+
/[\s\(\[\'\"]*#{::Regexp.escape(row[second_section])}[\s\)\]\'\"]*/
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class Errata
|
2
|
+
class Erratum
|
3
|
+
class Transform < Erratum
|
4
|
+
ALLOWED_METHODS = %w{upcase downcase}
|
5
|
+
|
6
|
+
def string_method
|
7
|
+
raise %{string method "#{options['y']}" not allowed} unless ALLOWED_METHODS.include? options['y']
|
8
|
+
options['y']
|
9
|
+
end
|
10
|
+
|
11
|
+
def correct!(row)
|
12
|
+
super(row) do
|
13
|
+
row[section].gsub!(matching_expression) { |match| match.send string_method }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
class Errata
|
2
|
+
class Erratum
|
3
|
+
autoload :Delete, 'errata/erratum/delete'
|
4
|
+
autoload :Reject, 'errata/erratum/reject'
|
5
|
+
autoload :Replace, 'errata/erratum/replace'
|
6
|
+
autoload :Simplify, 'errata/erratum/simplify'
|
7
|
+
autoload :Transform, 'errata/erratum/transform'
|
8
|
+
autoload :Truncate, 'errata/erratum/truncate'
|
9
|
+
|
10
|
+
attr_reader :errata
|
11
|
+
attr_reader :options
|
12
|
+
|
13
|
+
def initialize(errata, options = {})
|
14
|
+
@errata = errata
|
15
|
+
@options = options.dup
|
16
|
+
end
|
17
|
+
|
18
|
+
def section
|
19
|
+
options['section']
|
20
|
+
end
|
21
|
+
|
22
|
+
def responder
|
23
|
+
errata.responder
|
24
|
+
end
|
25
|
+
|
26
|
+
def matching_methods
|
27
|
+
@matching_methods ||= options['condition'].split(/\s*;\s*/).map do |method_id|
|
28
|
+
"#{method_id.strip.gsub(/[^a-z0-9]/i, '_').downcase}?"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def targets?(row)
|
33
|
+
!!(conditions_match?(row) and expression_matches?(row))
|
34
|
+
end
|
35
|
+
|
36
|
+
def correct!(row, &blk)
|
37
|
+
return :skipped unless targets? row
|
38
|
+
yield if block_given?
|
39
|
+
:corrected
|
40
|
+
end
|
41
|
+
|
42
|
+
def expression_matches?(row)
|
43
|
+
return true if matching_expression.blank? or section.blank?
|
44
|
+
if matching_expression.is_a? ::Regexp
|
45
|
+
matching_expression.match row[section].to_s
|
46
|
+
else
|
47
|
+
row[section].to_s.include? matching_expression
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def conditions_match?(row)
|
52
|
+
matching_methods.all? { |method_id| responder.send method_id, row }
|
53
|
+
end
|
54
|
+
|
55
|
+
def matching_expression
|
56
|
+
return @_matching_expression[0] if @_matching_expression.is_a? ::Array
|
57
|
+
@_matching_expression = []
|
58
|
+
@_matching_expression[0] = if options['x'].blank?
|
59
|
+
nil
|
60
|
+
elsif options['x'].start_with? '/'
|
61
|
+
if options['x'].end_with? 'i'
|
62
|
+
ci = true
|
63
|
+
expr = options['x'].chop
|
64
|
+
else
|
65
|
+
ci = false
|
66
|
+
expr = options['x'].dup
|
67
|
+
end
|
68
|
+
expr.gsub! /\A\/|\/\z/, ''
|
69
|
+
::Regexp.new expr, ci
|
70
|
+
elsif /\Aabbr\((.*)\)\z/.match options['x']
|
71
|
+
abbr = $1.split(/(\w\??)/).reject { |a| a == '' }.join('\.?\s?') + '\.?([^\w\.]|\z)'
|
72
|
+
expr = '(\A|\s)' + abbr
|
73
|
+
::Regexp.new expr, true
|
74
|
+
elsif %w{reject truncate}.include? options['action']
|
75
|
+
expr = '\A\s*' + ::Regexp.escape(options['x'])
|
76
|
+
::Regexp.new expr, true
|
77
|
+
else
|
78
|
+
options['x']
|
79
|
+
end
|
80
|
+
@_matching_expression[0]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
data/lib/errata.rb
CHANGED
@@ -1,45 +1,31 @@
|
|
1
1
|
require 'active_support'
|
2
2
|
require 'active_support/version'
|
3
3
|
%w{
|
4
|
-
active_support/core_ext/module/delegation
|
5
4
|
active_support/core_ext/hash/keys
|
6
5
|
active_support/core_ext/hash/slice
|
7
6
|
}.each do |active_support_3_requirement|
|
8
7
|
require active_support_3_requirement
|
9
|
-
end if ActiveSupport::VERSION::MAJOR == 3
|
8
|
+
end if ::ActiveSupport::VERSION::MAJOR == 3
|
10
9
|
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
10
|
|
19
11
|
class Errata
|
20
|
-
|
12
|
+
autoload :Erratum, 'errata/erratum'
|
13
|
+
|
14
|
+
ERRATUM_TYPES = %w{delete replace simplify transform truncate reject}
|
21
15
|
|
22
16
|
attr_reader :options
|
23
17
|
|
24
18
|
# Arguments
|
25
|
-
# * <tt
|
26
|
-
# * <tt
|
27
|
-
# If and only if you don't pass <tt
|
19
|
+
# * <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.
|
20
|
+
# * <tt>'table'</tt> - takes something that acts like a RemoteTable
|
21
|
+
# 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
22
|
def initialize(options = {})
|
29
|
-
options.
|
30
|
-
@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
|
23
|
+
@options = options.dup
|
24
|
+
@options.stringify_keys!
|
39
25
|
end
|
40
26
|
|
41
27
|
def responder
|
42
|
-
|
28
|
+
options['responder'].is_a?(::String) ? options['responder'].constantize.new : options['responder']
|
43
29
|
end
|
44
30
|
|
45
31
|
def rejects?(row)
|
@@ -50,12 +36,19 @@ class Errata
|
|
50
36
|
corrections.each { |erratum| erratum.correct!(row) }
|
51
37
|
nil
|
52
38
|
end
|
53
|
-
|
39
|
+
|
40
|
+
def errata
|
41
|
+
@errata ||= (options['table'] ? options['table'] : ::RemoteTable.new(options.except('responder'))).map do |erratum_description|
|
42
|
+
next unless ERRATUM_TYPES.include? erratum_description['action']
|
43
|
+
"::Errata::Erratum::#{erratum_description['action'].camelcase}".constantize.new self, erratum_description
|
44
|
+
end.compact
|
45
|
+
end
|
46
|
+
|
54
47
|
def rejections
|
55
|
-
|
48
|
+
errata.select { |erratum| erratum.is_a? ::Errata::Erratum::Reject }
|
56
49
|
end
|
57
50
|
|
58
51
|
def corrections
|
59
|
-
|
52
|
+
errata.select { |erratum| not erratum.is_a? ::Errata::Erratum::Reject }
|
60
53
|
end
|
61
54
|
end
|
@@ -1,10 +1,17 @@
|
|
1
1
|
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
unless RUBY_VERSION >= '1.9'
|
4
|
+
gem 'fastercsv'
|
5
|
+
require 'fastercsv'
|
6
|
+
end
|
7
|
+
Bundler.setup
|
2
8
|
require 'test/unit'
|
3
9
|
require 'shoulda'
|
4
|
-
|
5
|
-
|
10
|
+
unless RUBY_VERSION >= '1.9'
|
11
|
+
require 'ruby-debug'
|
12
|
+
end
|
6
13
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
7
|
-
|
8
|
-
|
14
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
15
|
+
require 'errata'
|
9
16
|
class Test::Unit::TestCase
|
10
17
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'helper'
|
2
2
|
|
3
3
|
class AutomobileVariantGuru
|
4
4
|
def transmission_is_blank?(row)
|
@@ -54,7 +54,7 @@ class AutomobileVariantGuru
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
class
|
57
|
+
class TestOldSyntax < Test::Unit::TestCase
|
58
58
|
def setup
|
59
59
|
@e = Errata.new :table => RemoteTable.new(:url => 'http://spreadsheets.google.com/pub?key=t9WkYT39zjrStx7ruCFrZJg'),
|
60
60
|
:responder => AutomobileVariantGuru.new
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: errata
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.2.4
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Seamus Abshere
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2011-01-25 00:00:00 -06:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -41,52 +41,91 @@ dependencies:
|
|
41
41
|
requirement: &id002 !ruby/object:Gem::Requirement
|
42
42
|
none: false
|
43
43
|
requirements:
|
44
|
-
- -
|
44
|
+
- - ~>
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
hash:
|
46
|
+
hash: 1
|
47
47
|
segments:
|
48
|
-
-
|
49
|
-
|
50
|
-
- 31
|
51
|
-
version: 0.2.31
|
48
|
+
- 1
|
49
|
+
version: "1"
|
52
50
|
type: :runtime
|
53
51
|
version_requirements: *id002
|
54
|
-
|
55
|
-
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: test-unit
|
54
|
+
prerelease: false
|
55
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
hash: 3
|
61
|
+
segments:
|
62
|
+
- 0
|
63
|
+
version: "0"
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: shoulda
|
68
|
+
prerelease: false
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
type: :development
|
79
|
+
version_requirements: *id004
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: ruby-debug
|
82
|
+
prerelease: false
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
type: :development
|
93
|
+
version_requirements: *id005
|
94
|
+
description: Correct strings based on remote errata files.
|
95
|
+
email:
|
96
|
+
- seamus@abshere.net
|
56
97
|
executables: []
|
57
98
|
|
58
99
|
extensions: []
|
59
100
|
|
60
|
-
extra_rdoc_files:
|
61
|
-
|
62
|
-
- README.rdoc
|
101
|
+
extra_rdoc_files: []
|
102
|
+
|
63
103
|
files:
|
64
104
|
- .document
|
65
105
|
- .gitignore
|
106
|
+
- Gemfile
|
66
107
|
- LICENSE
|
67
108
|
- README.rdoc
|
68
109
|
- Rakefile
|
69
|
-
- VERSION
|
70
110
|
- errata.gemspec
|
71
111
|
- 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
|
-
-
|
80
|
-
- test/
|
112
|
+
- lib/errata/erratum.rb
|
113
|
+
- lib/errata/erratum/delete.rb
|
114
|
+
- lib/errata/erratum/reject.rb
|
115
|
+
- lib/errata/erratum/replace.rb
|
116
|
+
- lib/errata/erratum/simplify.rb
|
117
|
+
- lib/errata/erratum/transform.rb
|
118
|
+
- lib/errata/erratum/truncate.rb
|
119
|
+
- lib/errata/version.rb
|
120
|
+
- test/helper.rb
|
121
|
+
- test/test_old_syntax.rb
|
81
122
|
has_rdoc: true
|
82
|
-
homepage:
|
123
|
+
homepage: https://github.com/seamusabshere/errata
|
83
124
|
licenses: []
|
84
125
|
|
85
126
|
post_install_message:
|
86
|
-
rdoc_options:
|
87
|
-
|
88
|
-
- --line-numbers
|
89
|
-
- --inline-source
|
127
|
+
rdoc_options: []
|
128
|
+
|
90
129
|
require_paths:
|
91
130
|
- lib
|
92
131
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -109,11 +148,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
148
|
version: "0"
|
110
149
|
requirements: []
|
111
150
|
|
112
|
-
rubyforge_project:
|
151
|
+
rubyforge_project: errata
|
113
152
|
rubygems_version: 1.3.7
|
114
153
|
signing_key:
|
115
154
|
specification_version: 3
|
116
155
|
summary: Correct strings based on remote errata files
|
117
156
|
test_files:
|
118
|
-
- test/
|
119
|
-
- test/
|
157
|
+
- test/helper.rb
|
158
|
+
- test/test_old_syntax.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.2.4
|
data/lib/erratum/delete.rb
DELETED
@@ -1,24 +0,0 @@
|
|
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
|
data/lib/erratum/reject.rb
DELETED
@@ -1,20 +0,0 @@
|
|
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
|
data/lib/erratum/replace.rb
DELETED
@@ -1,27 +0,0 @@
|
|
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
|
data/lib/erratum/simplify.rb
DELETED
@@ -1,31 +0,0 @@
|
|
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
|
data/lib/erratum/transform.rb
DELETED
@@ -1,25 +0,0 @@
|
|
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
|
data/lib/erratum/truncate.rb
DELETED
@@ -1,24 +0,0 @@
|
|
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/lib/erratum.rb
DELETED
@@ -1,78 +0,0 @@
|
|
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
|