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+)" b="(?<b>\d+)" r="(?<r>\d+)" t="(?<t>\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 (Integer)
  • b (Integer)
  • r (Integer)
  • t (Integer)
  • kind (Symbol) (defaults to: nil)

    optional



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

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
# File 'lib/mupdf/box.rb', line 32

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

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

Instance Method Details

#heightInteger

Returns:

  • (Integer)


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

def height
  @t - @b
end

#inspectString

Returns:

  • (String)


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

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

#widthInteger

Returns:

  • (Integer)


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

def width
  @r - @l
end