extenso_pt 0.6.6 → 0.6.7
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.
- checksums.yaml +4 -4
- data/.project_alt.json +3 -1
- data/Gemfile.lock +2 -2
- data/README.md +18 -18
- data/extenso_pt.gemspec +1 -1
- data/lib/extenso_pt/constantes.rb +5 -1
- data/lib/extenso_pt/extenso.rb +23 -125
- data/lib/extenso_pt/romana.rb +1 -1
- data/lib/extenso_pt/variaveis.rb +64 -0
- data/lib/extenso_pt/version.rb +1 -1
- data/lib/extenso_pt.rb +70 -42
- metadata +5 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 51e6593de1a365ff37d40f901a2d18a35155b95da6e4806ce8d134f268f18782
|
|
4
|
+
data.tar.gz: d68b5512109c2e6175ea90c92d9634deac4ccc3fb894a4137e5f78aa1efffaec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 141411e04fba9bcd9e96bca1c97a8a446ca40b44936b5d510dbd024d0a89837ac420c8e450cc069d2b919da7f871f051ca7ea500c7b1847867b8a5d51ecb732e
|
|
7
|
+
data.tar.gz: 660b7f2b1485b4762f997ad514e083506246329da2b72cd007513fd1786cd17b6cf23e25e6c1f92570b49bf76ed71368b91fe863388f9c38cabe26164a41e4d8
|
data/.project_alt.json
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
|
@@ -21,24 +21,24 @@ Or install it yourself as:
|
|
|
21
21
|
## Usage
|
|
22
22
|
|
|
23
23
|
```ruby
|
|
24
|
-
1234.extenso
|
|
25
|
-
1234.romana
|
|
26
|
-
"MCCXXXIV".romana
|
|
27
|
-
12000000.12.extenso
|
|
28
|
-
1.01.extenso(
|
|
29
|
-
14.
|
|
30
|
-
14.1.extenso(lc: :br)
|
|
31
|
-
|
|
32
|
-
10.
|
|
33
|
-
1e10.extenso(lc: :pt)
|
|
34
|
-
1e10.extenso(lc: :br)
|
|
35
|
-
[0.
|
|
36
|
-
[4, 5, 6, 7].romana
|
|
37
|
-
(1..2).extenso
|
|
38
|
-
(7..9).romana
|
|
39
|
-
{:a=>1, :b=>2}.extenso
|
|
40
|
-
{:a=>[3, 4], :b=>2}.extenso
|
|
41
|
-
{:a=>["MCMLXVIII", "XIV"], :b=>4}.romana
|
|
24
|
+
1234.extenso => "MIL DUZENTOS E TRINTA E QUATRO EUROS"
|
|
25
|
+
1234.romana => "MCCXXXIV"
|
|
26
|
+
"MCCXXXIV".romana => 1234
|
|
27
|
+
12000000.12.extenso => "DOZE MILHÕES DE EUROS E DOZE CÊNTIMOS"
|
|
28
|
+
1.01.extenso(moeda_singular: 'DÓLAR') => "UM DÓLAR E UM CÊNTIMO"
|
|
29
|
+
14.1.extenso(moeda_plural: 'REAIS') => "CATORZE REAIS E DEZ CÊNTIMOS"
|
|
30
|
+
14.1.extenso(lc: :br) => "QUATORZE REAIS E DEZ CENTAVOS"
|
|
31
|
+
10.01.extenso(fracao_plural: 'CENTAVOS') => "DEZ EUROS E UM CENTAVO" # singular inferido = <plural> menos "S"
|
|
32
|
+
10.10.extenso(fracao_singular: 'CENTAVO') => "DEZ EUROS E DEZ CENTAVOS" # plural inferido = <silgular> mais "S"
|
|
33
|
+
1e10.extenso(lc: :pt) => "DEZ MIL MILHÕES DE EUROS" # portugal usa escala longa
|
|
34
|
+
1e10.extenso(lc: :br) => "DEZ BILHÕES DE REAIS" # brasil usa escala curta
|
|
35
|
+
[0.01, 0.2].extenso => ["UM CÊNTIMO","VINTE CÊNTIMOS"]
|
|
36
|
+
[4, 5, 6, 7].romana => ["IV", "V", "VI", "VII"]
|
|
37
|
+
(1..2).extenso => ["UM EURO","DOIS EUROS"]
|
|
38
|
+
(7..9).romana => ["VII", "VIII", "IX"]
|
|
39
|
+
{:a=>1, :b=>2}.extenso => {:a=>"UM EURO",:b=>"DOIS EUROS"}
|
|
40
|
+
{:a=>[3, 4], :b=>2}.extenso => {:a=>["TRÊS EUROS", "QUATRO EUROS"],:b=>"DOIS EUROS"}
|
|
41
|
+
{:a=>["MCMLXVIII", "XIV"], :b=>4}.romana => {:a=>[1968, 14], :b=>"IV"}
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
## Development
|
data/extenso_pt.gemspec
CHANGED
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
# @author Hernani Rodrigues Vaz
|
|
4
4
|
module ExtensoPt
|
|
5
|
-
#
|
|
5
|
+
# chaves parametrizacao moeda permitidas
|
|
6
|
+
MOEDA = %i[moeda_singular fracao_singular
|
|
7
|
+
moeda_plural fracao_plural lc].freeze
|
|
8
|
+
# somente portugues de portugal ou brasil permitidos
|
|
9
|
+
# qualquer outro locale equivale usar :pt
|
|
6
10
|
EXTLC = %i[pt br].freeze
|
|
7
11
|
# extensos 1 ate 19
|
|
8
12
|
A0020 = {
|
data/lib/extenso_pt/extenso.rb
CHANGED
|
@@ -32,12 +32,8 @@ module ExtensoPt
|
|
|
32
32
|
#
|
|
33
33
|
# @return [String] extenso da parte fracionaria
|
|
34
34
|
def self.ef99
|
|
35
|
-
# parametrizacao por defeito
|
|
36
|
-
@cs ||= 'CÊNTIMO'
|
|
37
|
-
@cp ||= @cs + 'S'
|
|
38
|
-
|
|
39
35
|
if @nf.positive?
|
|
40
|
-
e090(@nf) + e009(@nf) + (@nf > 1 ? ' ' + @
|
|
36
|
+
e090(@nf) + e009(@nf) + (@nf > 1 ? ' ' + @fp : ' ' + @fs)
|
|
41
37
|
else
|
|
42
38
|
''
|
|
43
39
|
end
|
|
@@ -47,17 +43,16 @@ module ExtensoPt
|
|
|
47
43
|
#
|
|
48
44
|
# @return [String] final da moeda
|
|
49
45
|
def self.efim
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
emo + (@tt.positive? && @nf.positive? ? ' E ' : '') + ef99
|
|
46
|
+
if c124.positive?
|
|
47
|
+
# proposicao DE entre parte inteira e moeda
|
|
48
|
+
# moeda singular/plural
|
|
49
|
+
# proposicao E entre moeda e parte fracionaria
|
|
50
|
+
(cpde? ? ' DE ' : ' ') +
|
|
51
|
+
(c124 > 1 ? @mp : @ms) +
|
|
52
|
+
(@nf.positive? ? ' E ' : '')
|
|
53
|
+
else
|
|
54
|
+
''
|
|
55
|
+
end + ef99
|
|
61
56
|
end
|
|
62
57
|
|
|
63
58
|
# Produz separador entre grupos 3 digitos
|
|
@@ -87,7 +82,7 @@ module ExtensoPt
|
|
|
87
82
|
# Produz extenso de grupo 3 digitos em portugues de portugal ou brasil
|
|
88
83
|
#
|
|
89
84
|
# @param [Integer] pos posicao actual nos grupos 3 digitos
|
|
90
|
-
# @return [String] extenso grupo 3 digitos
|
|
85
|
+
# @return [String] extenso do grupo 3 digitos
|
|
91
86
|
def self.edg3(pos)
|
|
92
87
|
# caso especial MIL EUROS
|
|
93
88
|
if pos == 1 && @ai[pos] == 1
|
|
@@ -97,119 +92,22 @@ module ExtensoPt
|
|
|
97
92
|
end + e124(pos)
|
|
98
93
|
end
|
|
99
94
|
|
|
100
|
-
#
|
|
101
|
-
#
|
|
102
|
-
# @return [void]
|
|
103
|
-
def self.epsp
|
|
104
|
-
# soma grupos 1,2 (primeiros 6 digitos)
|
|
105
|
-
@s6 = @ai[0].to_i + @ai[1].to_i * 2
|
|
106
|
-
# soma grupos 3.. (digitos acima de 6)
|
|
107
|
-
@m6 = @ai[2..-1].to_a.inject(:+).to_i * 2
|
|
108
|
-
# parametrizar controle de proposicao E & singular/plural
|
|
109
|
-
@tt = @s6 + @m6
|
|
110
|
-
# parametrizar controle de proposicao DE
|
|
111
|
-
@de = @s6.zero? && @m6.positive?
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
# Produz extenso em portugues de portugal ou brasil
|
|
95
|
+
# Produz extenso da parte inteira (@ai) e fracionaria (@nf)
|
|
115
96
|
#
|
|
116
|
-
# @param [Integer] pos posicao
|
|
97
|
+
# @param [Integer] pos posicao no grupo 3 digitos
|
|
117
98
|
# @param [String] ext extenso em construcao
|
|
118
|
-
# @return [String]
|
|
119
|
-
def self.
|
|
99
|
+
# @return [String] extenso do valor monetario
|
|
100
|
+
def self.ejun(pos, ext)
|
|
120
101
|
# testa fim do valor monetario
|
|
121
102
|
if pos >= @ai.count
|
|
122
|
-
#
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
# caso especial zero
|
|
126
|
-
(@tt + @nf).zero? ? 'ZERO ' + @mp : ext + efim
|
|
127
|
-
else
|
|
128
|
-
# tratamento de grupo 3 digitos
|
|
129
|
-
etot(pos + 1, edg3(pos) + ext)
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
# Parametrizar parte inteira/fracionaria da string digitos
|
|
134
|
-
#
|
|
135
|
-
# @param [String] digitos do valor monetario
|
|
136
|
-
# @return [void]
|
|
137
|
-
def self.epif(dig)
|
|
138
|
-
# parametrizacao por defeito
|
|
139
|
-
# the first mention of an @<variable> creates the
|
|
140
|
-
# instance variable in the current object ie: self = ExtensoPt
|
|
141
|
-
@lc ||= :pt
|
|
142
|
-
|
|
143
|
-
# converte parte inteira da string digitos em array com grupos de 3 digitos
|
|
144
|
-
# ex: 123022.12 => [22, 123]
|
|
145
|
-
@ai = dig[/^\d+/].to_s.reverse.scan(/\d{1,3}/).map { |i| i.reverse.to_i }
|
|
146
|
-
|
|
147
|
-
# obtem parte fracionaria da string digitos
|
|
148
|
-
# ex: 123022.12 => 12
|
|
149
|
-
# arredondada a 2 casas decimais (centimos/centavos)
|
|
150
|
-
@nf = (dig[/\.\d*/].to_f * 100).round
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
# Converte objeto criando extenso(s) em portugues de portugal ou brasil
|
|
154
|
-
#
|
|
155
|
-
# @param [Object] obj objeto a converter
|
|
156
|
-
# (String, Float, Integer, Array, Range, Hash)
|
|
157
|
-
# @return [String, Array, Hash] string extenso
|
|
158
|
-
# se objecto for (String, Float, Integer),
|
|
159
|
-
# array<extensos> se objecto for (Array, Range),
|
|
160
|
-
# hash<extensos> se objecto for (Hash)
|
|
161
|
-
def self.eo2e(obj)
|
|
162
|
-
# converte os valores do Hash nos seus extensos
|
|
163
|
-
if obj.is_a?(Hash) then obj.map { |k, v| [k, eo2e(v)] }.to_h
|
|
164
|
-
# converte objecto num Array com os valores convertidos em extensos
|
|
165
|
-
elsif obj.respond_to?(:to_a) then obj.to_a.map { |a| eo2e(a) }
|
|
103
|
+
# caso especial de zero
|
|
104
|
+
(c124 + @nf).zero? ? 'ZERO ' + @mp : ext + efim
|
|
166
105
|
else
|
|
167
|
-
# converte
|
|
168
|
-
#
|
|
169
|
-
|
|
170
|
-
epif(obj.to_d.to_s('F'))
|
|
171
|
-
|
|
172
|
-
# processar extenso - valores >1e24 sao ignorados
|
|
173
|
-
@ai.count > 8 ? '' : etot(0, '')
|
|
106
|
+
# converte grupo 3 digitos na posicao corrente
|
|
107
|
+
# envoca proxima posicao
|
|
108
|
+
ejun(pos + 1, edg3(pos) + ext)
|
|
174
109
|
end
|
|
175
110
|
end
|
|
176
|
-
|
|
177
|
-
#
|
|
178
|
-
#
|
|
179
|
-
# @param [Hash] moeda as opcoes para parametrizar moeda/fracao
|
|
180
|
-
# @option moeda [Symbol] :lc locale do extenso -
|
|
181
|
-
# portugues de portugal (:pt) portugues do brasil (:br)
|
|
182
|
-
# @option moeda [String] :msingular moeda no singular -
|
|
183
|
-
# inferido do plural menos"S"
|
|
184
|
-
# @option moeda [String] :fsingular fracao no singular -
|
|
185
|
-
# inferido do plural menos "S"
|
|
186
|
-
# @option moeda [String] :mplural moeda no plural
|
|
187
|
-
# @option moeda [String] :fplural fracao no plural
|
|
188
|
-
# @return [void]
|
|
189
|
-
def self.epsi(moeda)
|
|
190
|
-
@ms = moeda[:msingular] ||
|
|
191
|
-
(moeda[:mplural].to_s[-1] == 'S' ? moeda[:mplural][0..-2] : 'EURO')
|
|
192
|
-
@cs = moeda[:fsingular] ||
|
|
193
|
-
(moeda[:fplural].to_s[-1] == 'S' ? moeda[:fplural][0..-2] : 'CÊNTIMO')
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
# Parametrizar moeda inferindo plural a partir do singular
|
|
197
|
-
#
|
|
198
|
-
# @param [Hash] moeda as opcoes para parametrizar moeda/fracao
|
|
199
|
-
# @option moeda [Symbol] :lc locale do extenso -
|
|
200
|
-
# portugues de portugal (:pt) portugues do brasil (:br)
|
|
201
|
-
# @option moeda [String] :msingular moeda no singular
|
|
202
|
-
# @option moeda [String] :fsingular fracao no singular
|
|
203
|
-
# @option moeda [String] :mplural moeda no plural -
|
|
204
|
-
# inferido do singular mais "S"
|
|
205
|
-
# @option moeda [String] :fplural fracao no plural -
|
|
206
|
-
# inferido do singular mais "S"
|
|
207
|
-
# @return [void]
|
|
208
|
-
def self.eppl(moeda)
|
|
209
|
-
# somente [:pt, :br]
|
|
210
|
-
@lc = EXTLC.include?(moeda[:lc]) ? moeda[:lc] : :pt
|
|
211
|
-
|
|
212
|
-
@mp = moeda[:mplural] || @ms + 'S'
|
|
213
|
-
@cp = moeda[:fplural] || @cs + 'S'
|
|
214
|
-
end
|
|
111
|
+
# private_class_method :e900, :e090, :e009, :ef99, :efim,
|
|
112
|
+
# :edgs, :e124, :edg3
|
|
215
113
|
end
|
data/lib/extenso_pt/romana.rb
CHANGED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# @author Hernani Rodrigues Vaz
|
|
4
|
+
module ExtensoPt
|
|
5
|
+
# Parametrizar moeda
|
|
6
|
+
#
|
|
7
|
+
# @param [Hash] moeda as opcoes para parametrizar moeda/fracao
|
|
8
|
+
# @option moeda [Symbol] :lc locale do extenso -
|
|
9
|
+
# portugues de portugal (:pt) portugues do brasil (:br)
|
|
10
|
+
# @option moeda [String] :moeda_singular moeda no singular
|
|
11
|
+
# @option moeda [String] :fracao_singular fracao no singular
|
|
12
|
+
# @option moeda [String] :moeda_plural moeda no plural
|
|
13
|
+
# @option moeda [String] :fracao_plural fracao no plural
|
|
14
|
+
# @return [void]
|
|
15
|
+
def self.epmo(moeda)
|
|
16
|
+
# parametrizacao por defeito
|
|
17
|
+
# the first mention of a @<variable> creates that instance variable
|
|
18
|
+
# in the current object ie: self = ExtensoPt
|
|
19
|
+
@lc = moeda[:lc] || :pt
|
|
20
|
+
@ms = moeda[:moeda_singular] || 'EURO'
|
|
21
|
+
@fs = moeda[:fracao_singular] || 'CÊNTIMO'
|
|
22
|
+
@mp = moeda[:moeda_plural] || @ms + 'S'
|
|
23
|
+
@fp = moeda[:fracao_plural] || @fs + 'S'
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Parametrizar parte inteira e fracionaria
|
|
27
|
+
#
|
|
28
|
+
# @param [String] digitos do valor monetario a converter
|
|
29
|
+
# @return [void]
|
|
30
|
+
def self.epif(digitos)
|
|
31
|
+
# cria array de grupos 3 digitos da parte inteira
|
|
32
|
+
# ex: 123022.12 => [22, 123]
|
|
33
|
+
@ai = digitos[/^\d+/].to_s.reverse.scan(/\d{1,3}/)
|
|
34
|
+
.map { |i| i.reverse.to_i }
|
|
35
|
+
|
|
36
|
+
# obtem parte fracionaria da string digitos
|
|
37
|
+
# ex: 123022.12 => 12
|
|
38
|
+
# arredondada a 2 casas decimais (centimos/centavos)
|
|
39
|
+
@nf = (digitos[/\.\d*/].to_f * 100).round
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Array grupos 3 digitos da parte inteira
|
|
43
|
+
#
|
|
44
|
+
# @return array[Integer] attr_reader
|
|
45
|
+
def self.ivai
|
|
46
|
+
@ai
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Soma grupos 1-8 de digitos
|
|
50
|
+
#
|
|
51
|
+
# @return [Integer] soma digitos
|
|
52
|
+
def self.c124
|
|
53
|
+
@ai[0].to_i + @ai[1].to_i * 2 + @ai[2..-1].to_a.inject(:+).to_i * 2
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Controla proposicao DE
|
|
57
|
+
#
|
|
58
|
+
# @return [true, false] sim ou nao proposicao DE
|
|
59
|
+
def self.cpde?
|
|
60
|
+
@ai[0..1].to_a.inject(:+).to_i.zero? &&
|
|
61
|
+
@ai[2..-1].to_a.inject(:+).to_i.positive?
|
|
62
|
+
end
|
|
63
|
+
# private_class_method :c124, :cpde?
|
|
64
|
+
end
|
data/lib/extenso_pt/version.rb
CHANGED
data/lib/extenso_pt.rb
CHANGED
|
@@ -1,41 +1,83 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'bigdecimal/util'
|
|
4
|
-
require 'extenso_pt/version'
|
|
5
4
|
require 'extenso_pt/constantes'
|
|
5
|
+
require 'extenso_pt/variaveis'
|
|
6
6
|
require 'extenso_pt/extenso'
|
|
7
7
|
require 'extenso_pt/romana'
|
|
8
|
+
require 'extenso_pt/version'
|
|
8
9
|
|
|
9
10
|
# @author Hernani Rodrigues Vaz
|
|
10
11
|
module ExtensoPt
|
|
11
12
|
class Error < StandardError; end
|
|
12
|
-
|
|
13
13
|
# Produz extenso em portugues de portugal ou brasil
|
|
14
14
|
# (valor numerico pode ser uma string digitos)
|
|
15
15
|
#
|
|
16
16
|
# @param [Hash] moeda as opcoes para parametrizar moeda/fracao
|
|
17
17
|
# @option moeda [Symbol] :lc locale do extenso -
|
|
18
18
|
# portugues de portugal (:pt) portugues do brasil (:br)
|
|
19
|
-
# @option moeda [String] :
|
|
20
|
-
# @option moeda [String] :
|
|
21
|
-
# @option moeda [String] :
|
|
22
|
-
# @option moeda [String] :
|
|
23
|
-
# @return [String, Array, Hash]
|
|
24
|
-
# se objecto for (String, Float, Integer),
|
|
19
|
+
# @option moeda [String] :moeda_singular moeda no singular
|
|
20
|
+
# @option moeda [String] :fracao_singular fracao no singular
|
|
21
|
+
# @option moeda [String] :moeda_plural moeda no plural
|
|
22
|
+
# @option moeda [String] :fracao_plural fracao no plural
|
|
23
|
+
# @return [String, Array, Hash]
|
|
24
|
+
# string<extenso> se objecto for (String, Float, Integer),
|
|
25
25
|
# array<extensos> se objecto for (Array, Range),
|
|
26
|
-
# hash<extensos>
|
|
27
|
-
def extenso(moeda = { lc: :pt
|
|
28
|
-
#
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
# hash<extensos> se objecto for (Hash)
|
|
27
|
+
def extenso(moeda = { lc: :pt })
|
|
28
|
+
# parametrizar moeda
|
|
29
|
+
ExtensoPt.epmo(moeda.parametrizar)
|
|
30
|
+
|
|
31
|
+
processa
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Processa objeto criando extenso(s) em portugues de portugal ou brasil
|
|
35
|
+
#
|
|
36
|
+
# @return [String, Array, Hash]
|
|
37
|
+
# string<extenso> se objecto for (String, Float, Integer),
|
|
38
|
+
# array<extensos> se objecto for (Array, Range),
|
|
39
|
+
# hash<extensos> se objecto for (Hash)
|
|
40
|
+
def processa
|
|
41
|
+
# converte valores do Hash nos seus extensos
|
|
42
|
+
if is_a?(Hash) then map { |k, v| [k, v.processa] }.to_h
|
|
43
|
+
# converte objecto num Array com os valores convertidos nos seus extensos
|
|
44
|
+
elsif respond_to?(:to_a) then to_a.map(&:processa)
|
|
45
|
+
else
|
|
46
|
+
# converte objeto em string digitos utilizando bigdecimal para
|
|
47
|
+
# evitar problemas com aritmetica virgula flutuante em valores >1e12
|
|
48
|
+
# parametrizar parte inteira/fracionaria (@ai, @nf) da string digitos
|
|
49
|
+
ExtensoPt.epif(to_d.to_s('F'))
|
|
50
|
+
|
|
51
|
+
# processar extenso - valores >1e24 sao ignorados
|
|
52
|
+
ExtensoPt.ivai.count > 8 ? '' : ExtensoPt.ejun(0, '')
|
|
31
53
|
end
|
|
54
|
+
end
|
|
32
55
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
56
|
+
# Parametrizacao por defeito para :br
|
|
57
|
+
#
|
|
58
|
+
# @return [Hash] parametrizacao moeda
|
|
59
|
+
def parametrizar
|
|
60
|
+
if value?(:br) &&
|
|
61
|
+
%i[moeda_singular moeda_plural].all? { |e| !keys.include?(e) }
|
|
62
|
+
{ lc: :br, moeda_singular: 'REAL', moeda_plural: 'REAIS',
|
|
63
|
+
fracao_singular: 'CENTAVO', fracao_plural: 'CENTAVOS' }
|
|
64
|
+
else
|
|
65
|
+
inferir_singular
|
|
66
|
+
end
|
|
67
|
+
end
|
|
36
68
|
|
|
37
|
-
|
|
38
|
-
|
|
69
|
+
# Parametrizacao singular inferindo do plural
|
|
70
|
+
#
|
|
71
|
+
# @return [Hash] parametrizacao moeda
|
|
72
|
+
def inferir_singular
|
|
73
|
+
self[:moeda_singular] ||= if fetch(:moeda_plural, '')[-1] == 'S'
|
|
74
|
+
fetch(:moeda_plural, '')[0..-2]
|
|
75
|
+
end
|
|
76
|
+
self[:fracao_singular] ||= if fetch(:fracao_plural, '')[-1] == 'S'
|
|
77
|
+
fetch(:fracao_plural, '')[0..-2]
|
|
78
|
+
end
|
|
79
|
+
# eliminar parametros errados
|
|
80
|
+
keep_if { |k, v| MOEDA.include?(k) && (k != :lc || EXTLC.include?(v)) }
|
|
39
81
|
end
|
|
40
82
|
|
|
41
83
|
# Testa se contem numeracao romana
|
|
@@ -64,27 +106,13 @@ module ExtensoPt
|
|
|
64
106
|
end
|
|
65
107
|
end
|
|
66
108
|
|
|
67
|
-
#
|
|
68
|
-
class Hash
|
|
69
|
-
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
# permite obter um Array com valores do Range convertidos
|
|
78
|
-
class Range
|
|
79
|
-
include ExtensoPt
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
# permite obter Float ou Integer convertidos
|
|
83
|
-
class Numeric
|
|
84
|
-
include ExtensoPt
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
# permite obter strings convertidas
|
|
88
|
-
class String
|
|
89
|
-
include ExtensoPt
|
|
90
|
-
end
|
|
109
|
+
# converter Hash
|
|
110
|
+
class Hash; include ExtensoPt; end
|
|
111
|
+
# converter Array
|
|
112
|
+
class Array; include ExtensoPt; end
|
|
113
|
+
# converter Range
|
|
114
|
+
class Range; include ExtensoPt; end
|
|
115
|
+
# converter Float, Integer
|
|
116
|
+
class Numeric; include ExtensoPt; end
|
|
117
|
+
# converter Strings
|
|
118
|
+
class String; include ExtensoPt; end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: extenso_pt
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Hernâni Rodrigues Vaz
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-11-
|
|
11
|
+
date: 2019-11-24 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -58,14 +58,14 @@ dependencies:
|
|
|
58
58
|
requirements:
|
|
59
59
|
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: 1.4
|
|
61
|
+
version: '1.4'
|
|
62
62
|
type: :runtime
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
66
|
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: 1.4
|
|
68
|
+
version: '1.4'
|
|
69
69
|
description: Produz extenso em portugês de portugal, brasil ou numeracao romana. Os
|
|
70
70
|
valores podem ser um numerico, uma string de digitos ou um conjunto destes agrupados
|
|
71
71
|
em (array, range, hash). O extenso pode ser produzido na escala longa (utilizada
|
|
@@ -92,6 +92,7 @@ files:
|
|
|
92
92
|
- lib/extenso_pt/constantes.rb
|
|
93
93
|
- lib/extenso_pt/extenso.rb
|
|
94
94
|
- lib/extenso_pt/romana.rb
|
|
95
|
+
- lib/extenso_pt/variaveis.rb
|
|
95
96
|
- lib/extenso_pt/version.rb
|
|
96
97
|
homepage: https://github.com/hernanilr/extenso_pt
|
|
97
98
|
licenses:
|