Class: MuPDF::Box

Inherits:
Object
  • Object
show all
Defined in:
lib/mupdf/box.rb

Overview

A bounding box for a PDF (e.g. media / crop / bleed / trim).

Constant Summary collapse

REGEX =
/l="(?<l>\d+.?\d*)" b="(?<b>\d+.?\d*)" r="(?<r>\d+.?\d*)" t="(?<t>\d+.?\d*)"/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(l:, b:, r:, t:, kind: nil) ⇒ Box

Returns a new instance of Box.

Parameters:

  • l (BigDecimal)
  • b (BigDecimal)
  • r (BigDecimal)
  • t (BigDecimal)
  • kind (Symbol) (defaults to: nil)

    optional



50
51
52
53
54
55
56
# File 'lib/mupdf/box.rb', line 50

def initialize(l:, b:, r:, t:, kind: nil)
  @l = l
  @b = b
  @r = r
  @t = t
  @kind = kind
end

Instance Attribute Details

#bObject

Returns the value of attribute b.



14
15
16
# File 'lib/mupdf/box.rb', line 14

def b
  @b
end

#kindObject

Returns the value of attribute kind.



26
27
28
# File 'lib/mupdf/box.rb', line 26

def kind
  @kind
end

#lObject

Returns the value of attribute l.



10
11
12
# File 'lib/mupdf/box.rb', line 10

def l
  @l
end

#rObject

Returns the value of attribute r.



18
19
20
# File 'lib/mupdf/box.rb', line 18

def r
  @r
end

#tObject

Returns the value of attribute t.



22
23
24
# File 'lib/mupdf/box.rb', line 22

def t
  @t
end

Class Method Details

.parse(text, kind:) ⇒ MuPDF::Box?

Parameters:

  • text (String)
  • kind (Symbol)

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/mupdf/box.rb', line 32

def self.parse(text, kind:)
  match = text.match(REGEX)
  return unless match

  new(
    l: BigDecimal(match[:l]),
    b: BigDecimal(match[:b]),
    r: BigDecimal(match[:r]),
    t: BigDecimal(match[:t]),
    kind:
  )
end

Instance Method Details

#heightBigDecimal

Returns:

  • (BigDecimal)


69
70
71
# File 'lib/mupdf/box.rb', line 69

def height
  @t - @b
end

#inspectString

Returns:

  • (String)


59
60
61
# File 'lib/mupdf/box.rb', line 59

def inspect
  "#<#{self.class.name} l=#{l} b=#{b} r=#{r} t=#{t} kind=#{kind}>"
end

#widthBigDecimal

Returns:

  • (BigDecimal)


64
65
66
# File 'lib/mupdf/box.rb', line 64

def width
  @r - @l
end