Sha256: 6771aec6de154c7e982304b54f76b1abfbdde6d56b68b0d07fa81437ed491f14

Contents?: true

Size: 1022 Bytes

Versions: 62

Compression:

Stored size: 1022 Bytes

Contents

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

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
eco-helpers-2.0.55 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.0.54 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.0.53 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.0.52 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.0.51 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.0.50 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.0.49 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.0.48 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.0.47 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.0.46 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.0.45 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.0.44 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.0.43 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.0.42 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.0.41 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.0.40 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.0.39 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.0.38 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.0.37 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.0.36 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb