soundex 0.0.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/soundex.rb +52 -20
- metadata +19 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ea0b0df09e3056ab8f560cde75394912b6988c3
|
4
|
+
data.tar.gz: 4b6eac2cfcd8516bf5569c90013250ddfe5bbccc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 357b18a699d7e4c778a3c91e2a61b27bb22777c4036ecd0eb3d3d371e352f412b67b2d29f49e81dd04a1d536f01da9f10b82518f84720f9307b7ecbfb0d9fd2b
|
7
|
+
data.tar.gz: bc650b69722613748e520f455c30e4942cc4fb8ef7a3c3273082bb9850a3713fdd13abe87f57fe5af51afd6d98f705d629ed77223379caf4d5948b419bc338c8
|
data/lib/soundex.rb
CHANGED
@@ -1,22 +1,54 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
soundex
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
(1
|
16
|
-
|
17
|
-
|
18
|
-
text
|
19
|
-
|
1
|
+
class Soundex
|
2
|
+
attr_accessor :original
|
3
|
+
attr_accessor :soundex
|
4
|
+
|
5
|
+
def initialize input
|
6
|
+
self.original = input
|
7
|
+
|
8
|
+
process input if !input.nil? && input.length > 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def remove_neighbors input
|
12
|
+
text = input.dup
|
13
|
+
text.gsub!(/[bfpv][hw]{0,1}[bfpv]/) { |m| m[0] }
|
14
|
+
text.gsub!(/[cgjkqsxz][hw]{0,1}[cgjkqsxz]/) { |m| m[0] }
|
15
|
+
text.gsub!(/[dt][hw]{0,1}[dt]/) { |m| m[0] }
|
16
|
+
text.gsub!(/l[hw]{0,1}l/, 'l')
|
17
|
+
text.gsub!(/[mn][hw]{0,1}[mn]/) { |m| m[0] }
|
18
|
+
text.gsub!(/r[hw]{0,1}r/, 'r')
|
19
|
+
text
|
20
|
+
end
|
21
|
+
|
22
|
+
def strip_vowels input
|
23
|
+
input.gsub(/[aeiouyhw]/, '')
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_numbers input
|
27
|
+
text = input.dup
|
28
|
+
text.gsub!(/[bfpv]/, '1')
|
29
|
+
text.gsub!(/[cgjkqsxz]/, '2')
|
30
|
+
text.gsub!(/[dt]/, '3')
|
31
|
+
text.gsub!(/[l]/, '4')
|
32
|
+
text.gsub!(/[mn]/, '5')
|
33
|
+
text.gsub!(/r/, '6')
|
34
|
+
text
|
35
|
+
end
|
36
|
+
|
37
|
+
def process input
|
38
|
+
first_letter = input[0]
|
39
|
+
input = input.downcase
|
40
|
+
input = remove_neighbors(input)
|
41
|
+
input = strip_vowels(input)
|
42
|
+
|
43
|
+
input = input[1..-1] unless first_letter.downcase.match(/[aeiouyhw]/)
|
44
|
+
input = to_numbers(input)
|
45
|
+
|
46
|
+
soundex = first_letter + input
|
47
|
+
soundex = soundex.ljust(4, '0')
|
48
|
+
self.soundex = soundex[0..3]
|
49
|
+
end
|
50
|
+
|
51
|
+
def to_s
|
52
|
+
self.soundex
|
20
53
|
end
|
21
|
-
(text + "0000")[0..3]
|
22
54
|
end
|
metadata
CHANGED
@@ -1,15 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soundex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
+
- Adam Gross
|
7
8
|
- Karthikeyan A K
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
12
|
+
date: 2015-07-13 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
13
28
|
description: Get American soundex of an word
|
14
29
|
email: 77minds@gmail.com
|
15
30
|
executables: []
|
@@ -37,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
37
52
|
version: '0'
|
38
53
|
requirements: []
|
39
54
|
rubyforge_project:
|
40
|
-
rubygems_version: 2.
|
55
|
+
rubygems_version: 2.4.8
|
41
56
|
signing_key:
|
42
57
|
specification_version: 4
|
43
58
|
summary: Get American soundex of an word
|