extenso_pt 0.6.8 → 0.6.9

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: f3c85e73c00f9ad91da3664b425f6496f31bf77b2215672dc9e1eb440862f603
4
+ data.tar.gz: cd138e1dada000bb8e772b36b78a96fcae555bbc552931e3e8a18a71ebb55f0f
5
5
  SHA512:
6
- metadata.gz: 4efd27e160444288dc581130369a8c7873ad57fa0521efb082e08634d11cba96417ce37beee2bd45b08aa0d7c84983822aabc666430aad0399634e9121ca5f33
7
- data.tar.gz: 0bf776b8e3b06910010735e71d6c63da7df12e8e47c706dc866dba3d7941c2f23f76e40a485c64de994b7ebc237e1aa7e8f5ada1beec2e91b8437b0b1a29106e
6
+ metadata.gz: c8337da02b55273cf83bde20da682fe43c9348c338233993d64dc30752cbbc2329171c20ebae84289362e283f37c90ec5ce1b98fa33e7a01e2b76b7da97ff730
7
+ data.tar.gz: 4b6ccdcdd967fed66a3e7b9eeeed40ff40d2e9494890121829d17d19cdcd290f29cd3305ef435feff01ba44655eb733b10aedd9f7f30f8780507b05f21f0d92c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- extenso_pt (0.6.8)
4
+ extenso_pt (0.6.9)
5
5
  bigdecimal (~> 1.4)
6
6
 
7
7
  GEM
@@ -13,30 +13,30 @@ module ExtensoPt
13
13
  # Produz extenso em portugues de portugal ou brasil
14
14
  # (valor numerico pode ser uma string digitos)
15
15
  #
16
- # @param [Hash] moeda as opcoes para parametrizar moeda/fracao
16
+ # @param [Hash<String, Symbol>] moeda opcoes parametrizar moeda/fracao
17
17
  # @option moeda [Symbol] :lc locale do extenso -
18
18
  # portugues de portugal (:pt) portugues do brasil (:br)
19
19
  # @option moeda [String] :moeda_singular moeda no singular
20
20
  # @option moeda [String] :fracao_singular fracao no singular
21
21
  # @option moeda [String] :moeda_plural moeda no plural
22
22
  # @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)
23
+ # @return [String, Array<String>, Hash<String>]
24
+ # String<extenso> se objecto for (String, Float, Integer),
25
+ # Array<extensos> se objecto for (Array, Range),
26
+ # Hash<extensos> se objecto for (Hash)
27
27
  def extenso(moeda = { lc: :pt })
28
28
  # parametrizar moeda
29
- ExtensoPt.epmo(moeda.parametrizar)
29
+ ExtensoPt.prmo(moeda.parametrizar)
30
30
 
31
31
  processa
32
32
  end
33
33
 
34
34
  # Processa objeto criando extenso(s) em portugues de portugal ou brasil
35
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)
36
+ # @return [String, Array<String>, Hash<String>]
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
40
  def processa
41
41
  # converte valores do Hash nos seus extensos
42
42
  if is_a?(Hash) then map { |k, v| [k, v.processa] }.to_h
@@ -46,16 +46,16 @@ module ExtensoPt
46
46
  # converte objeto em string digitos utilizando bigdecimal para
47
47
  # evitar problemas com aritmetica virgula flutuante em valores >1e12
48
48
  # parametrizar parte inteira/fracionaria (@ai, @nf) da string digitos
49
- ExtensoPt.epif(to_d.to_s('F'))
49
+ ExtensoPt.prif(to_d.to_s('F'))
50
50
 
51
51
  # processar extenso - valores >1e24 sao ignorados
52
- ExtensoPt.ivai.count > 8 ? '' : ExtensoPt.ejun(0, '')
52
+ ExtensoPt.cvai.count > 8 ? '' : ExtensoPt.ejun
53
53
  end
54
54
  end
55
55
 
56
56
  # Parametrizacao por defeito para :br
57
57
  #
58
- # @return [Hash] parametrizacao moeda
58
+ # @return [Hash<String, Symbol>] parametrizacao moeda
59
59
  def parametrizar
60
60
  if value?(:br) &&
