-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Agregando clase para obtención de totales
- Loading branch information
hermes-logicalbricks
committed
Jan 18, 2014
1 parent
5dc8e20
commit 34b977d
Showing
4 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# -*- encoding : utf-8 -*- | ||
require 'nokogiri' | ||
|
||
module FmTimbradoCfdi | ||
class FmInformacionCfdi | ||
attr_reader :total, :subtotal, :descuento | ||
|
||
def initialize ( nodo_timbre ) | ||
parse( nodo_timbre ) | ||
end | ||
|
||
private | ||
def parse ( nodo_timbre ) | ||
xml = Nokogiri::XML(nodo_timbre) | ||
ns = generar_namespaces(xml) | ||
atributos.each do |variable| | ||
instance_variable_set("@#{variable}", send("obtener_#{variable}", xml, ns)) | ||
end | ||
end | ||
|
||
def atributos | ||
[ 'total', | ||
'subtotal', | ||
'descuento', | ||
] | ||
end | ||
|
||
def obtener_total(xml,ns) | ||
xml.xpath("//cfdi:Comprobante",ns).attribute('total').value rescue nil | ||
end | ||
|
||
def obtener_subtotal(xml,ns) | ||
xml.xpath("//cfdi:Comprobante",ns).attribute('subTotal').value rescue nil | ||
end | ||
|
||
def obtener_descuento(xml,ns) | ||
xml.xpath("//cfdi:Comprobante",ns).attribute('descuento').value rescue nil | ||
end | ||
|
||
def generar_namespaces(xml) | ||
namespaces = xml.collect_namespaces | ||
ns = {} | ||
namespaces.each_pair do |key, value| | ||
ns[key.sub(/^xmlns:/, '')] = value | ||
end | ||
ns | ||
end | ||
|
||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module FmTimbradoCfdi | ||
VERSION = "0.0.4" | ||
VERSION = "0.0.5" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# encoding: utf-8 | ||
require 'spec_helper' | ||
|
||
describe FmTimbradoCfdi::FmInformacionCfdi do | ||
context "debe crear un objeto válido" do | ||
let(:plantilla){File.open('spec/fixtures/layout_example.txt').read} | ||
let(:layout){ plantilla.gsub('--fecha-comprobante--', 'asignarFecha' )} | ||
let(:respuesta){ FmTimbradoCfdi.timbra_cfdi_layout 'ESI920427886', layout } | ||
let(:informacion) { FmTimbradoCfdi::FmInformacionCfdi.new(respuesta.xml)} | ||
it { informacion.total.should_not be_nil } | ||
it { informacion.total.should == "116.00"} | ||
it { informacion.subtotal.should_not be_nil } | ||
it { informacion.subtotal.should == "100.00"} | ||
it { informacion.descuento.should_not be_nil } | ||
it { informacion.descuento.should == "0.00" } | ||
end | ||
end |