Class: ChupaText::Decomposers::XML
- Inherits:
-
ChupaText::Decomposer
- Object
- ChupaText::Decomposer
- ChupaText::Decomposers::XML
- Includes:
- Loggable
- Defined in:
- lib/chupa-text/decomposers/xml.rb
Defined Under Namespace
Classes: Listener
Instance Method Summary collapse
Methods inherited from ChupaText::Decomposer
#initialize, registry, #target_score
Constructor Details
This class inherits a constructor from ChupaText::Decomposer
Instance Method Details
#decompose(data) {|text_data| ... } ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/chupa-text/decomposers/xml.rb', line 31 def decompose(data) text = +"" listener = Listener.new(text) data.open do |input| begin parser = SAXParser.new(input, listener) parser.parse rescue SAXParser::ParseError => xml_error error do = "#{log_tag} Failed to parse XML: " << "#{xml_error.class}: #{xml_error.}\n" << xml_error.backtrace.join("\n") end return end end text_data = TextData.new(text, :source_data => data) yield(text_data) end |
#target?(data) ⇒ Boolean
26 27 28 29 |
# File 'lib/chupa-text/decomposers/xml.rb', line 26 def target?(data) data.extension == "xml" or data.mime_type == "text/xml" end |