spanish_pluralizer 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +4 -0
  2. data/lib/spanish_pluralizer.rb +98 -0
  3. metadata +48 -0
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ spanish_pluralizer
2
+ ==================
3
+
4
+ An alpha version of a pluralizer
@@ -0,0 +1,98 @@
1
+ # encoding: utf-8
2
+
3
+ class AlreadyDefinedMethod < StandardError
4
+ end
5
+
6
+ class String
7
+
8
+ raise AlreadyDefinedMethod.new unless (self.instance_methods(true) & [:acute, :unacute, :pluralize_spanish, :is_acute?]).empty?
9
+
10
+ def acute
11
+ case self
12
+ when 'a'
13
+ 'á'
14
+ when 'e'
15
+ 'é'
16
+ when 'i'
17
+ 'í'
18
+ when 'o'
19
+ 'ó'
20
+ when 'u'
21
+ 'ú'
22
+ else self
23
+ end
24
+ end
25
+
26
+ def unacute
27
+ case self
28
+ when 'á'
29
+ 'a'
30
+ when 'é'
31
+ 'e'
32
+ when 'í'
33
+ 'i'
34
+ when 'ó'
35
+ 'o'
36
+ when 'ú'
37
+ 'u'
38
+ else self
39
+ end
40
+ end
41
+
42
+ def is_acute?
43
+ ['á','é','í','ó','ú'].include? self
44
+ end
45
+
46
+ def pluralize_spanish
47
+ #orden por probabilidad de ocurrencia para optimizar
48
+ case self
49
+ when /.*[aeiouáéó]$/
50
+ #caja => cajas
51
+ #puente => puentes
52
+ #papi => papis
53
+ #mono => monos
54
+ #río => ríos
55
+ #palabru => palabrus
56
+ #sofá => sofás
57
+ #palabré => palabrés
58
+ #palabró => palabrós
59
+ self + 's'
60
+ when /(?<pre>.*)(?<last_vowel>.)(?<ending>[ns])$/
61
+ if $~[:last_vowel].is_acute?
62
+ new_str = self
63
+ #aguda con tilde => grave sin tilde, a menos que el tilde se mantenga por existir hiato
64
+ new_str[-2] = new_str[-2].unacute unless new_str[-3..-1].match(/(a|e|o)(í|ú)/)
65
+ new_str + 'es'
66
+ else
67
+ if $~[:ending] == 's'
68
+ #análisis => análisis
69
+ self
70
+ else
71
+ #imagen => imágenes
72
+ #palebren => palébrenes
73
+ #origen => orígenes
74
+ #orden => órdenes
75
+ #resumen => resúmenes
76
+ ending = $~[:last_vowel] + 'nes'
77
+ $~[:pre].sub(/(a|e|i|o|u)(?=[^aeiou]*$)/, &:acute) + ending
78
+ end
79
+ end
80
+ when /.*z$/
81
+ #arroz => arroces
82
+ self[0..-2] + 'ces'
83
+ else
84
+ #delantal => delantales
85
+ #mantel => manteles
86
+ #mandril => mandriles
87
+ #tambor => tambores
88
+ #gandul => gandules
89
+ #maní => maníes
90
+ #menú => menúes
91
+ #rey => reyes
92
+ #fax => faxes
93
+ #árbol => árboles
94
+ #laúd => laúdes
95
+ self + 'es'
96
+ end
97
+ end
98
+ end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spanish_pluralizer
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Pablo Bianciotto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-07 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! 'An alpha version of a gem for converting spanish singular nouns into
15
+ plural. It works by adding the following methods to String: [:acute, :unacute, :pluralize_spanish,
16
+ :is_acute?]. Fails with monosyllable and exceptions like "régimen => regímenes"'
17
+ email: bianciottopablo@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/spanish_pluralizer.rb
23
+ - README.md
24
+ homepage: https://github.com/akhanubis/spanish_pluralizer
25
+ licenses: []
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ! '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 1.8.24
45
+ signing_key:
46
+ specification_version: 3
47
+ summary: A gem for converting spanish singular nouns into plural
48
+ test_files: []