61
61
  %i[moeda_singular moeda_plural].all? { |e| !keys.include?(e) }
@@ -68,7 +68,7 @@ module ExtensoPt
68
68
 
69
69
  # Parametrizacao singular inferindo do plural
70
70
  #
71
- # @return [Hash] parametrizacao moeda
71
+ # @return [Hash<String, Symbol>] parametrizacao moeda
72
72
  def inferir_singular
73
73
  self[:moeda_singular] ||= if fetch(:moeda_plural, '')[-1] == 'S'
74
74
  fetch(:moeda_plural, '')[0..-2]
@@ -96,7 +96,7 @@ module ExtensoPt
96
96
  # @param [Integer] pos posicao no grupo 3 digitos
97
97
  # @param [String] ext extenso em construcao
98
98
  # @return [String] extenso do valor monetario
99
- def self.ejun(pos, ext)
99
+ def self.ejun(pos = 0, ext = '')
100
100
  # testa fim do valor monetario
101
101
  if pos >= @ai.count
102
102
  # caso especial de zero
@@ -4,15 +4,14 @@
4
4
  module ExtensoPt
5
5
  # Parametrizar moeda
6
6
  #
7
- # @param [Hash] moeda as opcoes para parametrizar moeda/fracao
7
+ # @param [Hash<String, Symbol>] moeda opcoes parametrizar moeda/fracao
8
8
  # @option moeda [Symbol] :lc locale do extenso -
9
9
  # portugues de portugal (:pt) portugues do brasil (:br)
10
10
  # @option moeda [String] :moeda_singular moeda no singular
11
11
  # @option moeda [String] :fracao_singular fracao no singular
12
12
  # @option moeda [String] :moeda_plural moeda no plural
13
13
  # @option moeda [String] :fracao_plural fracao no plural
14
- # @return [void]
15
- def self.epmo(moeda)
14
+ def self.prmo(moeda)
16
15
  # parametrizacao por defeito
17
16
  # the first mention of a @<variable> creates that instance variable
18
17
  # in the current object ie: self = ExtensoPt
@@ -26,8 +25,7 @@ module ExtensoPt
26
25
  # Parametrizar parte inteira e fracionaria
27
26
  #
28
27
  # @param [String] digitos do valor monetario a converter
29
- # @return [void]
30
- def self.epif(digitos)
28
+ def self.prif(digitos)
31
29
  # cria array de grupos 3 digitos da parte inteira
32
30
  # ex: 123022.12 => [22, 123]
33
31
  @ai = digitos[/^\d+/].to_s.reverse.scan(/\d{1,3}/)
@@ -39,31 +37,23 @@ module ExtensoPt
39
37
  @nf = (digitos[/\.\d*/].to_f * 100).round
40
38
  end
41
39
 
42
- # Array grupos 3 digitos da parte inteira
43
- #
44
- # @return array[Integer] attr_reader
45
- def self.ivai
40
+ # @return [Array<Integer>] grupos 3 digitos da parte inteira
41
+ def self.cvai
46
42
  @ai
47
43
  end
48
44
 
49
- # Soma grupos 1-8 de digitos
50
- #
51
- # @return [Integer] soma digitos
45
+ # @return [Integer] soma grupos 1-8 de digitos
52
46
  def self.c124
53
47
  @ai[0].to_i + @ai[1].to_i * 2 + @ai[2..-1].to_a.inject(:+).to_i * 2
54
48
  end
55
49
 
56
- # Controla proposicao DE
57
- #
58
- # @return [true, false] sim ou nao proposicao DE
50
+ # @return [true, false] sim ou nao para controle proposicao DE
59
51
  def self.cde?
60
52
  @ai[0..1].to_a.inject(:+).to_i.zero? &&
61
53
  @ai[2..-1].to_a.inject(:+).to_i.positive?
62
54
  end
63
55
 
64
- # Controla proposicao E
65
- #
66
- # @return [true, false] sim ou nao proposicao E
56
+ # @return [true, false] sim ou nao para controle proposicao E
67
57
  def self.cnf?
68
58
  @nf.positive?
69
59
  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.6.9'
5
5
  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.8
4
+ version: 0.6.9
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-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler