extenso_pt 0.6.8 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d22c60bebdce5b03bcc2b3b3310905cec4b0437359b7c3dfe04a34fe153ad946
4
- data.tar.gz: 94afcdbee0f86983007bfc6e15efd0b08ff9f906bc4f3e3f157cb627bf264cf1
3
+ metadata.gz: 585d41335b5503f750798310e043e7a90a55b37a616eb2fc34e8399cc7bde3df
4
+ data.tar.gz: 86f6231beffdac04d18c5a32a452e48fa090e70d24a12912d0fecdb88dfbbe57
5
5
  SHA512:
6
- metadata.gz: 4efd27e160444288dc581130369a8c7873ad57fa0521efb082e08634d11cba96417ce37beee2bd45b08aa0d7c84983822aabc666430aad0399634e9121ca5f33
7
- data.tar.gz: 0bf776b8e3b06910010735e71d6c63da7df12e8e47c706dc866dba3d7941c2f23f76e40a485c64de994b7ebc237e1aa7e8f5ada1beec2e91b8437b0b1a29106e
6
+ metadata.gz: 8a3741e89853e408a92e655c5333cd1e718f1b5d308f9b09ba5c50302f77de1560d272da2f9aff18c956e952f870b3964425222d4faff673fe491581b2e40bd7
7
+ data.tar.gz: 113ac582f6ac5f4554b83dd64ca4e842b45b2f470c6fbfb4c1154633090fa6a8157aaf027aaecb7502623ead61b361524d7e13c9e2a72d624c9f62e976796d19
@@ -1,24 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- extenso_pt (0.6.8)
5
- bigdecimal (~> 1.4)
4
+ extenso_pt (0.7.0)
5
+ bigdecimal
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- bigdecimal (1.4.4)
11
- minitest (5.13.0)
12
- rake (10.5.0)
10
+ bigdecimal (2.0.0)
11
+ minitest (5.14.1)
12
+ rake (13.0.1)
13
13
 
14
14
  PLATFORMS
15
15
  ruby
16
16
 
17
17
  DEPENDENCIES
18
- bundler (~> 1.17)
18
+ bundler
19
19
  extenso_pt!
20
- minitest (~> 5.0)
21
- rake (~> 10.0)
20
+ minitest
21
+ rake
22
22
 
23
23
  BUNDLED WITH
24
- 1.17.2
24
+ 2.1.2
@@ -12,14 +12,11 @@ Gem::Specification.new do |spec|
12
12
  spec.homepage = 'https://github.com/hernanilr/extenso_pt'
13
13
  spec.license = 'MIT'
14
14
 
15
- spec.summary = 'Produz extenso em portugês de portugal, brasil '\
16
- 'ou numeracao romana.'
15
+ spec.summary = 'Produz extenso em portugês de portugal, brasil ou numeracao romana.'
17
16
  spec.description = spec.summary
18
- spec.description += ' Os valores podem ser um numerico, uma string de '\
19
- 'digitos ou um conjunto destes agrupados em (array, range, hash). '\
20
- 'O extenso pode ser produzido na escala longa (utilizada em todos os '\
21
- 'países lusófonos) ou na escala curta (utilizada no Brasil). Pode ainda '\
22
- 'produzir numeracao romana e vice versa.'
17
+ spec.description += ' Os valores podem ser um numerico, uma string de digitos ou um conjunto destes agrupados em '\
18
+ '(array, range, hash). O extenso pode ser produzido na escala longa (utilizada em todos os países lusófonos) ou '\
19
+ 'na escala curta (utilizada no Brasil). Pode ainda produzir numeracao romana e vice versa.'
23
20
 
24
21
  spec.metadata['yard.run'] = 'yard' # use "yard" to build full HTML docs.
25
22
  spec.metadata['homepage_uri'] = spec.homepage
@@ -27,16 +24,15 @@ Gem::Specification.new do |spec|
27
24
  # Specify which files should be added to the gem when it is released.
28
25
  # loads the files in the RubyGem that have been added into git.
29
26
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
30
- `git ls-files -z`.split("\x0").reject \
31
- { |f| f.match(%r{^(test|spec|features)/}) }
27
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
32
28
  end
33
29
  spec.bindir = 'exe'
34
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
31
  spec.require_paths = ['lib']
36
32
 
