Module Extenso
In: brnumeros/lib/brnumeros/number_portuguese.rb

Methods

Public Class methods

Escreve o numero por extenso.

Exemplo:

 Extenso.por_extenso(1) ==> "um"
 Extenso.por_extenso(100) ==> "cem"
 Extenso.por_extenso(158) ==> "cento e cinquenta e oito"

[Source]

    # File brnumeros/lib/brnumeros/number_portuguese.rb, line 62
62:   def Extenso.por_extenso(numero)
63:     negativo=(numero<0)?"menos ":""
64:     n=numero.to_i.abs
65:     return case n
66:     when 0..9: negativo + @@unidade[n].to_s
67:     when 10..19: negativo + @@dezena[n].to_s
68:     when 20..99:
69:       v=n % 10
70:       if  v== 0
71:         negativo + @@dezena[n].to_s
72:       else
73:         "#{negativo}#{@@dezena[n-v]} e #{por_extenso(v)}"
74:       end
75:     when 100
76:       negativo+"cem"
77:     when 101..999
78:       v=n % 100
79:       if  v== 0
80:         negativo + @@centena[n].to_s
81:       else
82:         "#{negativo}#{@@centena[n-v]} e #{por_extenso(v)}"
83:       end
84:     when 1000..999999
85:       m,c=n/1000,n%1000
86:       %(#{negativo}#{por_extenso(m)} mil#{c > 0 ? " e #{por_extenso(c)}":''})
87:     when 1_000_000..999_999_999
88:       mi,m=n/1_000_000,n%1_000_000
89:       %(#{negativo}#{por_extenso(mi)} milh#{mi > 1 ? 'ões':'ão'}#{m > 0 ? " e #{por_extenso(m)}" : ''})
90:     when 1_000_000_000..999_999_999_999
91:       bi,mi=n/1_000_000_000,n%1_000_000_000
92:       %(#{negativo}#{por_extenso(bi)} bilh#{bi > 1 ? 'ões':'ão'}#{mi > 0 ? " e #{por_extenso(mi)}" : ''})
93:     when 1_000_000_000_000..999_999_999_999_999
94:       tri,bi=n/1_000_000_000_000,n%1_000_000_000_000
95:       %(#{negativo}#{por_extenso(tri)} trilh#{tri > 1 ? 'ões':'ão'}#{bi > 0 ? " e #{por_extenso(bi)}" : ''})
96:     else
97:       raise "Valor excede o permitido: #{n}"
98:     end
99:   end

Public Instance methods

Escreve o numero por extenso.

Exemplo:

 1.por_extenso ==> 'um'
 100.por_extenso ==> 'cem'
 158.por_extenso ==> 'cento e cinquenta e oito'

[Source]

    # File brnumeros/lib/brnumeros/number_portuguese.rb, line 49
49:   def por_extenso
50:     Extenso.por_extenso(self)
51:   end
to_extenso()

Alias for por_extenso

[Validate]