spanish_number 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/spanish_number.rb +9 -4
  2. metadata +2 -2
@@ -1,12 +1,15 @@
1
+ #!/bin/env ruby
2
+ # encoding: utf-8
3
+
1
4
  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
5
  DECENAS = ["", "diez", "veinte", "treinta", "cuarenta", "cincuenta", "sesenta", "setenta", "ochenta", "noventa"]
3
6
  CENTENAS = ["", "ciento", "doscientos", "trescientos", "cuatrocientos", "quinientos", "seiscientos", "setecientos", "ochocientos", "novecientos"]
4
- MILLONES = ["millon", "billon", "trillon", "cuatrillon"]
7
+ MILLONES = ["mill", "bill", "trill", "cuatrill"]
5
8
 
6
9
  class Numeric
7
10
  def to_spanish_text currency=""
8
11
  final_text = ""
9
- self.to_s =~ /([^\.]*)(\..*)?/
12
+ sprintf( "%.2f", self ) =~ /([^\.]*)(\..*)?/
10
13
  int, dec = $1.reverse, $2 ? $2[1..-1] : ""
11
14
  int = int.scan(/.{1,6}/).reverse
12
15
  int = int.map{ |million| million.scan(/.{1,3}/).reverse}
@@ -15,13 +18,15 @@ class Numeric
15
18
  final_text += solve_million sixdigit
16
19
  if (i-2) >= 0
17
20
  final_text += " " + MILLONES[ i-2 ]
18
- final_text += "es" if sixdigit != ["1"]
21
+ final_text += sixdigit == ["1"] ? "ón" : "ones"
19
22
  end
20
23
  end
21
24
  final_text += mxn dec if currency == 'mxn'
22
- final_text
25
+ final_text[1..-1]
23
26
  end
24
27
 
28
+ private
29
+
25
30
  def solve_million sixdigit
26
31
  text = ""
27
32
  text += solve_thousand sixdigit.first
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spanish_number
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-29 00:00:00.000000000 Z
12
+ date: 2013-02-06 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Express a number in spanish text
15
15
  email: leo@kueski.com