Class: Cfdi40::OriginalContent

Inherits:
Object
  • Object
show all
Defined in:
lib/cfdi40/original_content.rb

Constant Summary collapse

LOCAL_XSLT_PATH =
File.join(File.dirname(__FILE__), "..", "..", "lib/xslt/cadenaoriginal_local.xslt")

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ OriginalContent

Returns a new instance of OriginalContent.



11
12
13
# File 'lib/cfdi40/original_content.rb', line 11

def initialize(xml)
  @xml_doc = Nokogiri::XML(xml)
end

Class Method Details

.generate(xml_string) ⇒ Object



6
7
8
9
# File 'lib/cfdi40/original_content.rb', line 6

def self.generate(xml_string)
  generator = new(xml_string)
  generator.original_content
end

Instance Method Details

#original_contentObject



15
16
17
18
19
20
21
# File 'lib/cfdi40/original_content.rb', line 15

def original_content
  xslt = Nokogiri::XSLT(File.open(LOCAL_XSLT_PATH))
  transformed = xslt.transform(@xml_doc)
  # The ampersand (&) char must be used in original content
  # even though the documentation indicates otherwise
  transformed.children.to_s.gsub("&", "&").strip
end