37
- spec.add_development_dependency 'bundler', '~> 1.17'
38
- spec.add_development_dependency 'minitest', '~> 5.0'
39
- spec.add_development_dependency 'rake', '~> 10.0'
33
+ spec.add_development_dependency 'bundler'
34
+ spec.add_development_dependency 'minitest'
35
+ spec.add_development_dependency 'rake'
40
36
 
41
- spec.add_dependency 'bigdecimal', '~> 1.4'
37
+ spec.add_dependency 'bigdecimal'
42
38
  end
@@ -10,33 +10,29 @@ require 'extenso_pt/version'
10
10
  # @author Hernani Rodrigues Vaz
11
11
  module ExtensoPt
12
12
  class Error < StandardError; end
13
- # Produz extenso em portugues de portugal ou brasil
14
- # (valor numerico pode ser uma string digitos)
13
+ # Produz extenso em portugues de portugal ou brasil a partir de valor numerico
15
14
  #
16
- # @param [Hash] moeda as opcoes para parametrizar moeda/fracao
17
- # @option moeda [Symbol] :lc locale do extenso -
18
- # portugues de portugal (:pt) portugues do brasil (:br)
15
+ # @note valor numerico pode ser uma string digitos
16
+ # @param [Hash<String, Symbol>] moeda opcoes parametrizar moeda/fracao
17
+ # @option moeda [Symbol] :lc locale do extenso - portugues de portugal (:pt) portugues do brasil (:br)
19
18
  # @option moeda [String] :moeda_singular moeda no singular
20
19
  # @option moeda [String] :fracao_singular fracao no singular
21
20
  # @option moeda [String] :moeda_plural moeda no plural
22
21
  # @option moeda [String] :fracao_plural fracao no plural
23
- # @return [String, Array, Hash]
24
- # string<extenso> se objecto for (String, Float, Integer),
25
- # array<extensos> se objecto for (Array, Range),
26
- # hash<extensos> se objecto for (Hash)
22
+ # @return [String, Array<String>, Hash<String>]
23
+ # String<extenso> se objecto for (String, Float, Integer),
24
+ # Array<extensos> se objecto for (Array, Range),
25
+ # Hash<extensos> se objecto for (Hash)
27
26
  def extenso(moeda = { lc: :pt })
28
27
  # parametrizar moeda
29
- ExtensoPt.epmo(moeda.parametrizar)
28
+ ExtensoPt.prmo(moeda.parametrizar)
30
29
 
31
30
  processa
32
31
  end
33
32
 
34
33
  # Processa objeto criando extenso(s) em portugues de portugal ou brasil
35
34
  #
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)
35
+ # @return (see #extenso)
40
36
  def processa
41
37
  # converte valores do Hash nos seus extensos
42
38
  if is_a?(Hash) then map { |k, v| [k, v.processa] }.to_h
@@ -46,59 +42,47 @@ module ExtensoPt
46
42
  # converte objeto em string digitos utilizando bigdecimal para
47
43
  # evitar problemas com aritmetica virgula flutuante em valores >1e12
48
44
  # parametrizar parte inteira/fracionaria (@ai, @nf) da string digitos
49
- ExtensoPt.epif(to_d.to_s('F'))
45
+ ExtensoPt.prif(to_d.to_s('F'))
50
46
 
51
47
  # processar extenso - valores >1e24 sao ignorados
52
- ExtensoPt.ivai.count > 8 ? '' : ExtensoPt.ejun(0, '')
48
+ ExtensoPt.cvai.count > 8 ? '' : ExtensoPt.ejun
53
49
  end
54
50
  end
55
51
 
56
- # Parametrizacao por defeito para :br
57
- #
58
- # @return [Hash] parametrizacao moeda
52
+ # @return [Hash<String, Symbol>] parametrizacao moeda por defeito para :br & inferencias & errados
59
53
  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' }
54
+ if value?(:br) && %i[moeda_singular moeda_plural].all? { |e| !keys.include?(e) }
55
+ { lc: :br, moeda_singular: 'REAL', moeda_plural: 'REAIS', fracao_singular: 'CENTAVO', fracao_plural: 'CENTAVOS' }
64
56
  else
65
- inferir_singular
57
+ inferir_singular.eliminar_errados
66
58
  end
67
59
  end
68
60
 
69
- # Parametrizacao singular inferindo do plural
70
- #
71
- # @return [Hash] parametrizacao moeda
61
+ # @return [Hash<String, Symbol>] parametrizacao moeda singular inferindo do plural
72
62
  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
