soundcord 0.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.
Files changed (2) hide show
  1. data/lib/soundcord.rb +101 -0
  2. metadata +46 -0
data/lib/soundcord.rb ADDED
@@ -0,0 +1,101 @@
1
+ # encoding: utf-8
2
+
3
+ class SoundCord
4
+ def self.phonetize text, use_vogals=false
5
+ return handle_text(text, use_vogals)
6
+ end
7
+
8
+ def self.compare term_1, term_2, use_vogals=false
9
+ handle_text(term_1, use_vogals) == handle_text(term_2, use_vogals)
10
+ end
11
+
12
+ private
13
+ def self.handle_text text, use_vogals
14
+ text.downcase!
15
+
16
+ handle_special_chars text
17
+ handle_unusual_chars text
18
+ handle_unusual_combinations text
19
+ handle_terminations text
20
+ remove_vogals(text) unless use_vogals
21
+ remove_unwanted_chars text
22
+ text = remove_duplicity text
23
+
24
+ text.upcase
25
+ end
26
+
27
+ def self.handle_special_chars text
28
+ text.gsub! /(á|à|â|ã)/, 'a'
29
+ text.gsub! /(é|è|ê)/, 'e'
30
+ text.gsub! /(í|ì|î)/, 'i'
31
+ text.gsub! /(ó|ò|ô|õ)/, 'o'
32
+ text.gsub! /(ú|ù|û)/, 'u'
33
+ end
34
+
35
+ def self.handle_unusual_chars text
36
+ text.gsub! /y/, 'i'
37
+ end
38
+
39
+ def self.handle_unusual_combinations text
40
+ text.gsub! /(br|bl)/, 'b'
41
+
42
+ text.gsub! /ph/, 'f'
43
+
44
+ text.gsub! /(gr|mg|ng|rg|gl)/, 'g'
45
+
46
+ text.gsub! /(ge|gi|rj|mj|nj)/, 'j'
47
+
48
+ text.gsub! /(ce|ci|ch|cs)/, 's'
49
+
50
+ text.gsub! /ct/, 't'
51
+
52
+ text.gsub! /(q|ca|co|cu|ck|c)/, 'k'
53
+
54
+ text.gsub! /lh/, 'l'
55
+
56
+ text.gsub! /rm/, 'sm'
57
+
58
+ text.gsub! /(n|rm|gm|md|sm|ao\b)/, 'm'
59
+
60
+ text.gsub! /ao\b/, 'm'
61
+
62
+ text.gsub! /nh/, 'n'
63
+
64
+ text.gsub! /pr/, 'p'
65
+
66
+ text.gsub! /(ç|x|ts|c|z|rs)/, 's'
67
+
68
+ text.gsub! /(tr|tl|lt|rt|st)/, 's'
69
+
70
+ text.gsub! /w/, 'v'
71
+ end
72
+
73
+ def self.handle_terminations text
74
+ text.gsub! /(s|z|r|m|n|ao|l)\b/, ''
75
+ end
76
+
77
+ def self.remove_vogals text
78
+ text.gsub! /(a|e|i|o|u)/, ''
79
+ end
80
+
81
+ def self.remove_unwanted_chars text
82
+ text.gsub! /h/, ''
83
+ end
84
+
85
+ def self.remove_duplicity text
86
+ text.split(//).uniq.inject("") { |s,n| s+n }
87
+ end
88
+ end
89
+
90
+
91
+ class String
92
+ def phonetize options = { :use_vogals => false }
93
+ SoundCord.phonetize self, options[:use_vogals]
94
+ end
95
+ def compare_phntc compared
96
+ SoundCord.compare self, compared
97
+ end
98
+ def compare_phonetically compared
99
+ compare_phntc compared
100
+ end
101
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soundcord
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Lukas Alexandre
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-13 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: A phonetic algorithm, that integrates with ActiveRecord, to make searches
15
+ by phonetically similar terms easier.
16
+ email: lukeskytm@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/soundcord.rb
22
+ homepage: https://github.com/lukasalexandre/soundcord
23
+ licenses: []
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 1.8.24
43
+ signing_key:
44
+ specification_version: 3
45
+ summary: A phonetic algorithm implementation
46
+ test_files: []