Class: Caracal::Core::Models::PageSizeModel

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/caracal/core/models/page_size_model.rb

Overview

This class handles block options passed to the page size method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ PageSizeModel

initialization



28
29
30
31
32
33
34
# File 'lib/caracal/core/models/page_size_model.rb', line 28

def initialize(options={}, &block)
  @page_width       = DEFAULT_PAGE_WIDTH
  @page_height      = DEFAULT_PAGE_HEIGHT
  @page_orientation = DEFAULT_PAGE_ORIENTATION

  super options, &block
end

Instance Attribute Details

#page_heightObject (readonly)

Returns the value of attribute page_height.



24
25
26
# File 'lib/caracal/core/models/page_size_model.rb', line 24

def page_height
  @page_height
end

#page_orientationObject (readonly)

Returns the value of attribute page_orientation.



25
26
27
# File 'lib/caracal/core/models/page_size_model.rb', line 25

def page_orientation
  @page_orientation
end

#page_widthObject (readonly)

accessors



23
24
25
# File 'lib/caracal/core/models/page_size_model.rb', line 23

def page_width
  @page_width
end

Instance Method Details

#height(value) ⇒ Object

SETTERS ==============================


43
44
45
# File 'lib/caracal/core/models/page_size_model.rb', line 43

def height(value)
  @page_height = value.to_i
end

#orientation(value) ⇒ Object



47
48
49
50
51
# File 'lib/caracal/core/models/page_size_model.rb', line 47

def orientation(value)
  allowed = ['landscape','portrait']
  given   = value.to_s.downcase
  @page_orientation = allowed.include?(given) ? given : 'portrait'
end

#valid?Boolean

VALIDATION ==============================

Returns:

  • (Boolean)


60
61
62
63
# File 'lib/caracal/core/models/page_size_model.rb', line 60

def valid?
  dims = [page_width, page_height]
  dims.all? { |d| d > 0 }
end

#width(value) ⇒ Object



53
54
55
# File 'lib/caracal/core/models/page_size_model.rb', line 53

def width(value)
  @page_width = value.to_i
end