require 'docx' # Use case to abstract FORM from word document class Eco::API::UseCases::OozeSamples::OozeFromDocCase < Eco::API::UseCases::OozeSamples::OozeUpdateCase name "ooze-forms-case" type :other private def with_column(num = 0) with_tables do |table, i| raise "Column num (#{num}) is to big. Table '#{i}' only has #{table.column_count} columns." if table.column_count < num table.columns[num].cells.each_with_index do |cell_row, j| txt = normalize_string(cell_row.text) yield(txt, i, j, table, cell_row) end end end def with_tables raise "There are no tables in the doc" unless table_count > 0 i = 0 doc.tables.each do |table| yield(table, i) if block_given? i += 1 end end def table_count doc.tables.count end def tables? table_count > 0 end def doc @doc ||= Docx::Document.open(input_file) end def input_file options.dig(:source, :file) end end