Class: EdiParser::Ocurrence

Inherits:
Object
  • Object
show all
Defined in:
lib/edi_parser/ocurrence.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Ocurrence

Returns a new instance of Ocurrence.



22
23
24
25
26
# File 'lib/edi_parser/ocurrence.rb', line 22

def initialize(attributes = {})
  attributes.each do |key, value|
    __send__("#{key}=", value)
  end
end

Instance Attribute Details

#codeString

Returns the ocurrence code.

Returns:

  • (String)

    the ocurrence code.



11
12
13
# File 'lib/edi_parser/ocurrence.rb', line 11

def code
  @code
end

#dateDateTime

Returns the ocurrence date and time.

Returns:

  • (DateTime)

    the ocurrence date and time.



14
15
16
# File 'lib/edi_parser/ocurrence.rb', line 14

def date
  @date
end

#geopositionString

Returns the ocurrence textual geoposition.

Returns:

  • (String)

    the ocurrence textual geoposition.



20
21
22
# File 'lib/edi_parser/ocurrence.rb', line 20

def geoposition
  @geoposition
end

#incoming_codeString

Returns the ocurrence incoming code.

Returns:

  • (String)

    the ocurrence incoming code.



17
18
19
# File 'lib/edi_parser/ocurrence.rb', line 17

def incoming_code
  @incoming_code
end

#invoiceEdiParser::Invoice

Returns the invoice object.

Returns:



8
9
10
# File 'lib/edi_parser/ocurrence.rb', line 8

def invoice
  @invoice
end

#sender_cnpjString

Returns the sender’s cnpj.

Returns:

  • (String)

    the sender’s cnpj.



5
6
7
# File 'lib/edi_parser/ocurrence.rb', line 5

def sender_cnpj
  @sender_cnpj
end

Class Method Details

.parse(line) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/edi_parser/ocurrence.rb', line 28

def self.parse(line)
  return nil unless line.start_with?("342")

  ocurrence = Ocurrence.new
  ocurrence.sender_cnpj = line[3..16]
  ocurrence.invoice = Invoice.new(number: line[20..27].to_i, series: line[17..19].strip)
  ocurrence.code = line[28..29]
  ocurrence.date = DateTime.strptime(line[30, 41], "%d%m%Y%H%M")
  ocurrence.incoming_code = line[42..43].strip
  ocurrence.geoposition = line[44..113].strip

  ocurrence
end