Class: Tabula::ZoneEntity

Inherits:
Tabula.javajava.awtjava.awt.geomjava.awt.geom.Rectangle2Djava.awt.geom.Rectangle2D::Float
  • Object
show all
Defined in:
lib/tabula/entities/zone_entity.rb

Direct Known Subclasses

Cell, Line, Page, Spreadsheet, TextChunk, TextElement

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(top, left, width, height) ⇒ ZoneEntity

Returns a new instance of ZoneEntity.



10
11
12
13
14
15
16
17
# File 'lib/tabula/entities/zone_entity.rb', line 10

def initialize(top, left, width, height)
  super()
  if left && top && width && height
    self.java_send :setRect, [Java::float, Java::float, Java::float, Java::float,], left, top, width, height
  end
  # TODO used? remove if not.
  self.texts = []
end

Instance Attribute Details

#textsObject

TODO used? remove if not.



8
9
10
# File 'lib/tabula/entities/zone_entity.rb', line 8

def texts
  @texts
end

Instance Method Details

#<=>(other) ⇒ Object

default sorting order for ZoneEntity objects is lexicographical (left to right, top to bottom)



32
33
34
35
36
37
38
39
40
41
# File 'lib/tabula/entities/zone_entity.rb', line 32

def <=>(other)
  yDifference = (self.bottom - other.bottom).abs
  if yDifference < 0.1 ||
      (other.bottom >= self.top && other.bottom <= self.bottom) ||
      (self.bottom >= other.top && self.bottom <= other.bottom)
    self.left <=> other.left
  else
    self.bottom <=> other.bottom
  end
end

#inspectObject



47
48
49
# File 'lib/tabula/entities/zone_entity.rb', line 47

def inspect
  "#<#{self.class} dims: #{self.dims(:top, :left, :width, :height)}>"
end

#merge!(other) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/tabula/entities/zone_entity.rb', line 19

def merge!(other)
  self.top    = [self.top, other.top].min
  self.left   = [self.left, other.left].min
  self.width  = [self.right, other.right].max - left
  self.height = [self.bottom, other.bottom].max - top

  self.java_send :setRect, [Java::float, Java::float, Java::float, Java::float,], self.left, self.top, self.width, self.height
  self
end

#pointsObject



59
60
61
62
63
64
# File 'lib/tabula/entities/zone_entity.rb', line 59

def points
  [ Point2D::Float.new(left, top),
    Point2D::Float.new(right, top),
    Point2D::Float.new(right, bottom),
    Point2D::Float.new(left, bottom) ]
end

#tlbrObject



51
52
53
# File 'lib/tabula/entities/zone_entity.rb', line 51

def tlbr
  [top, left, bottom, right]
end

#tlwhObject



55
56
57
# File 'lib/tabula/entities/zone_entity.rb', line 55

def tlwh
  [top, left, width, height]
end

#to_json(options = {}) ⇒ Object



43
44
45
# File 'lib/tabula/entities/zone_entity.rb', line 43

def to_json(options={})
  self.to_h.to_json
end