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.4.9 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.4.8 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.4.7 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.4.6 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.4.5 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.4.4 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.4.3 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.4.2 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.3.3 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.3.2 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.2.5 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.2.4 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.2.3 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.2.2 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.2.1 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.1.12 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.1.11 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.1.10 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.1.9 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb
eco-helpers-2.1.8 lib/eco/api/usecases/ooze_samples/ooze_from_doc_case.rb