Class: EdiParser::Ocurrence
- Inherits:
-
Object
- Object
- EdiParser::Ocurrence
- Defined in:
- lib/edi_parser/ocurrence.rb
Instance Attribute Summary collapse
-
#code ⇒ String
The ocurrence code.
-
#date ⇒ DateTime
The ocurrence date and time.
-
#geoposition ⇒ String
The ocurrence textual geoposition.
-
#incoming_code ⇒ String
The ocurrence incoming code.
-
#invoice ⇒ EdiParser::Invoice
The invoice object.
-
#sender_cnpj ⇒ String
The sender’s cnpj.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Ocurrence
constructor
A new instance of Ocurrence.
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
#code ⇒ String
Returns the ocurrence code.
11 12 13 |
# File 'lib/edi_parser/ocurrence.rb', line 11 def code @code end |
#date ⇒ DateTime
Returns the ocurrence date and time.
14 15 16 |
# File 'lib/edi_parser/ocurrence.rb', line 14 def date @date end |
#geoposition ⇒ String
Returns the ocurrence textual geoposition.
20 21 22 |
# File 'lib/edi_parser/ocurrence.rb', line 20 def geoposition @geoposition end |
#incoming_code ⇒ String
Returns the ocurrence incoming code.
17 18 19 |
# File 'lib/edi_parser/ocurrence.rb', line 17 def incoming_code @incoming_code end |
#invoice ⇒ EdiParser::Invoice
Returns the invoice object.
8 9 10 |
# File 'lib/edi_parser/ocurrence.rb', line 8 def invoice @invoice end |
#sender_cnpj ⇒ String
Returns 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 |