Module: Caligrafo::Writer::FileExtension
- Defined in:
- lib/caligrafo/writer.rb
Instance Attribute Summary collapse
-
#bloco ⇒ Object
Returns the value of attribute bloco.
-
#estrutura ⇒ Object
Returns the value of attribute estrutura.
-
#indice ⇒ Object
Returns the value of attribute indice.
-
#linha ⇒ Object
Returns the value of attribute linha.
-
#numero_linha ⇒ Object
Returns the value of attribute numero_linha.
-
#objeto ⇒ Object
Returns the value of attribute objeto.
-
#secao_corrente ⇒ Object
Returns the value of attribute secao_corrente.
Instance Method Summary collapse
-
#imprimir(nome_campo, valor) ⇒ Object
Sobrescreve a definição do arquivo.
- #nova_linha ⇒ Object
- #secao(nome, &bloco) ⇒ Object
Instance Attribute Details
#bloco ⇒ Object
Returns the value of attribute bloco.
23 24 25 |
# File 'lib/caligrafo/writer.rb', line 23 def bloco @bloco end |
#estrutura ⇒ Object
Returns the value of attribute estrutura.
23 24 25 |
# File 'lib/caligrafo/writer.rb', line 23 def estrutura @estrutura end |
#indice ⇒ Object
Returns the value of attribute indice.
23 24 25 |
# File 'lib/caligrafo/writer.rb', line 23 def indice @indice end |
#linha ⇒ Object
Returns the value of attribute linha.
23 24 25 |
# File 'lib/caligrafo/writer.rb', line 23 def linha @linha end |
#numero_linha ⇒ Object
Returns the value of attribute numero_linha.
23 24 25 |
# File 'lib/caligrafo/writer.rb', line 23 def numero_linha @numero_linha end |
#objeto ⇒ Object
Returns the value of attribute objeto.
23 24 25 |
# File 'lib/caligrafo/writer.rb', line 23 def objeto @objeto end |
#secao_corrente ⇒ Object
Returns the value of attribute secao_corrente.
23 24 25 |
# File 'lib/caligrafo/writer.rb', line 23 def secao_corrente @secao_corrente end |
Instance Method Details
#imprimir(nome_campo, valor) ⇒ Object
Sobrescreve a definição do arquivo.
62 63 64 65 |
# File 'lib/caligrafo/writer.rb', line 62 def imprimir(nome_campo, valor) campo = self.secao_corrente.campos.find {|campo_pre_definido| campo_pre_definido.nome == nome_campo} campo.guarda_valor_para(self.objeto, valor) end |
#nova_linha ⇒ Object
56 57 58 59 |
# File 'lib/caligrafo/writer.rb', line 56 def nova_linha self.linha = ' ' * self.secao_corrente.size self.numero_linha += 1 end |
#secao(nome, &bloco) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/caligrafo/writer.rb', line 25 def secao(nome, &bloco) self.secao_corrente = self.estrutura.secoes.find {|secao| secao.nome == nome } raise "Seção #{nome.inspect} não encontrada, verifique a descrição do arquivo." unless self.secao_corrente if self.objeto.respond_to? nome objetos = self.objeto.send nome objetos = [objetos] if objetos.nil? or !objetos.is_a?(Array) else objetos = [objeto] end objetos.each_with_index do |objeto, index| self.objeto = objeto self.indice = index nova_linha bloco.call objeto for campo in self.secao_corrente.campos valor = (campo.valor_guardado || campo.valor_para(self.objeto)) # Só preenche o espaço quando o novo valor não for vazio. # Isso permite que a inicialização da linha inteira não seja sobrescrita com espaços em branco. self.linha[campo.intervalo] = valor if not valor.strip.empty? end self.print self.linha self.print "\n" end self.objeto = self.bloco.binding.send :eval, "self" end |