Sha256: 11eb5e90d8630938822a612b647743d6743f06198287fe23fd39b84017476715

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

module Tabula

  #cells are components of spreadsheets

  class Cell < ZoneEntity

    NORMAL = 0
    DEBUG = 1
    SUPERDEBUG = 2

    attr_accessor :text_elements, :placeholder, :spanning, :options

    def initialize(top, left, width, height, options={})
      super(top, left, width, height)
      @placeholder = false
      @spanning = false
      @text_elements = []
      @options = ({:use_line_returns => false, :cell_debug => NORMAL}).merge options
    end

    def self.new_from_points(topleft, bottomright, options={})
      width = bottomright.x - topleft.x
      height = bottomright.y - topleft.y
      Cell.new(topleft.y, topleft.x, width, height, options)
    end

    def text
      return "placeholder" if @placeholder && @options[:cell_debug] >= DEBUG
      output = ""
      text_elements.sort #use the default sort for ZoneEntity
      text_elements.group_by(&:top).values.each do |row|
        output << row.map{|el| el.text}.join('') + (@options[:use_line_returns] ? "\n" : '')
      end 
      if (output.empty? && @options[:cell_debug] >= DEBUG) || @options[:cell_debug] >= SUPERDEBUG
        text_output = output.dup
        output = "top: #{top} left: #{left} \n w: #{width} h: #{height}" 
        output += " \n #{text_output}"
      end
      output.strip
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tabula-extractor-0.7.0-java lib/tabula/entities/cell.rb