63
+ self[:moeda_singular] ||= (fetch(:moeda_plural, '')[0..-2] if fetch(:moeda_plural, '')[-1] == 'S')
64
+ self[:fracao_singular] ||= (fetch(:fracao_plural, '')[0..-2] if fetch(:fracao_plural, '')[-1] == 'S')
65
+ self
66
+ end
67
+
68
+ # @return [Hash<String, Symbol>] parametrizacao moeda eliminar parametros errados
69
+ def eliminar_errados
80
70
  keep_if { |k, v| MOEDA.include?(k) && (k != :lc || EXTLC.include?(v)) }
81
71
  end
82
72
 
83
- # Testa se contem numeracao romana
84
- #
85
- # @return [true, false] sim ou nao numeracao romana
73
+ # @return [true, false] testa se contem numeracao romana
86
74
  def romana?
87
75
  is_a?(String) ? RO_RE.match?(upcase) : false
88
76
  end
89
77
 
90
- # Produz numeracao romana a partir de valor numerico
91
- # ou valor numerico a partir da numeracao romana
92
- # (valor numerico pode ser uma string digitos)
93
- #
94
- # @return [String, Integer] numeracao romana ou valor numerico
78
+ # @note valor numerico pode ser uma string digitos
79
+ # @return [String, Integer] numeracao romana a partir de numerico ou inteiro a partir da numeracao romana
95
80
  def romana
96
81
  # converte os valores do Hash
97
82
  if is_a?(Hash) then map { |k, v| [k, v.romana] }.to_h
98
83
  # converte objecto num Array com os valores convertidos
99
84
  elsif respond_to?(:to_a) then to_a.map(&:romana)
100
- # numeracao romana a partir de inteiro ou string digitos
101
- # (ignora parte fracionaria)
85
+ # numeracao romana a partir de inteiro ou string digitos (ignora parte fracionaria)
102
86
  elsif (inteiro = to_i) != 0 then ExtensoPt.ri2r(inteiro)
103
87
  # inteiro a partir da numeracao romana
104
88
  else RO_RE.match?(to_s) ? ExtensoPt.rr2i(upcase, 0) : ''
@@ -3,37 +3,33 @@
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
+ MOEDA = %i[moeda_singular fracao_singular moeda_plural fracao_plural lc].freeze
7
+
8
+ # somente portugues de portugal ou brasil permitidos, qualquer outro locale equivale usar :pt
10
9
  EXTLC = %i[pt br].freeze
10
+
11
+ E13 = %w[UM DOIS TRÊS QUATRO CINCO SEIS SETE OITO NOVE DEZ ONZE DOZE TREZE].freeze
12
+
11
13
  # extensos 1 ate 19
12
14
  A0020 = {
13
- pt: ['', 'UM', 'DOIS', 'TRÊS', 'QUATRO', 'CINCO', 'SEIS', 'SETE',
14
- 'OITO', 'NOVE', 'DEZ', 'ONZE', 'DOZE', 'TREZE', 'CATORZE',
15
- 'QUINZE', 'DEZASSEIS', 'DEZASSETE', 'DEZOITO', 'DEZANOVE'],
16
- br: ['', 'UM', 'DOIS', 'TRES', 'QUATRO', 'CINCO', 'SEIS', 'SETE',
17
- 'OITO', 'NOVE', 'DEZ', 'ONZE', 'DOZE', 'TREZE', 'QUATORZE',
18
- 'QUINZE', 'DEZESSEIS', 'DEZESSETE', 'DEZOITO', 'DEZENOVE']
15
+ pt: [''] + E13 + %w[CATORZE QUINZE DEZASSEIS DEZASSETE DEZOITO DEZANOVE],
16
+ br: [''] + E13 + %w[QUATORZE QUINZE DEZESSEIS DEZESSETE DEZOITO DEZENOVE]
19
17
  }.freeze
18
+
20
19
  # extensos 20 ate 90
21
20
  A0100 = {
22
- pt: ['', '', 'VINTE', 'TRINTA', 'QUARENTA', 'CINQUENTA', 'SESSENTA',
23
- 'SETENTA', 'OITENTA', 'NOVENTA'],
24
- br: ['', '', 'VINTE', 'TRINTA', 'QUARENTA', 'CINQUENTA', 'SESSENTA',
25
- 'SETENTA', 'OITENTA', 'NOVENTA']
21
+ pt: ['', ''] + %w[VINTE TRINTA QUARENTA CINQUENTA SESSENTA SETENTA OITENTA NOVENTA],
22
+ br: ['', ''] + %w[VINTE TRINTA QUARENTA CINQUENTA SESSENTA SETENTA OITENTA NOVENTA]
26
23
  }.freeze
