Class: AfdParser::Header

Inherits:
RecordParser show all
Defined in:
lib/afd_parser/header.rb

Constant Summary collapse

EMPLOYER_TYPES =
{1 => :cnpj, 2 => :cpf}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Header

Returns a new instance of Header.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/afd_parser/header.rb', line 28

def initialize(*args)
  if args.size == 1
    line = args[0]

    self.line_id, self.record_type_id, self.employer_type, self.employer_document,
    self.employer_cei, self.employer_name, self.rep_serial_number, self.afd_start_date,
    self.afd_end_date, self.afd_creation_time =
      line.unpack("A9AAA14A12A150A17A8A8A12").collect{|str| _clean!(str)}
  elsif args.size == 8
    @line_id           = 0
    @record_type_id    = 1
    @employer_type     = args[0]
    @employer_document = args[1]
    @employer_cei      = args[2]
    @employer_name     = args[3]
    @rep_serial_number = args[4]
    @afd_start_date    = args[5]
    @afd_end_date      = args[6]
    @afd_creation_time = args[7]
  else
    raise AfdParser::AfdParserException.new("wrong number of arguments for header object, should be 1 or 8")
  end
end

Instance Attribute Details

#afd_creation_timeObject

Returns the value of attribute afd_creation_time.



24
25
26
# File 'lib/afd_parser/header.rb', line 24

def afd_creation_time
  @afd_creation_time
end

#afd_end_dateObject

Returns the value of attribute afd_end_date.



24
25
26
# File 'lib/afd_parser/header.rb', line 24

def afd_end_date
  @afd_end_date
end

#afd_start_dateObject

Returns the value of attribute afd_start_date.



24
25
26
# File 'lib/afd_parser/header.rb', line 24

def afd_start_date
  @afd_start_date
end

#employer_ceiObject

Returns the value of attribute employer_cei.



24
25
26
# File 'lib/afd_parser/header.rb', line 24

def employer_cei
  @employer_cei
end

#employer_documentObject

Returns the value of attribute employer_document.



24
25
26
# File 'lib/afd_parser/header.rb', line 24

def employer_document
  @employer_document
end

#employer_nameObject

Returns the value of attribute employer_name.



24
25
26
# File 'lib/afd_parser/header.rb', line 24

def employer_name
  @employer_name
end

#employer_typeObject

Returns the value of attribute employer_type.



24
25
26
# File 'lib/afd_parser/header.rb', line 24

def employer_type
  @employer_type
end

#line_idObject

Returns the value of attribute line_id.



24
25
26
# File 'lib/afd_parser/header.rb', line 24

def line_id
  @line_id
end

#record_type_idObject

Returns the value of attribute record_type_id.



24
25
26
# File 'lib/afd_parser/header.rb', line 24

def record_type_id
  @record_type_id
end

#rep_serial_numberObject

Returns the value of attribute rep_serial_number.



24
25
26
# File 'lib/afd_parser/header.rb', line 24

def rep_serial_number
  @rep_serial_number
end

Class Method Details

.sizeObject



67
68
69
# File 'lib/afd_parser/header.rb', line 67

def self.size
  232
end

Instance Method Details

#==(other) ⇒ Object



71
72
73
74
75
# File 'lib/afd_parser/header.rb', line 71

def ==(other)
  return self.class == other.class && [:line_id, :record_type_id, :employer_type, :employer_document, :employer_cei, :employer_name, :rep_serial_number, :afd_start_date, :afd_end_date, :afd_creation_time].all? do |reader|
    self.send(reader) == other.send(reader)
  end
end

#exportObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/afd_parser/header.rb', line 52

def export
  line_export = ""
  line_export += @line_id.to_s.rjust(9,"0")
  line_export += @record_type_id.to_s
  line_export += get_employer_type_number(@employer_type).to_s
  line_export += @employer_document.to_s.rjust(14, "0")
  line_export += @employer_cei.to_s.rjust(12, "0")
  line_export += @employer_name.to_s.ljust(150, " ")
  line_export += @rep_serial_number
  line_export += format_date(@afd_start_date)
  line_export += format_date(@afd_end_date)
  line_export += format_time(@afd_creation_time)
  line_export
end