Class: Pdfrb::Model::Rectangle

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfrb/model/rectangle.rb

Overview

PDF rectangle (s7.9.5): 4-number array [llx lly urx ury]. Immutable value object.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(llx, lly, urx, ury) ⇒ Rectangle

Returns a new instance of Rectangle.



10
11
12
13
14
15
16
# File 'lib/pdfrb/model/rectangle.rb', line 10

def initialize(llx, lly, urx, ury)
  @llx = llx.to_f
  @lly = lly.to_f
  @urx = urx.to_f
  @ury = ury.to_f
  freeze
end

Instance Attribute Details

#llxObject (readonly)

Returns the value of attribute llx.



8
9
10
# File 'lib/pdfrb/model/rectangle.rb', line 8

def llx
  @llx
end

#llyObject (readonly)

Returns the value of attribute lly.



8
9
10
# File 'lib/pdfrb/model/rectangle.rb', line 8

def lly
  @lly
end

#urxObject (readonly)

Returns the value of attribute urx.



8
9
10
# File 'lib/pdfrb/model/rectangle.rb', line 8

def urx
  @urx
end

#uryObject (readonly)

Returns the value of attribute ury.



8
9
10
# File 'lib/pdfrb/model/rectangle.rb', line 8

def ury
  @ury
end

Class Method Details

.from_array(arr) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/pdfrb/model/rectangle.rb', line 18

def self.from_array(arr)
  case arr
  when Rectangle then arr
  when PdfArray, Array then new(arr[0], arr[1], arr[2], arr[3])
  else raise ArgumentError, "cannot build Rectangle from #{arr.class}"
  end
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



40
41
42
# File 'lib/pdfrb/model/rectangle.rb', line 40

def ==(other)
  other.is_a?(Rectangle) && to_a == other.to_a
end

#bottomObject



29
# File 'lib/pdfrb/model/rectangle.rb', line 29

def bottom; @lly; end

#cornerObject



34
# File 'lib/pdfrb/model/rectangle.rb', line 34

def corner; [@urx, @ury]; end

#hashObject



45
46
47
# File 'lib/pdfrb/model/rectangle.rb', line 45

def hash
  to_a.hash
end

#heightObject



27
# File 'lib/pdfrb/model/rectangle.rb', line 27

def height; @ury - @lly; end

#inspectObject



49
50
51
# File 'lib/pdfrb/model/rectangle.rb', line 49

def inspect
  "#<Rectangle llx=#{@llx} lly=#{@lly} urx=#{@urx} ury=#{@ury}>"
end

#leftObject



28
# File 'lib/pdfrb/model/rectangle.rb', line 28

def left;   @llx; end

#originObject



33
# File 'lib/pdfrb/model/rectangle.rb', line 33

def origin; [@llx, @lly]; end

#rightObject



30
# File 'lib/pdfrb/model/rectangle.rb', line 30

def right;  @urx; end

#to_aObject



36
37
38
# File 'lib/pdfrb/model/rectangle.rb', line 36

def to_a
  [@llx, @lly, @urx, @ury]
end

#topObject



31
# File 'lib/pdfrb/model/rectangle.rb', line 31

def top;    @ury; end

#widthObject



26
# File 'lib/pdfrb/model/rectangle.rb', line 26

def width;  @urx - @llx; end