24
+
27
25
  # extensos 100 ate 900
28
26
  A1000 = {
29
- pt: ['', 'CEM', 'CENTO', 'DUZENTOS', 'TREZENTOS', 'QUATROCENTOS',
30
- 'QUINHENTOS', 'SEISCENTOS', 'SETECENTOS', 'OITOCENTOS', 'NOVECENTOS'],
31
- br: ['', 'CEM', 'CENTO', 'DUZENTOS', 'TREZENTOS', 'QUATROCENTOS',
32
- 'QUINHENTOS', 'SEISCENTOS', 'SETECENTOS', 'OITOCENTOS', 'NOVECENTOS']
27
+ pt: [''] + %w[CEM CENTO DUZENTOS TREZENTOS QUATROCENTOS QUINHENTOS SEISCENTOS SETECENTOS OITOCENTOS NOVECENTOS],
28
+ br: [''] + %w[CEM CENTO DUZENTOS TREZENTOS QUATROCENTOS QUINHENTOS SEISCENTOS SETECENTOS OITOCENTOS NOVECENTOS]
33
29
  }.freeze
34
30
 
35
31
  # singular extensos 1e3 ate 1e24
36
- # escala segundo convencao entre varios paises,
32
+ # @note escala segundo convencao entre varios paises,
37
33
  # na 9a Conferencia Geral de Pesos e Medidas (12-21 de Outubro de 1948),
38
34
  # organizada pelo Bureau International des Poids et Mesures
39
35
  # @example
@@ -43,24 +39,25 @@ module ExtensoPt
43
39
  # 1 000 000 000 000 000 000 000 000 = quadriliao
44
40
  # 1 000 000 000 000 000 000 000 000 000 000 = quintiliao
45
41
  # 1 000 000 000 000 000 000 000 000 000 000 000 000 = sextiliao
46
- S1E24 = { pt: ['', 'MIL', ' MILHÃO', ' MIL MILHÃO', ' BILIÃO',
47
- ' MIL BILIÃO', ' TRILIÃO', ' MIL TRILIÃO'],
48
- br: ['', 'MIL', ' MILHÃO', ' BILHÃO', ' TRILHÃO',
49
- ' QUADRILHÃO', ' QUINTILHÃO', ' SEXTILHÃO'] }.freeze
42
+ S1E24 = {
43
+ pt: ['', 'MIL', ' MILHÃO', ' MIL MILHÃO', ' BILIÃO', ' MIL BILIÃO', ' TRILIÃO', ' MIL TRILIÃO'],
44
+ br: ['', 'MIL', ' MILHÃO', ' BILHÃO', ' TRILHÃO', ' QUADRILHÃO', ' QUINTILHÃO', ' SEXTILHÃO']
45
+ }.freeze
46
+
50
47
  # plural extensos 1e3 ate 1e24
51
- P1E24 = { pt: ['', ' MIL', ' MILHÕES', ' MIL MILHÕES', ' BILIÕES',
52
- ' MIL BILIÕES', ' TRILIÕES', ' MIL TRILIÕES'],
53
- br: ['', ' MIL', ' MILHÕES', ' BILHÕES', ' TRILHÕES',
54
- ' QUADRILHÕES', ' QUINTILHÕES', ' SEXTILHÕES'] }.freeze
48
+ # @note escala segundo convencao entre varios paises,
49
+ # na 9a Conferencia Geral de Pesos e Medidas (12-21 de Outubro de 1948),
50
+ # organizada pelo Bureau International des Poids et Mesures
51
+ P1E24 = {
52
+ pt: ['', ' MIL', ' MILHÕES', ' MIL MILHÕES', ' BILIÕES', ' MIL BILIÕES', ' TRILIÕES', ' MIL TRILIÕES'],
53
+ br: ['', ' MIL', ' MILHÕES', ' BILHÕES', ' TRILHÕES', ' QUADRILHÕES', ' QUINTILHÕES', ' SEXTILHÕES']
54
+ }.freeze
55
55
 
56
56
  # numeracao romana
