Class: ImgToPdf::Dimension

Inherits:
Struct
  • Object
show all
Defined in:
lib/img_to_pdf/dimension.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#heightObject

Returns the value of attribute height

Returns:

  • (Object)

    the current value of height



3
4
5
# File 'lib/img_to_pdf/dimension.rb', line 3

def height
  @height
end

#widthObject

Returns the value of attribute width

Returns:

  • (Object)

    the current value of width



3
4
5
# File 'lib/img_to_pdf/dimension.rb', line 3

def width
  @width
end

Class Method Details

.from_array(ary) ⇒ Object

Returns ImgToPdf::Dimension parsed.

Parameters:

  • ary (Array<(Float, Float)>)

    ‘[width, height]`.

Returns:

  • ImgToPdf::Dimension parsed.



7
8
9
# File 'lib/img_to_pdf/dimension.rb', line 7

def from_array(ary)
  return new(width: ary[0], height: ary[1])
end

Instance Method Details

#direction:landscape, :portrait

Returns direction of dimension.

Returns:

  • (:landscape, :portrait)

    direction of dimension.



18
19
20
# File 'lib/img_to_pdf/dimension.rb', line 18

def direction
  return width > height ? :landscape : :portrait
end

#justify_direction(target_direction) ⇒ ImgToPdf::Dimension

Returns justified dimension.

Parameters:

  • direction (:landscape, :portrait)

Returns:



29
30
31
# File 'lib/img_to_pdf/dimension.rb', line 29

def justify_direction(target_direction)
  return direction == target_direction ? dup : transpose
end

#pt_to_inImgToPdf::Dimension

points to inches.

Returns:



36
37
38
39
# File 'lib/img_to_pdf/dimension.rb', line 36

def pt_to_in
  return self.class.new(width: ImgToPdf::Unit.convert_pt_to_in(width),
                        height: ImgToPdf::Unit.convert_pt_to_in(height))
end

#to_aArray<(Float, Float)>

Returns array. ‘[width, height]`.

Returns:

  • (Array<(Float, Float)>)

    array. ‘[width, height]`.



13
14
15
# File 'lib/img_to_pdf/dimension.rb', line 13

def to_a
  return [width, height]
end

#transposeImgToPdf::Dimension

Returns transposed dimension.

Returns:



23
24
25
# File 'lib/img_to_pdf/dimension.rb', line 23

def transpose
  return self.class.new(width: height, height: width)
end