Class: ChupaText::Decomposers::Spreadsheet
- Inherits:
-
Decomposer
- Object
- Decomposer
- ChupaText::Decomposers::Spreadsheet
- Includes:
- Loggable
- Defined in:
- lib/chupa-text/decomposers/spreadsheet.rb
Constant Summary collapse
- TARGET_EXTENSIONS =
["ods", "xls", "xlsx", "xlsm", "xml"]
- TARGET_MIME_TYPES =
[ "application/vnd.oasis.opendocument.spreadsheet", "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ]
Instance Method Summary collapse
Instance Method Details
#decompose(data) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/chupa-text/decomposers/spreadsheet.rb', line 33 def decompose(data) open_book(data) do |book| book.sheets.each do |sheet_name| sheet = book.sheet(sheet_name) body = sheet.to_csv text_data = TextData.new(body, source_data: data) text_data["name"] = sheet_name text_data["digest"] = Digest::SHA1.hexdigest(body) text_data["size"] = body.bytesize text_data["first-row"] = sheet.first_row text_data["last-row"] = sheet.last_row text_data["first-column"] = sheet.first_column && sheet.first_column_as_letter text_data["last-column"] = sheet.last_column && sheet.last_column_as_letter yield text_data end end end |
#target?(data) ⇒ Boolean
20 21 22 23 |
# File 'lib/chupa-text/decomposers/spreadsheet.rb', line 20 def target?(data) TARGET_EXTENSIONS.include?(data.extension) or TARGET_MIME_TYPES.include?(data.mime_type) end |
#target_score(data) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/chupa-text/decomposers/spreadsheet.rb', line 25 def target_score(data) if target?(data) 10 else nil end end |