Class: Caracal::Core::Models::BorderModel

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

Overview

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

Direct Known Subclasses

RuleModel

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

initialization



32
33
34
35
36
37
38
39
40
# File 'lib/caracal/core/models/border_model.rb', line 32

def initialize(options={}, &block)
  @border_color   = DEFAULT_BORDER_COLOR
  @border_line    = DEFAULT_BORDER_LINE
  @border_size    = DEFAULT_BORDER_SIZE
  @border_spacing = DEFAULT_BORDER_SPACING
  @border_type    = DEFAULT_BORDER_TYPE
  
  super options, &block
end

Instance Attribute Details

#border_colorObject (readonly)

accessors



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

def border_color
  @border_color
end

#border_lineObject (readonly)

Returns the value of attribute border_line.



26
27
28
# File 'lib/caracal/core/models/border_model.rb', line 26

def border_line
  @border_line
end

#border_sizeObject (readonly)

Returns the value of attribute border_size.



27
28
29
# File 'lib/caracal/core/models/border_model.rb', line 27

def border_size
  @border_size
end

#border_spacingObject (readonly)

Returns the value of attribute border_spacing.



28
29
30
# File 'lib/caracal/core/models/border_model.rb', line 28

def border_spacing
  @border_spacing
end

#border_typeObject (readonly)

Returns the value of attribute border_type.



29
30
31
# File 'lib/caracal/core/models/border_model.rb', line 29

def border_type
  @border_type
end

Class Method Details

.formatted_type(type) ⇒ Object


Class Methods




47
48
49
50
51
52
53
54
55
56
57
# File 'lib/caracal/core/models/border_model.rb', line 47

def self.formatted_type(type)
  case type.to_s.to_sym
  when :horizontal  then 'insideH'
  when :vertical    then 'insideV'
  when :top         then 'top'
  when :bottom      then 'bottom'
  when :left        then 'left'
  when :right       then 'right'
  else nil
  end
end

Instance Method Details

#formatted_typeObject

GETTERS ==============================


66
67
68
# File 'lib/caracal/core/models/border_model.rb', line 66

def formatted_type
  self.class.formatted_type(border_type)
end

#total_sizeObject



70
71
72
# File 'lib/caracal/core/models/border_model.rb', line 70

def total_size
  border_size + (2 * border_spacing)
end

#valid?Boolean

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

Returns:

  • (Boolean)


101
102
103
104
# File 'lib/caracal/core/models/border_model.rb', line 101

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