Class: ChupaText::Decomposers::OpenDocumentSpreadsheet::SheetsListener
- Inherits:
-
SAXListener
- Object
- SAXListener
- ChupaText::Decomposers::OpenDocumentSpreadsheet::SheetsListener
- Defined in:
- lib/chupa-text/decomposers/opendocument-spreadsheet.rb
Constant Summary collapse
- TEXT_URI =
"urn:oasis:names:tc:opendocument:xmlns:text:1.0"
- TABLE_URI =
"urn:oasis:names:tc:opendocument:xmlns:table:1.0"
Instance Method Summary collapse
- #cdata(content) ⇒ Object
- #characters(text) ⇒ Object
- #end_element(uri, local_name, qname) ⇒ Object
- #end_prefix_mapping(prefix) ⇒ Object
-
#initialize(sheets) ⇒ SheetsListener
constructor
A new instance of SheetsListener.
- #start_element(uri, local_name, qname, attributes) ⇒ Object
- #start_prefix_mapping(prefix, uri) ⇒ Object
Constructor Details
#initialize(sheets) ⇒ SheetsListener
Returns a new instance of SheetsListener.
62 63 64 65 66 67 68 |
# File 'lib/chupa-text/decomposers/opendocument-spreadsheet.rb', line 62 def initialize(sheets) @sheets = sheets @prefix_to_uri = {} @uri_to_prefix = {} @in_p = false @in_shapes = false end |
Instance Method Details
#cdata(content) ⇒ Object
140 141 142 |
# File 'lib/chupa-text/decomposers/opendocument-spreadsheet.rb', line 140 def cdata(content) add_text(content) end |
#characters(text) ⇒ Object
136 137 138 |
# File 'lib/chupa-text/decomposers/opendocument-spreadsheet.rb', line 136 def characters(text) add_text(text) end |
#end_element(uri, local_name, qname) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/chupa-text/decomposers/opendocument-spreadsheet.rb', line 108 def end_element(uri, local_name, qname) case uri when TEXT_URI case local_name when "p" @in_p = false end when TABLE_URI case local_name when "table" sheet = @sheets.last text = +"" shape_texts = sheet[:shape_texts] unless shape_texts.empty? text << shape_texts.join("\n") << "\n" end sheet[:rows].each do |row| cell_texts = row.collect {|cell| cell[:text]} next if cell_texts.all?(&:empty?) text << cell_texts.join("\t") << "\n" end sheet[:text] = text when "shapes" @in_shapes = false end end end |
#end_prefix_mapping(prefix) ⇒ Object
75 76 77 78 |
# File 'lib/chupa-text/decomposers/opendocument-spreadsheet.rb', line 75 def end_prefix_mapping(prefix) uri = @prefix_to_uri.delete(prefix) @uri_to_prefix.delete(uri) end |
#start_element(uri, local_name, qname, attributes) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/chupa-text/decomposers/opendocument-spreadsheet.rb', line 80 def start_element(uri, local_name, qname, attributes) case uri when TEXT_URI case local_name when "p" @in_p = true end when TABLE_URI table_prefix = @uri_to_prefix[TABLE_URI] case local_name when "table" @sheets << { name: attributes["#{table_prefix}:name"], rows: [], shape_texts: [], } when "table-row" @sheets.last[:rows] << [] when "table-cell" @sheets.last[:rows].last << {text: +""} when "covered-table-cell" @sheets.last[:rows].last << {text: +""} when "shapes" @in_shapes = true end end end |
#start_prefix_mapping(prefix, uri) ⇒ Object
70 71 72 73 |
# File 'lib/chupa-text/decomposers/opendocument-spreadsheet.rb', line 70 def start_prefix_mapping(prefix, uri) @prefix_to_uri[prefix] = uri @uri_to_prefix[uri] = prefix end |