soundex 0.0.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/soundex.rb +52 -20
  3. metadata +19 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d782c368e8ff54e4a0a43510216951d0182d6232
4
- data.tar.gz: e5b882e0ff5c0b97129a50afbbbda8cdfe4d0e4c
3
+ metadata.gz: 6ea0b0df09e3056ab8f560cde75394912b6988c3
4
+ data.tar.gz: 4b6eac2cfcd8516bf5569c90013250ddfe5bbccc
5
5
  SHA512:
6
- metadata.gz: 4364ff732dccb1215b629e40cab372b9cf64bde305f1402dc6dbf31109139f2b79913b1e394e49f6ee01b4123457e0e0968171714cf70650207f9eaac989b421
7
- data.tar.gz: af976202f3b3c2336e0677c8e9746d74e2e8acf2a25b416b73a59595b348b98bc0311a3c4565e0319c48c57e3eeb3b6abd1df3230bf2b823754468de2def89e1
6
+ metadata.gz: 357b18a699d7e4c778a3c91e2a61b27bb22777c4036ecd0eb3d3d371e352f412b67b2d29f49e81dd04a1d536f01da9f10b82518f84720f9307b7ecbfb0d9fd2b
7
+ data.tar.gz: bc650b69722613748e520f455c30e4942cc4fb8ef7a3c3273082bb9850a3713fdd13abe87f57fe5af51afd6d98f705d629ed77223379caf4d5948b419bc338c8
@@ -1,22 +1,54 @@
1
- def soundex word
2
- text = word
3
- soundex = ""
4
- loop do
5
- text = text.downcase
6
- first_letter = text[0]
7
- other_letters = text[1..text.length]
8
- other_letters = other_letters.gsub /[aeiouyhw]/, ''
9
- other_letters = other_letters.gsub /[bfpv]/, '1'
10
- other_letters = other_letters.gsub /[cgjkqsxz]/, '2'
11
- other_letters = other_letters.gsub /[dt]/, '3'
12
- other_letters = other_letters.gsub /[i]/, '4'
13
- other_letters = other_letters.gsub /[mn]/, '5'
14
- other_letters = other_letters.gsub /r/, '6'
15
- (1..6).to_a.each do |num|
16
- other_letters = other_letters.gsub Regexp.new("#{num}+"), num.to_s
17
- end
18
- text = first_letter + other_letters
19
- break if text.match /\w\d+/
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.0.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: 2014-08-05 00:00:00.000000000 Z
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.2.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