Class: Corrails::Parser::DirectlogParser
- Inherits:
-
Object
- Object
- Corrails::Parser::DirectlogParser
- Defined in:
- lib/corrails/parser/directlog_parser.rb
Class Method Summary collapse
- .build_remessa(xml) ⇒ Object
- .get_error(xml) ⇒ Object
- .get_ocorrencias(historico) ⇒ Object
- .get_status_list(xml_doc) ⇒ Object
- .parse(returnXml) ⇒ Object
Class Method Details
.build_remessa(xml) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/corrails/parser/directlog_parser.rb', line 24 def self.build_remessa(xml) xml_doc = Nokogiri::XML(xml) numero = xml_doc.xpath('//nrremessa').first.content pedido = xml_doc.xpath('//nrpedido').first.content notafiscal = xml_doc.xpath('//nrnotafiscal').first.content serianota = xml_doc.xpath('//serianota').first.content remessa = Hash.new remessa[:numero] = numero remessa[:pedido] = pedido remessa[:notafiscal] = notafiscal remessa[:serianota] = serianota remessa[:historico] = get_status_list(xml_doc) remessa end |
.get_error(xml) ⇒ Object
19 20 21 22 |
# File 'lib/corrails/parser/directlog_parser.rb', line 19 def self.get_error xml xml_doc = Nokogiri::XML(xml) xml_doc.xpath('//mensagem').first.content end |
.get_ocorrencias(historico) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/corrails/parser/directlog_parser.rb', line 54 def self.get_ocorrencias(historico) list = Array.new ocorrencias = historico.xpath('ocorrencia') ocorrencias.each do |ocorrencia| ocorren = Hash.new ocorren[:codigo] = ocorrencia.xpath('codocorrencia').first.content ocorren[:descricao] = ocorrencia.xpath('descricaoocorrencia').first.content list << ocorren end list end |
.get_status_list(xml_doc) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/corrails/parser/directlog_parser.rb', line 40 def self.get_status_list(xml_doc) status_list = Array.new historicos = xml_doc.xpath("//historicos//status") historicos.each do |historico| status = Hash.new status[:codigo] = historico.xpath('codstatus').first.content status[:status] = historico.xpath('descricaostatus').first.content status[:data] = historico.xpath('dtstatus').first.content status[:ocorrencias] = get_ocorrencias(historico) status_list << status end status_list end |
.parse(returnXml) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/corrails/parser/directlog_parser.rb', line 7 def self.parse(returnXml) resp = returnXml.to_hash[:consulta_status_entrega_response] response = Corrails::Response.new response.result = resp[:consulta_status_entrega_result] if(response.ok?) response.item = build_remessa(resp[:xml]) else response.error_msg = get_error(resp[:xml]) end response end |