57
- ROMAN = { M: 1000, CM: 900,
58
- D: 500, CD: 400,
59
- C: 100, XC: 90,
60
- L: 50, XL: 40,
61
- X: 10, IX: 9,
62
- V: 5, IV: 4,
63
- I: 1 }.freeze
64
- # exprecao regular da numeracao romana
57
+ ROMAN = {
58
+ M: 1000, CM: 900, D: 500, CD: 400, C: 100, XC: 90, L: 50, XL: 40, X: 10, IX: 9, V: 5, IV: 4, I: 1
59
+ }.freeze
60
+
61
+ # expressao regular da numeracao romana
65
62
  RO_RE = /^M*(D?C{0,3}|C[DM])(L?X{0,3}|X[LC])(V?I{0,3}|I[VX])$/i.freeze
66
63
  end
@@ -28,9 +28,7 @@ module ExtensoPt
28
28
  A0020[@lc][cem < 20 ? cem : cem % 10]
29
29
  end
30
30
 
31
- # Produz extenso da parte fracionaria em portugues de portugal ou brasil
32
- #
33
- # @return [String] extenso da parte fracionaria
31
+ # @return [String] extenso da parte fracionaria em portugues de portugal ou brasil
34
32
  def self.ef99
35
33
  if cnf?
36
34
  e090(@nf) + e009(@nf) + ' ' + (@nf > 1 ? @fp : @fs)
@@ -39,25 +37,21 @@ module ExtensoPt
39
37
  end
40
38
  end
41
39
 
42
- # Produz final da moeda em portugues de portugal ou brasil
43
- #
44
- # @return [String] final da moeda
40
+ # @return [String] final da moeda em portugues de portugal ou brasil
45
41
  def self.efim
46
42
  t = c124
47
43
  if t.positive?
48
- # proposicao DE entre parte inteira e moeda
49
- # moeda singular/plural
50
- # proposicao E entre moeda e parte fracionaria
44
+ # proposicao DE entre parte inteira e moeda & moeda singular/plural & proposicao E entre moeda e parte fracionaria
51
45
  (cde? ? ' DE ' : ' ') + (t > 1 ? @mp : @ms) + (cnf? ? ' E ' : '')
52
46
  else
53
47
  ''
54
48
  end + ef99
55
49
  end
56
50
 
57
- # Produz separador entre grupos 3 digitos
51
+ # Produz proposicao E entre grupos 3 digitos
58
52
  #
59
53
  # @param [Integer] pos posicao actual nos grupos 3 digitos
60
- # @return [String] separador entre grupos 3 digitos
54
+ # @return [String] proposicao E entre grupos 3 digitos
61
55
  def self.edgs(pos)
62
56
  if pos.positive? && @ai[pos - 1].positive?
63
57
  @ai[pos - 1] > 100 ? ' ' : ' E '
@@ -87,6 +81,7 @@ module ExtensoPt
87
81
  if pos == 1 && @ai[pos] == 1
88
82
  ''
89
83
  else
84
+ # extenso das centenas + extenso das dezenas + extenso das unidades
90
85
  e900(@ai[pos]) + e090(@ai[pos] % 100) + e009(@ai[pos] % 100)
91
86
  end + e124(pos)
92
87
  end
@@ -96,14 +91,13 @@ module ExtensoPt
96
91
  # @param [Integer] pos posicao no grupo 3 digitos
97
92
  # @param [String] ext extenso em construcao
98
93
  # @return [String] extenso do valor monetario
99
- def self.ejun(pos, ext)
94
+ def self.ejun(pos = 0, ext = '')
100
95
  # testa fim do valor monetario
101
96
  if pos >= @ai.count
102
97
  # caso especial de zero
103
98
  (c124 + @nf).zero? ? 'ZERO ' + @mp : ext + efim
104
99
  else
105
- # converte grupo 3 digitos na posicao corrente
106
- # envoca proxima posicao
100
+ # converte grupo 3 digitos na posicao corrente & envoca proxima posicao
107
101
  ejun(pos + 1, edg3(pos) + ext)
108
102
  end
109
103
  end
@@ -23,6 +23,6 @@ module ExtensoPt
23
23
  return 0 if numeral.empty?
24
24
 
25
25
  v = ROMAN[numeral[-1].to_sym]
26
- v < ultimo ? (rr2i(numeral.chop, v) - v) : (rr2i(numeral.chop, v) + v)
26
+ rr2i(numeral.chop, v) + (v < ultimo ? -v : v)
27
27
  end
28
28
  end
@@ -2,20 +2,17 @@
2
2
 
3
3
  # @author Hernani Rodrigues Vaz
