Sha256: 8ab6de22658a9d86f54cc000a22ac2e56ff4155a1fea6b4c65cb7cebb655e33f

Contents?: true

Size: 700 Bytes

Versions: 1

Compression:

Stored size: 700 Bytes

Contents

module Cesri
  class RecepcionComprobanteResponse

    attr_reader :response, :state, :messages

    def initialize(response)
      @response = response
      @state = state_value
      @messages = []

      load_messages
    end

    def success?
      @state == 'RECIBIDA'
    end

    private

    def state_value
      doc.xpath('//estado').first.content if doc.xpath('//estado').first
    end

    def load_messages
      doc.xpath('//mensajes//mensaje').each do |message|
        response_message = ResponseMessage.new(message)
        messages << response_message if response_message.identificador
      end
    end

    def doc
      @doc ||= Nokogiri::XML(@response.to_s)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cesri-0.1.0 lib/cesri/recepcion_comprobante_response.rb