Class: BoaVista::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/boa_vista/request.rb,
lib/boa_vista/request/layout.rb,
lib/boa_vista/request/default.rb,
lib/boa_vista/request/factory.rb,
lib/boa_vista/request/layout/cpf.rb,
lib/boa_vista/request/layout/cnpj.rb

Defined Under Namespace

Modules: Default, Factory, Layout

Constant Summary collapse

DOCUMENT_TYPE =
{
  cpf:  1,
  cnpj: 2
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ Request

Returns a new instance of Request.



8
9
10
# File 'lib/boa_vista/request.rb', line 8

def initialize(values)
  @values = BoaVista::Request::Factory.build(values)
end

Class Method Details

.document_name(document_type) ⇒ Object



30
31
32
33
34
35
# File 'lib/boa_vista/request.rb', line 30

def self.document_name(document_type)
  DOCUMENT_TYPE.each do |k, v|
    return k if document_type.to_i == v
  end
  return false
end

.layout(document_type) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/boa_vista/request.rb', line 21

def self.layout(document_type)
  case document_type.to_i
  when DOCUMENT_TYPE[:cpf]  then BoaVista::Request::Layout::Cpf
  when DOCUMENT_TYPE[:cnpj] then BoaVista::Request::Layout::Cnpj
  else
    fail BoaVista::Errors::InvalidDocumentType.new("Invalid document type: #{document_type}")
  end
end

.read(line) ⇒ Object



16
17
18
19
# File 'lib/boa_vista/request.rb', line 16

def self.read(line)
  document_type = line.slice(68..68)
  BoaVista::Line.prepare_for_read(line, layout(document_type)).read
end

Instance Method Details

#createObject



12
13
14
# File 'lib/boa_vista/request.rb', line 12

def create
  write_line_with(self.class.layout(@values[:document_type]))
end