Class: Caligrafo::Converter::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/caligrafo/converter.rb

Direct Known Subclasses

Data, Numerico

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



31
32
33
34
35
# File 'lib/caligrafo/converter.rb', line 31

def initialize
  @tipos = []
  @alinhamento = :esquerda
  @preenchimento = ' '
end

Instance Attribute Details

#alinhamentoObject (readonly)

Returns the value of attribute alinhamento.



29
30
31
# File 'lib/caligrafo/converter.rb', line 29

def alinhamento
  @alinhamento
end

#preenchimentoObject (readonly)

Returns the value of attribute preenchimento.



29
30
31
# File 'lib/caligrafo/converter.rb', line 29

def preenchimento
  @preenchimento
end

#tiposObject (readonly)

Returns the value of attribute tipos.



29
30
31
# File 'lib/caligrafo/converter.rb', line 29

def tipos
  @tipos
end

Instance Method Details

#preencher(string, tamanho) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/caligrafo/converter.rb', line 45

def preencher(string, tamanho)
  if self.alinhamento == :direita
    string = string.rjust tamanho, self.preenchimento
  else
    string = string.ljust tamanho, self.preenchimento
  end
 
  string = string[0..(tamanho - 1)] if string.size > tamanho
  string
end

#string_to_value(string) ⇒ Object



41
42
43
# File 'lib/caligrafo/converter.rb', line 41

def string_to_value(string)
  string.strip
end

#value_to_string(valor) ⇒ Object



37
38
39
# File 'lib/caligrafo/converter.rb', line 37

def value_to_string(valor)
  valor.to_s
end