Class: Caracal::Core::Models::StyleModel

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

Overview

This class encapsulates the logic needed to store and manipulate paragraph style data.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

initialization



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/caracal/core/models/style_model.rb', line 50

def initialize(options={}, &block)
  @style_default = false
  @style_base    = DEFAULT_STYLE_BASE
  @style_next    = DEFAULT_STYLE_NEXT

  super options, &block

  if (style_id == DEFAULT_STYLE_BASE)
    @style_default    ||= true
    @style_color      ||= DEFAULT_STYLE_COLOR
    @style_size       ||= DEFAULT_STYLE_SIZE
    @style_bold       ||= DEFAULT_STYLE_BOLD
    @style_italic     ||= DEFAULT_STYLE_ITALIC
    @style_underline  ||= DEFAULT_STYLE_UNDERLINE
    @style_caps       ||= DEFAULT_STYLE_CAPS
    @style_align      ||= DEFAULT_STYLE_ALIGN
    @style_top        ||= DEFAULT_STYLE_TOP
    @style_bottom     ||= DEFAULT_STYLE_BOTTOM
    @style_line       ||= DEFAULT_STYLE_LINE
  end
end

Instance Attribute Details

#style_alignObject (readonly)

Returns the value of attribute style_align.



42
43
44
# File 'lib/caracal/core/models/style_model.rb', line 42

def style_align
  @style_align
end

#style_baseObject (readonly)

Returns the value of attribute style_base.



46
47
48
# File 'lib/caracal/core/models/style_model.rb', line 46

def style_base
  @style_base
end

#style_boldObject (readonly)

Returns the value of attribute style_bold.



38
39
40
# File 'lib/caracal/core/models/style_model.rb', line 38

def style_bold
  @style_bold
end

#style_bottomObject (readonly)

Returns the value of attribute style_bottom.



44
45
46
# File 'lib/caracal/core/models/style_model.rb', line 44

def style_bottom
  @style_bottom
end

#style_capsObject (readonly)

Returns the value of attribute style_caps.



41
42
43
# File 'lib/caracal/core/models/style_model.rb', line 41

def style_caps
  @style_caps
end

#style_colorObject (readonly)

Returns the value of attribute style_color.



35
36
37
# File 'lib/caracal/core/models/style_model.rb', line 35

def style_color
  @style_color
end

#style_defaultObject (readonly)

accessors



32
33
34
# File 'lib/caracal/core/models/style_model.rb', line 32

def style_default
  @style_default
end

#style_fontObject (readonly)

Returns the value of attribute style_font.



36
37
38
# File 'lib/caracal/core/models/style_model.rb', line 36

def style_font
  @style_font
end

#style_idObject (readonly)

Returns the value of attribute style_id.



33
34
35
# File 'lib/caracal/core/models/style_model.rb', line 33

def style_id
  @style_id
end

#style_italicObject (readonly)

Returns the value of attribute style_italic.



39
40
41
# File 'lib/caracal/core/models/style_model.rb', line 39

def style_italic
  @style_italic
end

#style_lineObject (readonly)

Returns the value of attribute style_line.



45
46
47
# File 'lib/caracal/core/models/style_model.rb', line 45

def style_line
  @style_line
end

#style_nameObject (readonly)

Returns the value of attribute style_name.



34
35
36
# File 'lib/caracal/core/models/style_model.rb', line 34

def style_name
  @style_name
end

#style_nextObject (readonly)

Returns the value of attribute style_next.



47
48
49
# File 'lib/caracal/core/models/style_model.rb', line 47

def style_next
  @style_next
end

#style_sizeObject (readonly)

Returns the value of attribute style_size.



37
38
39
# File 'lib/caracal/core/models/style_model.rb', line 37

def style_size
  @style_size
end

#style_topObject (readonly)

Returns the value of attribute style_top.



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

def style_top
  @style_top
end

#style_underlineObject (readonly)

Returns the value of attribute style_underline.



40
41
42
# File 'lib/caracal/core/models/style_model.rb', line 40

def style_underline
  @style_underline
end

Instance Method Details

#matches?(str) ⇒ Boolean

STATE ================================


110
111
112
# File 'lib/caracal/core/models/style_model.rb', line 110

def matches?(str)
  style_id.downcase == str.to_s.downcase
end

#valid?Boolean

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


117
118
119
120
# File 'lib/caracal/core/models/style_model.rb', line 117

def valid?
  a = [:id, :name]
  a.map { |m| send("style_#{ m }") }.compact.size == a.size
end