Class: Tabula::Cell
- Inherits:
-
ZoneEntity
- Object
- Tabula.javajava.awtjava.awt.geomjava.awt.geom.Rectangle2Djava.awt.geom.Rectangle2D::Float
- ZoneEntity
- Tabula::Cell
- Defined in:
- lib/tabula/entities/cell.rb
Overview
cells are components of spreadsheets
Constant Summary collapse
- NORMAL =
0
- DEBUG =
1
- SUPERDEBUG =
2
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#placeholder ⇒ Object
Returns the value of attribute placeholder.
-
#spanning ⇒ Object
Returns the value of attribute spanning.
-
#text_elements ⇒ Object
Returns the value of attribute text_elements.
Attributes inherited from ZoneEntity
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(top, left, width, height, options = {}) ⇒ Cell
constructor
A new instance of Cell.
- #text ⇒ Object
- #to_json(*a) ⇒ Object
Methods inherited from ZoneEntity
#<=>, #inspect, #merge!, #points, #tlbr, #tlwh
Constructor Details
#initialize(top, left, width, height, options = {}) ⇒ Cell
Returns a new instance of Cell.
13 14 15 16 17 18 19 |
# File 'lib/tabula/entities/cell.rb', line 13 def initialize(top, left, width, height, ={}) super(top, left, width, height) @placeholder = false @spanning = false @text_elements = [] @options = ({:use_line_returns => true, :cell_debug => NORMAL}).merge end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
11 12 13 |
# File 'lib/tabula/entities/cell.rb', line 11 def @options end |
#placeholder ⇒ Object
Returns the value of attribute placeholder.
11 12 13 |
# File 'lib/tabula/entities/cell.rb', line 11 def placeholder @placeholder end |
#spanning ⇒ Object
Returns the value of attribute spanning.
11 12 13 |
# File 'lib/tabula/entities/cell.rb', line 11 def spanning @spanning end |
#text_elements ⇒ Object
Returns the value of attribute text_elements.
11 12 13 |
# File 'lib/tabula/entities/cell.rb', line 11 def text_elements @text_elements end |
Class Method Details
Instance Method Details
#text ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/tabula/entities/cell.rb', line 27 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] ? "\r" : '') # per @bchartoff, https://github.com/jazzido/tabula-extractor/pull/65#issuecomment-32899336 # line returns as \r behave better in Excel. 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 |
#to_json(*a) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/tabula/entities/cell.rb', line 44 def to_json(*a) { 'json_class' => self.class.name, 'text' => text, 'top' => top, 'left' => left, 'width' => width, 'height' => height }.to_json(*a) end |