errata 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/errata.gemspec +2 -2
- data/lib/errata.rb +1 -5
- data/lib/erratum/simplify.rb +1 -1
- data/lib/erratum.rb +12 -7
- data/test/errata_test.rb +6 -4
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.2
|
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.2.
|
8
|
+
s.version = "0.2.2"
|
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{2010-05-
|
12
|
+
s.date = %q{2010-05-26}
|
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 = [
|
data/lib/errata.rb
CHANGED
@@ -50,11 +50,7 @@ class Errata
|
|
50
50
|
corrections.each { |erratum| erratum.correct!(row) }
|
51
51
|
nil
|
52
52
|
end
|
53
|
-
|
54
|
-
def implied_matching_methods
|
55
|
-
(rejections + corrections).map { |erratum| erratum.matching_method }.compact.uniq
|
56
|
-
end
|
57
|
-
|
53
|
+
|
58
54
|
def rejections
|
59
55
|
@_rejections ||= table.rows.map { |hash| hash.symbolize_keys!; ::Errata::Erratum::Reject.new(self, hash) if hash[:action] == 'reject' }.compact
|
60
56
|
end
|
data/lib/erratum/simplify.rb
CHANGED
@@ -13,7 +13,7 @@ class Errata
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def targets?(row)
|
16
|
-
!row[column].blank? and !row[second_column].blank? and
|
16
|
+
!row[column].blank? and !row[second_column].blank? and conditions_match?(row) and matching_expression(row).match(row[column])
|
17
17
|
end
|
18
18
|
|
19
19
|
def correct!(row)
|
data/lib/erratum.rb
CHANGED
@@ -1,21 +1,27 @@
|
|
1
1
|
class Errata
|
2
2
|
class Erratum
|
3
|
-
attr_accessor :errata, :column, :
|
3
|
+
attr_accessor :errata, :column, :options
|
4
4
|
delegate :responder, :to => :errata
|
5
5
|
|
6
6
|
def initialize(errata, options = {})
|
7
7
|
raise "you can't set this from outside" if options[:prefix].present?
|
8
8
|
@errata = errata
|
9
9
|
@column = options[:section]
|
10
|
-
@
|
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
|
11
17
|
end
|
12
18
|
|
13
19
|
def inspect
|
14
|
-
"<#{self.class.name}:#{object_id} responder=#{responder.to_s} column=#{column}
|
20
|
+
"<#{self.class.name}:#{object_id} responder=#{responder.to_s} column=#{column} matching_methods=#{matching_methods.inspect}"
|
15
21
|
end
|
16
22
|
|
17
23
|
def targets?(row)
|
18
|
-
!!(
|
24
|
+
!!(conditions_match?(row) and expression_matches?(row))
|
19
25
|
end
|
20
26
|
|
21
27
|
def correct!(row, &block)
|
@@ -45,9 +51,8 @@ class Errata
|
|
45
51
|
end
|
46
52
|
end
|
47
53
|
|
48
|
-
def
|
49
|
-
|
50
|
-
responder.send(matching_method, row)
|
54
|
+
def conditions_match?(row)
|
55
|
+
matching_methods.all? { |method_id| responder.send method_id, row }
|
51
56
|
end
|
52
57
|
|
53
58
|
def set_matching_expression(options = {})
|
data/test/errata_test.rb
CHANGED
@@ -33,10 +33,6 @@ class AutomobileVariantGuru
|
|
33
33
|
row.slice('MFR', 'Manufacturer', 'carline_mfr_name').any? { |k, v| v.upcase == 'FORD' }
|
34
34
|
end
|
35
35
|
|
36
|
-
def is_a_rolls_royce_and_model_contains_bentley?(row)
|
37
|
-
is_a_rolls_royce?(row) and model_contains_bentley?(row)
|
38
|
-
end
|
39
|
-
|
40
36
|
def is_a_bentley?(row)
|
41
37
|
row.slice('MFR', 'Manufacturer', 'carline_mfr_name').any? { |k, v| v.upcase == 'BENTLEY' }
|
42
38
|
end
|
@@ -89,4 +85,10 @@ class ErrataTest < Test::Unit::TestCase
|
|
89
85
|
e.correct!(alfa)
|
90
86
|
assert_equal 'Alfa Romeo', alfa['carline_mfr_name']
|
91
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
|
92
94
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Seamus Abshere
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-05-
|
18
|
+
date: 2010-05-26 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|