spanish_number 0.1.0
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.
- data/lib/spanish_number.rb +61 -0
- metadata +45 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
UNIDADES = ["", "un", "dos", "tres", "cuatro", "cinco", "seis", "siete", "ocho", "nueve", "diez", "once", "doce", "trece", "catorce", "quince", "dieciseis", "diecisiete", "dieciocho", "diecinueve", "veinte", "veintiun", "veintidos", "veintitres", "veinticuatro", "veinticinco", "veintiseis", "veintisiete", "veintiocho", "veintinueve"]
|
|
2
|
+
DECENAS = ["", "diez", "veinte", "treinta", "cuarenta", "cincuenta", "sesenta", "setenta", "ochenta", "noventa"]
|
|
3
|
+
CENTENAS = ["", "ciento", "doscientos", "trescientos", "cuatrocientos", "quinientos", "seiscientos", "setecientos", "ochocientos", "novecientos"]
|
|
4
|
+
MILLONES = ["millon", "billon", "trillon", "cuatrillon"]
|
|
5
|
+
|
|
6
|
+
class Numeric
|
|
7
|
+
def to_text_spanish currency
|
|
8
|
+
final_text = ""
|
|
9
|
+
self.to_s =~ /([^\.]*)(\..*)?/
|
|
10
|
+
int, dec = $1.reverse, $2 ? $2[1..-1] : ""
|
|
11
|
+
int = int.scan(/.{1,6}/).reverse
|
|
12
|
+
int = int.map{ |million| million.scan(/.{1,3}/).reverse}
|
|
13
|
+
int.each_with_index do |sixdigit, index|
|
|
14
|
+
i = int.length - index
|
|
15
|
+
final_text += solve_million sixdigit
|
|
16
|
+
if (i-2) >= 0
|
|
17
|
+
final_text += " " + MILLONES[ i-2 ]
|
|
18
|
+
final_text += "es" if sixdigit != ["1"]
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
final_text += mxn dec if currency == 'mxn'
|
|
22
|
+
final_text
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def solve_million sixdigit
|
|
26
|
+
text = ""
|
|
27
|
+
text += solve_thousand sixdigit.first
|
|
28
|
+
if sixdigit.length > 1
|
|
29
|
+
text += " mil"
|
|
30
|
+
text += solve_thousand sixdigit.last
|
|
31
|
+
end
|
|
32
|
+
text
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def solve_thousand threedigit
|
|
36
|
+
text = ""
|
|
37
|
+
return "error" if threedigit.length > 3
|
|
38
|
+
text += " " + CENTENAS[ threedigit[2].to_i ] if threedigit.length > 2 && threedigit[2] != '0'
|
|
39
|
+
if threedigit.length >= 2 && threedigit[1].ord > '2'.ord
|
|
40
|
+
text += " " + DECENAS[ threedigit[1].to_i ] if threedigit[1] != '0'
|
|
41
|
+
unit = threedigit[0].to_i
|
|
42
|
+
text += " y" if unit != 0
|
|
43
|
+
text += " " + UNIDADES[ unit ] if unit != 0
|
|
44
|
+
else
|
|
45
|
+
unit = threedigit[0..1].reverse.to_i
|
|
46
|
+
text += " " + UNIDADES[ unit ] if unit != 0
|
|
47
|
+
end
|
|
48
|
+
text
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def mxn cents
|
|
52
|
+
text = ""
|
|
53
|
+
text += " pesos"
|
|
54
|
+
cents = "00" if cents.nil?
|
|
55
|
+
while cents.length < 2 do
|
|
56
|
+
cents << "0"
|
|
57
|
+
end
|
|
58
|
+
text += " " + cents[0..1].to_s + "/100"
|
|
59
|
+
text += " M.N."
|
|
60
|
+
end
|
|
61
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: spanish_number
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Leonardo de la Cerda
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-01-29 00:00:00.000000000 Z
|
|
13
|
+
dependencies: []
|
|
14
|
+
description: A simple hello world gem
|
|
15
|
+
email: leo@kueski.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- lib/spanish_number.rb
|
|
21
|
+
homepage: http://rubygems.org/gems/spanish_number
|
|
22
|
+
licenses: []
|
|
23
|
+
post_install_message:
|
|
24
|
+
rdoc_options: []
|
|
25
|
+
require_paths:
|
|
26
|
+
- lib
|
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
28
|
+
none: false
|
|
29
|
+
requirements:
|
|
30
|
+
- - ! '>='
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
none: false
|
|
35
|
+
requirements:
|
|
36
|
+
- - ! '>='
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: '0'
|
|
39
|
+
requirements: []
|
|
40
|
+
rubyforge_project:
|
|
41
|
+
rubygems_version: 1.8.23
|
|
42
|
+
signing_key:
|
|
43
|
+
specification_version: 3
|
|
44
|
+
summary: Express a number in spanish text
|
|
45
|
+
test_files: []
|