caligrafo 0.1.6 → 0.1.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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.6
1
+ 0.1.7
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{caligrafo}
8
- s.version = "0.1.6"
8
+ s.version = "0.1.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Lucas de Castro"]
@@ -1,3 +1,5 @@
1
+ require 'bigdecimal'
2
+
1
3
  module Caligrafo
2
4
  module Converter
3
5
  def self.formatadores
@@ -88,11 +90,15 @@ module Caligrafo
88
90
 
89
91
  class Decimal < Numerico
90
92
  def initialize
91
- @tipos = [Float]
93
+ @tipos = [Float, BigDecimal]
92
94
  end
93
95
 
94
96
  def value_to_string(valor)
95
- ('%.2f' % valor).gsub('.','')
97
+ ('%.2f' % valor.to_f).gsub('.','')
98
+ end
99
+
100
+ def string_to_value(string)
101
+ string.gsub(/(.*)(\d{2})/, '\1.\2').to_f
96
102
  end
97
103
  end
98
104
 
@@ -145,7 +145,7 @@ module Caligrafo
145
145
 
146
146
  formatar(valor)
147
147
  rescue => e
148
- raise "Erro ao preencher valor para #{objeto.inspect} no campo #{self.inspect}: #{e.message}"
148
+ raise "Erro ao preencher valor para #{objeto.inspect} no campo #{nome} da secao #{secao.nome}: #{e.message}"
149
149
  end
150
150
 
151
151
  def formatar(valor)
@@ -61,6 +61,7 @@ module Caligrafo
61
61
  # Sobrescreve a definição do arquivo.
62
62
  def imprimir(nome_campo, valor)
63
63
  campo = self.secao_corrente.campos.find {|campo_pre_definido| campo_pre_definido.nome == nome_campo}
64
+ raise ArgumentError, "campo '#{nome_campo}' inexistente na seção '#{self.secao_corrente.nome}'" unless campo
64
65
  campo.guarda_valor_para(self.objeto, valor)
65
66
  end
66
67
  end
@@ -69,6 +69,20 @@ class CaligrafoTest < Test::Unit::TestCase
69
69
  assert_equal 70, rodape.size
70
70
  end
71
71
 
72
+ def test_imprimir_com_campo_inexistente
73
+ def @portifolio.gerar_arquivo(nome_arquivo)
74
+ escrever_arquivo nome_arquivo do |f|
75
+ f.secao :cabecalho do
76
+ f.imprimir :esse_campo_nao_existe, 'qualquer bobeira'
77
+ end
78
+ end
79
+ end
80
+
81
+ assert_raise ArgumentError do
82
+ @portifolio.gerar_arquivo 'test/arquivo_gerado.txt'
83
+ end
84
+ end
85
+
72
86
  def test_escrever_arquivo_com_linha_predefinida
73
87
  def @portifolio.gerar_arquivo(nome_arquivo)
74
88
  escrever_arquivo nome_arquivo do |f|
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 6
9
- version: 0.1.6
8
+ - 7
9
+ version: 0.1.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Lucas de Castro