errata 0.2.4 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -3,3 +3,4 @@
3
3
  coverage
4
4
  rdoc
5
5
  pkg
6
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in errata.gemspec
4
+ gemspec
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Brighter Planet
1
+ Copyright (c) 2011 Brighter Planet
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
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/errata_test.rb</tt>:
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!(mercedes)
17
- errata.correct!(rover)
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) 2009 Brighter Planet. See LICENSE for details.
31
+ Copyright (c) 2011 Brighter Planet. See LICENSE for details.
data/Rakefile CHANGED
@@ -1,66 +1,23 @@
1
- require 'rubygems'
2
- require 'rake'
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/**/*_test.rb'
8
+ test.pattern = 'test/**/test_*.rb'
33
9
  test.verbose = true
34
10
  end
35
11
 
36
12
  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
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
- 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')
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 = %q{errata}
8
- s.version = "0.2.4"
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.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-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
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
53
- s.add_runtime_dependency(%q<activesupport>, [">= 2.3.4"])
54
- s.add_runtime_dependency(%q<remote_table>, [">= 0.2.31"])
55
- else
56
- s.add_dependency(%q<activesupport>, [">= 2.3.4"])
57
- s.add_dependency(%q<remote_table>, [">= 0.2.31"])
58
- end
59
- else
60
- s.add_dependency(%q<activesupport>, [">= 2.3.4"])
61
- s.add_dependency(%q<remote_table>, [">= 0.2.31"])
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,9 @@
1
+ class Errata
2
+ class Erratum
3
+ class Reject < Erratum
4
+ def correct!
5
+ raise "rejections don't correct"
6
+ end
7
+ end
8
+ end
9
+ 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,15 @@
1
+ class Errata
2
+ class Erratum
3
+ class Truncate < Erratum
4
+ def necessary_and_sufficient_prefix
5
+ options['x']
6
+ end
7
+
8
+ def correct!(row)
9
+ super(row) do
10
+ row[section] = necessary_and_sufficient_prefix.dup
11
+ end
12
+ end
13
+ end
14
+ end
15
+ 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
@@ -0,0 +1,3 @@
1
+ class Errata
2
+ VERSION = '1.0.1'
3
+ 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
- ERRATUM_TYPES = %w{delete replace simplify transform truncate}
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>: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.)
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.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
23
+ @options = options.dup
24
+ @options.stringify_keys!
39
25
  end
40
26
 
41
27
  def responder
42
- @_responder ||= (options[:responder].is_a?(String) ? options[:responder].constantize.new : options[:responder])
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
- @_rejections ||= table.rows.map { |hash| hash.symbolize_keys!; ::Errata::Erratum::Reject.new(self, hash) if hash[:action] == 'reject' }.compact
48
+ errata.select { |erratum| erratum.is_a? ::Errata::Erratum::Reject }
56
49
  end
57
50
 
58
51
  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
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
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
10
+ unless RUBY_VERSION >= '1.9'
11
+ require 'ruby-debug'
12
+ end
6
13
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'errata'))
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 'test_helper'
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 ErrataTest < Test::Unit::TestCase
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: 31
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
+ - 1
7
8
  - 0
8
- - 2
9
- - 4
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: 2010-09-30 00:00:00 -05:00
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: 41
46
+ hash: 1
47
47
  segments:
48
- - 0
49
- - 2
50
- - 31
51
- version: 0.2.31
48
+ - 1
49
+ version: "1"
52
50
  type: :runtime
53
51
  version_requirements: *id002
54
- description: Correct strings based on remote errata files
55
- email: seamus@abshere.net
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
- - LICENSE
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
- - test/errata_test.rb
80
- - test/test_helper.rb
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: http://github.com/seamusabshere/errata
123
+ homepage: https://github.com/seamusabshere/errata
83
124
  licenses: []
84
125
 
85
126
  post_install_message:
86
- rdoc_options:
87
- - --charset=UTF-8
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/errata_test.rb
119
- - test/test_helper.rb
157
+ - test/helper.rb
158
+ - test/test_old_syntax.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.2.4
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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