class Eco::API::UseCases::OozeSamples::OozeFromDocCase

Use case to abstract FORM from word document

Private Instance Methods

doc() click to toggle source
# File lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb, line 36
def doc
  @doc ||= Docx::Document.open(input_file)
end
input_file() click to toggle source
# File lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb, line 40
def input_file
  options.dig(:source, :file)
end
table_count() click to toggle source
# File lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb, line 28
def table_count
  doc.tables.count
end
tables?() click to toggle source
# File lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb, line 32
def tables?
  table_count > 0
end
with_column(num = 0) { |txt, i, j, table, cell_row| ... } click to toggle source
# File lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb, line 9
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
with_tables() { |table, i| ... } click to toggle source
# File lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb, line 19
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