4
4
  module ExtensoPt
5
- # Parametrizar moeda
5
+ # Parametrizar variaveis da moeda
6
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)
7
+ # @param [Hash<String, Symbol>] moeda opcoes parametrizar moeda/fracao
8
+ # @option moeda [Symbol] :lc locale do extenso - portugues de portugal (:pt) portugues do brasil (:br)
10
9
  # @option moeda [String] :moeda_singular moeda no singular
11
10
  # @option moeda [String] :fracao_singular fracao no singular
12
11
  # @option moeda [String] :moeda_plural moeda no plural
13
12
  # @option moeda [String] :fracao_plural fracao no plural
14
- # @return [void]
15
- def self.epmo(moeda)
13
+ def self.prmo(moeda)
16
14
  # parametrizacao por defeito
17
- # the first mention of a @<variable> creates that instance variable
18
- # in the current object ie: self = ExtensoPt
15
+ # the first mention of a @<variable> creates that instance variable in the current object ie: self = ExtensoPt
19
16
  @lc = moeda[:lc] || :pt
20
17
  @ms = moeda[:moeda_singular] || 'EURO'
21
18
  @fs = moeda[:fracao_singular] || 'CÊNTIMO'
@@ -23,47 +20,33 @@ module ExtensoPt
23
20
  @fp = moeda[:fracao_plural] || @fs + 'S'
24
21
  end
25
22
 
26
- # Parametrizar parte inteira e fracionaria
23
+ # Parametrizar variaveis parte inteira e fracionaria
27
24
  #
28
25
  # @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 }
26
+ def self.prif(digitos)
27
+ # cria array de grupos 3 digitos da parte inteira ex: 123022.12 => [22, 123]
28
+ @ai = digitos[/^\d+/].to_s.reverse.scan(/\d{1,3}/).map { |i| i.reverse.to_i }
35
29
 
36
- # obtem parte fracionaria da string digitos
37
- # ex: 123022.12 => 12
38
- # arredondada a 2 casas decimais (centimos/centavos)
30
+ # obtem parte fracionaria da string digitos arredondada a 2 casas decimais ex: 123022.12 => 12
39
31
  @nf = (digitos[/\.\d*/].to_f * 100).round
40
32
  end
41
33
 
42
- # Array grupos 3 digitos da parte inteira
43
- #
44
- # @return array[Integer] attr_reader
45
- def self.ivai
34
+ # @return [Array<Integer>] grupos 3 digitos da parte inteira
35
+ def self.cvai
46
36
  @ai
47
37
  end
48
38
 
49
- # Soma grupos 1-8 de digitos
50
- #
51
- # @return [Integer] soma digitos
39
+ # @return [Integer] soma grupos 1-8 de digitos
52
40
  def self.c124
53
41
  @ai[0].to_i + @ai[1].to_i * 2 + @ai[2..-1].to_a.inject(:+).to_i * 2
54
42
  end
55
43
 
56
- # Controla proposicao DE
57
- #
58
- # @return [true, false] sim ou nao proposicao DE
44
+ # @return [true, false] sim ou nao para controle proposicao DE
59
45
  def self.cde?
60
- @ai[0..1].to_a.inject(:+).to_i.zero? &&
61
- @ai[2..-1].to_a.inject(:+).to_i.positive?
46
+ @ai[0..1].to_a.inject(:+).to_i.zero? && @ai[2..-1].to_a.inject(:+).to_i.positive?
62
47
  end
63
48
 
64
- # Controla proposicao E
65
- #
66
- # @return [true, false] sim ou nao proposicao E
49
+ # @return [true, false] sim ou nao para controle proposicao E
67
50
  def self.cnf?
68
51
  @nf.positive?
69
52
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ExtensoPt
4
- VERSION = '0.6.8'
4
+ VERSION = '0.7.0'
5
5
  end
metadata CHANGED
@@ -1,71 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extenso_pt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.8
4
+ version: 0.7.0
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-24 00:00:00.000000000 Z
11
+ date: 2020-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.17'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.17'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '5.0'
33
+ version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '5.0'
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bigdecimal
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '1.4'
61
+ version: '0'
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: '0'
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
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
117
  requirements: []
118
- rubygems_version: 3.0.3
118
+ rubygems_version: 3.1.2
119
119
  signing_key:
120
120
  specification_version: 4
121
121
  summary: Produz extenso em portugês de portugal, brasil ou numeracao romana.