extenso_pt 0.7.1 → 0.7.2

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: ab0a52c0c901d62b897666d0386a3b3ae6e5e170a65bfb04bbb112631e456d90
4
- data.tar.gz: f6bbe149fd0bfb90035795a7bc21ba9cfd37d185fd2f9ae5c634714292c8480e
3
+ metadata.gz: 60c6fc6aeadb5973a9f9d9b59a2f92a8343c4d4e72dd5ac20d4fe70489022805
4
+ data.tar.gz: 16f3545f8a2a36a14d039c5b92a2f02da487c4f4eef6614ca2d06a83e93d7f3f
5
5
  SHA512:
6
- metadata.gz: 510463fe40f4a1c0da051401e4cdaaf478667f6d1f711bcae7456da64cdc3148308dfd1c4363667d10cf23d6d5d3af7bbb370ccbfec97d5deaf610be01d25f5b
7
- data.tar.gz: 27b7b1dac2a655e3796e046cf709bd7e76683667c5a5a70d082aa3c1bf6325cf5e0c0aa169602cb2276aa0e0e8249abdadcde71cadd9f3f24273a07918d629f9
6
+ metadata.gz: 1edbcbaf07ff510ab740dcd228a3616a18c9e1e4e54b664254eb24ffa34086b2a975f250b5a48a57f226c1346d75e5d7d826ed996ee44a95192716a01e47e482
7
+ data.tar.gz: 4f64f33054298180070746a3c110bc29e40a2513418be0744c0d9074bcebe9245d68f3047b68897e5c2d48d198c4f35f5e78d9a438a4f2c4d881384aea74fdcd
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- extenso_pt (0.7.1)
4
+ extenso_pt (0.7.2)
5
5
  bigdecimal
6
6
 
7
7
  GEM
@@ -41,10 +41,11 @@ module ExtensoPt
41
41
  else
42
42
  # converte objeto em string digitos utilizando bigdecimal para
43
43
  # evitar problemas com aritmetica virgula flutuante em valores >1e12
44
+ # valores negativos sao convertidos em positivos
44
45
  # parametrizar parte inteira/fracionaria (@ai, @nf) da string digitos
45
- ExtensoPt.prif(to_d.to_s('F'))
46
+ ExtensoPt.prif(to_d.abs.to_s('F'))
46
47
 
47
- # processar extenso - valores >1e24 sao ignorados
48
+ # processar extenso - valores >= 1e24 sao ignorados
48
49
  ExtensoPt.cvai.count > 8 ? '' : ExtensoPt.ejun
49
50
  end
50
51
  end
@@ -82,8 +83,8 @@ module ExtensoPt
82
83
  if is_a?(Hash) then transform_values(&:romana)
83
84
  # converte objecto num Array com os valores convertidos
84
85
  elsif respond_to?(:to_a) then to_a.map(&:romana)
85
- # numeracao romana a partir de inteiro ou string digitos (ignora parte fracionaria)
86
- elsif (inteiro = to_i) != 0 then ExtensoPt.ri2r(inteiro)
86
+ # numeracao romana a partir de inteiro ou string digitos (ignora parte fracionaria & negativos)
87
+ elsif (inteiro = to_i) != 0 then ExtensoPt.ri2r(inteiro.abs)
87
88
  # inteiro a partir da numeracao romana
88
89
  else RO_RE.match?(to_s) ? ExtensoPt.rr2i(upcase, 0) : ''
89
90
  end
@@ -53,10 +53,8 @@ module ExtensoPt
53
53
  br: ['', ' MIL', ' MILHÕES', ' BILHÕES', ' TRILHÕES', ' QUADRILHÕES', ' QUINTILHÕES', ' SEXTILHÕES']
54
54
  }.freeze
55
55
 
56
- # 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
56
+ # numeracao romana ordem decrescente (ordem importante)
57
+ ROMAN = { 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 }.freeze
60
58
 
61
59
  # expressao regular da numeracao romana
62
60
  RO_RE = /^M*(D?C{0,3}|C[DM])(L?X{0,3}|X[LC])(V?I{0,3}|I[VX])$/i.freeze
@@ -9,9 +9,9 @@ module ExtensoPt
9
9
  def self.ri2r(inteiro)
10
10
  return '' if inteiro.zero?
11
11
 
12
- # numeracao romana nao tem negativos
13
- inteiro = inteiro.abs if inteiro.negative?
14
- ROMAN.each { |r, v| return r.to_s + ri2r(inteiro - v) if v <= inteiro }
12
+ ROMAN.each do |r, v|
13
+ return r.to_s + ri2r(inteiro - v) if v <= inteiro
14
+ end
15
15
  end
16
16
 
17
17
  # Produz inteiro a partir de numeral romano
@@ -25,9 +25,9 @@ module ExtensoPt
25
25
  # @param [String] digitos do valor monetario a converter
26
26
  def self.prif(digitos)
27
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| Integer(i.reverse) }
28
+ @ai = digitos[/^\d+/].reverse.scan(/\d{1,3}/).map { |i| Integer(i.reverse) }
29
29
 
30
- # obtem parte fracionaria da string digitos arredondada a 2 casas decimais ex: 123022.12 => 12
30
+ # obtem parte fracionaria da string digitos arredondada a 2 casas decimais ex: 123022.124 => 12, 123022.125 => 13
31
31
  @nf = (Float(digitos[/\.\d*/]) * 100).round
32
32
  end
33
33
 
@@ -43,7 +43,7 @@ module ExtensoPt
43
43
 
44
44
  # @return [true, false] sim ou nao para controle proposicao DE
45
45
  def self.cde?
46
- Integer(@ai[0..1].to_a.inject(:+)).zero? && Integer(@ai[2..].to_a.inject(:+) || 0).positive?
46
+ Integer(@ai[0..1].inject(:+)).zero? && Integer(@ai[2..].to_a.inject(:+) || 0).positive?
47
47
  end
48
48
 
49
49
  # @return [true, false] sim ou nao para controle proposicao E
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ExtensoPt
4
- VERSION = '0.7.1'
4
+ VERSION = '0.7.2'
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.7.1
4
+ version: 0.7.2
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: 2020-08-28 00:00:00.000000000 Z
11
+ date: 2020-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler