guerrilla_patch 2.8.7 → 3.0.2
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.
- checksums.yaml +4 -4
- data/README.md +1 -11
- data/lib/guerrilla_patch/version.rb +1 -1
- metadata +1 -4
- data/lib/guerrilla_patch/text_matcher.rb +0 -60
- data/spec/guerrilla_patch/text_matcher_spec.rb +0 -76
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ddc9dac2282bcf39b6a79c7d71fb5ced82712773
|
4
|
+
data.tar.gz: e2def0850fe7cc1fadbf2d787aa6fe275596fb57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be95f230f216a62dfa009459ee0f69abead61ecc431dcbfdf7718c2f2a1a077008f0131b7f484a40f723367a3304244cb100d029683ec250148612ae172460d1
|
7
|
+
data.tar.gz: 34bf830eb720eb1883cabae852affe2c822deebced450a74152c6683ece909c2cee18117f709d31607f62d2541eba50c93bad98e0acba99209b802756855dedc
|
data/README.md
CHANGED
@@ -1,11 +1,9 @@
|
|
1
1
|
Guerrilla Patch
|
2
2
|
================
|
3
|
-
[](https://travis-ci.org/drKreso/guerrilla_patch)
|
4
|
-
|
5
3
|
|
6
4
|
I am tired of hunting and tracking down my own monkey patches. Not to mention hassle of dragging them between projects. I figured gem is a remedy for this.
|
7
5
|
|
8
|
-
Assign instance variables
|
6
|
+
Assign instance variables automatically
|
9
7
|
---------------------------------------
|
10
8
|
You know that neat coffee script trick that shortens code below.
|
11
9
|
|
@@ -144,14 +142,6 @@ end
|
|
144
142
|
|
145
143
|
Somehow for my convoluted brain the later reads better.
|
146
144
|
|
147
|
-
Text matching
|
148
|
-
-----------------------------------------
|
149
|
-
```
|
150
|
-
source = { 1 => "Petar goes to the store.", 2 => "It is crazy there." }
|
151
|
-
target = { 1 => "Petar goes to the store. It is crazy there." }
|
152
|
-
TextMatcher.match(source,target).should == { 1 => [1, 2] }
|
153
|
-
```
|
154
|
-
|
155
145
|
Contributing to guerrilla_patch
|
156
146
|
-------------------------------
|
157
147
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: guerrilla_patch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- drKreso
|
@@ -35,14 +35,12 @@ files:
|
|
35
35
|
- lib/guerrilla_patch/allocate.rb
|
36
36
|
- lib/guerrilla_patch/kernel.rb
|
37
37
|
- lib/guerrilla_patch/string.rb
|
38
|
-
- lib/guerrilla_patch/text_matcher.rb
|
39
38
|
- lib/guerrilla_patch/version.rb
|
40
39
|
- spec/guerrilla_patch/aggregate_by_type/aggregator_spec.rb
|
41
40
|
- spec/guerrilla_patch/aggregate_by_type/divide_by_type_spec.rb
|
42
41
|
- spec/guerrilla_patch/allocate_spec.rb
|
43
42
|
- spec/guerrilla_patch/kernel_spec.rb
|
44
43
|
- spec/guerrilla_patch/string_spec.rb
|
45
|
-
- spec/guerrilla_patch/text_matcher_spec.rb
|
46
44
|
homepage: http://github.com/drKreso/guerrilla_patch
|
47
45
|
licenses:
|
48
46
|
- MIT
|
@@ -74,4 +72,3 @@ test_files:
|
|
74
72
|
- spec/guerrilla_patch/allocate_spec.rb
|
75
73
|
- spec/guerrilla_patch/kernel_spec.rb
|
76
74
|
- spec/guerrilla_patch/string_spec.rb
|
77
|
-
- spec/guerrilla_patch/text_matcher_spec.rb
|
@@ -1,60 +0,0 @@
|
|
1
|
-
class TextMatcher
|
2
|
-
|
3
|
-
def self.match(source, target)
|
4
|
-
result = {}
|
5
|
-
source.each_pair { |key,value| source[key] = value.gsub(' ', '').downcase }
|
6
|
-
target.each_pair { |key,value| target[key] = value.gsub(' ', '').downcase }
|
7
|
-
|
8
|
-
mapped_source = source.each_with_index.map { |key_value,index| [index] * key_value[1].size }.flatten(1)
|
9
|
-
mapped_target = target.each_with_index.map { |key_value,index| [index] * key_value[1].size }.flatten(1)
|
10
|
-
|
11
|
-
source_clean_chars = source.each_value.map {|v| v}.join('')
|
12
|
-
target_clean_chars = target.each_value.map {|v| v}.join('')
|
13
|
-
|
14
|
-
#we have difference so we'll clean up source to match target
|
15
|
-
if source_clean_chars != target_clean_chars
|
16
|
-
source_index = 0
|
17
|
-
target_index = 0
|
18
|
-
while(target_index < target_clean_chars.size)
|
19
|
-
if source_clean_chars[source_index] == nil
|
20
|
-
target_index += 1
|
21
|
-
elsif source_clean_chars[source_index] != target_clean_chars[target_index]
|
22
|
-
mapped_source.insert(source_index, '-')
|
23
|
-
source_index += 1
|
24
|
-
else
|
25
|
-
source_index += 1
|
26
|
-
target_index += 1
|
27
|
-
end
|
28
|
-
puts target_index
|
29
|
-
end
|
30
|
-
puts " "
|
31
|
-
puts "#{mapped_source}"
|
32
|
-
puts "#{mapped_target}"
|
33
|
-
end
|
34
|
-
|
35
|
-
(0...mapped_target.size).each do |index|
|
36
|
-
if index == "-"
|
37
|
-
#nothing should happen
|
38
|
-
else
|
39
|
-
result[mapped_target[index]] ||= []
|
40
|
-
if mapped_source[index] == "-"
|
41
|
-
#nothing should happen
|
42
|
-
else
|
43
|
-
result[mapped_target[index]] << [mapped_source[index]]
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
result.each_pair { |key, value| result[key] = value.flatten.uniq }
|
48
|
-
|
49
|
-
#map real ids
|
50
|
-
target_as_pairs = target.map {|key, value| [key, value]}
|
51
|
-
source_as_pairs = source.map {|key, value| [key, value]}
|
52
|
-
real_result = {}
|
53
|
-
result.each_pair do |target_index, source_indexes|
|
54
|
-
real_result[target_as_pairs[target_index][0]] = source_indexes.map { |source_index| source_as_pairs[source_index][0] }
|
55
|
-
end
|
56
|
-
|
57
|
-
real_result
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
require 'guerrilla_patch/text_matcher.rb'
|
2
|
-
|
3
|
-
describe TextMatcher do
|
4
|
-
|
5
|
-
it 'should pair exact matches' do
|
6
|
-
source = { 1 => "Petar ide u ducan.", 2 => "Tamo je ludnica"}
|
7
|
-
target = { 1 => "Petar ide u ducan.", 2 => "Tamo je ludnica"}
|
8
|
-
TextMatcher.match(source,target).should == { 1 => [1], 2 => [2] }
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should pair exact matches' do
|
12
|
-
source = { 1 => "Petar ide u ducan.", 2 => "Tamo je ludnica.", 3=> "Sve je na popustu."}
|
13
|
-
target = { 1 => "Petar ide u ducan.", 2 => "Tamo je ludnica.", 3=> "Sve je na popustu."}
|
14
|
-
TextMatcher.match(source,target).should == { 1 => [1], 2 => [2], 3 => [3] }
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should pair two for one target' do
|
18
|
-
source = { 1 => "Petar ide u ducan.", 2 => "Tamo je ludnica." }
|
19
|
-
target = { 1 => "Petar ide u ducan.Tamo je ludnica." }
|
20
|
-
TextMatcher.match(source,target).should == { 1 => [1, 2] }
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should pair mismatced case' do
|
24
|
-
source = { 1 => "Petar ide u Ducan.", 2 => "Tamo je ludnica." }
|
25
|
-
target = { 1 => "Petar ide u ducan.Tamo je ludnica." }
|
26
|
-
TextMatcher.match(source,target).should == { 1 => [1, 2] }
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should pair two for one target and continue matching' do
|
30
|
-
source = { 1 => "Petar ide u ducan.", 2 => "Tamo je ludnica.", 3 => "A" }
|
31
|
-
target = { 1 => "Petar ide u ducan.Tamo je ludnica.", 2 => "A" }
|
32
|
-
TextMatcher.match(source,target).should == { 1 => [1, 2], 2 => [3] }
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should pair when index is bigger than single digit number' do
|
36
|
-
source = { 1 => "A", 2 => "B", 3 => "C", 4 => "D", 5 => "EF", 6 => "G", 7 => "H", 8 => "I",
|
37
|
-
9 => "J", 10 => "KL", 11 => "M", 12 => "N", 13 => "O" }
|
38
|
-
target = { 1 => "A", 2 => "B", 3 => "C", 4 => "D", 5 => "E", 6 => "FG", 7 => "H", 8 => "I",
|
39
|
-
9 => "J", 10 => "K", 11 => "LM", 12 => "N", 13 => "O" }
|
40
|
-
TextMatcher.match(source,target).should == { 1=>[1], 2=>[2], 3=>[3], 4=>[4], 5=>[5], 6=>[5, 6],
|
41
|
-
7=>[7], 8=>[8], 9=>[9], 10=>[10], 11=>[10, 11],
|
42
|
-
12=>[12], 13=>[13]
|
43
|
-
}
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should pair two for one target regardless of spacing' do
|
47
|
-
source = { 1 => "Petar ide u ducan.", 2 => "Tamo je ludnica." }
|
48
|
-
target = { 1 => "Petar ide u ducan. Tamo je ludnica." }
|
49
|
-
TextMatcher.match(source,target).should == { 1 => [1, 2] }
|
50
|
-
end
|
51
|
-
|
52
|
-
xit 'should recover after missing target' do
|
53
|
-
source = { 1 => "Petar ide u ducan.", 2 => "Tamo je ludnica." }
|
54
|
-
target = { 1 => "Petar ide u ducan.", 2 => "missing", 3=> "Tamo je ludnica." }
|
55
|
-
TextMatcher.match(source,target).should == { 1 => [1], 2 => [], 3 => [2] }
|
56
|
-
end
|
57
|
-
|
58
|
-
xit 'should recover after missing source' do
|
59
|
-
source = { 1 => "Petar ide u ducan.", 2 => "missing", 3 => "Tamo je ludnica." }
|
60
|
-
target = { 1 => "Petar ide u ducan.", 2=> "Tamo je ludnica." }
|
61
|
-
TextMatcher.match(source,target).should == { 1 => [1], 2 => [3] }
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'should recover on half match' do
|
65
|
-
source = { 1 => "Petar ide u ducan.", 2 => "Tamo je ludnica.", 3 => "Ovo je ok.", 4 => "Sadrzi zadnje dvije." }
|
66
|
-
target = { 1 => "Petar ide u ducan. Tamo", 2=> "je ludnica." , 3 => "Ovo je ok. Sadrzi zadnje dvije." }
|
67
|
-
TextMatcher.match(source,target).should == { 1 => [1,2], 2 => [2], 3 => [3,4] }
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'should recover on half match from source side' do
|
71
|
-
source = { 1 => "Petar ide u ducan. Tamo", 2 => "je ludnica.", 3 => "Ovo je ok.", 4 => "Sadrzi zadnje dvije." }
|
72
|
-
target = { 1 => "Petar ide u ducan.", 2=> "Tamo je ludnica." , 3 => "Ovo je ok. Sadrzi zadnje dvije." }
|
73
|
-
TextMatcher.match(source,target).should == { 1 => [1], 2 => [1,2], 3 => [3,4] }
|
74
|
-
end
|
75
|
-
|
76
|
-
end
|