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



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/caracal/core/models/style_model.rb', line 57

def initialize(options={}, &block)
  @style_default = false
  @style_type    = DEFAULT_STYLE_TYPE
  @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
    @style_outline    ||= DEFAULT_STYLE_OUTLINE
  end
end

Instance Attribute Details

#style_alignObject (readonly)

Returns the value of attribute style_align.



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

def style_align
  @style_align
end

#style_baseObject (readonly)

Returns the value of attribute style_base.



49
50
51
# File 'lib/caracal/core/models/style_model.rb', line 49

def style_base
  @style_base
end

#style_boldObject (readonly)

Returns the value of attribute style_bold.



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

def style_bold
  @style_bold
end

#style_bottomObject (readonly)

Returns the value of attribute style_bottom.



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

def style_bottom
  @style_bottom
end

#style_capsObject (readonly)

Returns the value of attribute style_caps.



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

def style_caps
  @style_caps
end

#style_colorObject (readonly)

Returns the value of attribute style_color.



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

def style_color
  @style_color
end

#style_defaultObject (readonly)

accessors



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

def style_default
  @style_default
end

#style_fontObject (readonly)

Returns the value of attribute style_font.



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

def style_font
  @style_font
end

#style_idObject (readonly)

Returns the value of attribute style_id.



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

def style_id
  @style_id
end

#style_indent_firstObject (readonly)

Returns the value of attribute style_indent_first.



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

def style_indent_first
  @style_indent_first
end

#style_indent_leftObject (readonly)

Returns the value of attribute style_indent_left.



51
52
53
# File 'lib/caracal/core/models/style_model.rb', line 51

def style_indent_left
  @style_indent_left
end

#style_indent_rightObject (readonly)

Returns the value of attribute style_indent_right.



52
53
54
# File 'lib/caracal/core/models/style_model.rb', line 52

def style_indent_right
  @style_indent_right
end

#style_italicObject (readonly)

Returns the value of attribute style_italic.



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

def style_italic
  @style_italic
end

#style_lineObject (readonly)

Returns the value of attribute style_line.



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

def style_line
  @style_line
end

#style_nameObject (readonly)

Returns the value of attribute style_name.



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

def style_name
  @style_name
end

#style_nextObject (readonly)

Returns the value of attribute style_next.



50
51
52
# File 'lib/caracal/core/models/style_model.rb', line 50

def style_next
  @style_next
end

#style_outlineObject (readonly)

Returns the value of attribute style_outline.



54
55
56
# File 'lib/caracal/core/models/style_model.rb', line 54

def style_outline
  @style_outline
end

#style_sizeObject (readonly)

Returns the value of attribute style_size.



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

def style_size
  @style_size
end

#style_topObject (readonly)

Returns the value of attribute style_top.



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

def style_top
  @style_top
end

#style_typeObject (readonly)

Returns the value of attribute style_type.



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

def style_type
  @style_type
end

#style_underlineObject (readonly)

Returns the value of attribute style_underline.



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

def style_underline
  @style_underline
end

Instance Method Details

#matches?(str) ⇒ Boolean

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

Returns:

  • (Boolean)


126
127
128
# File 'lib/caracal/core/models/style_model.rb', line 126

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

#type(value) ⇒ Object

custom



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

def type(value)
  allowed     = ['character', 'paragraph']
  given       = value.to_s.downcase.strip
  @style_type = allowed.include?(given) ? given : DEFAULT_STYLE_TYPE
end

#valid?Boolean

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

Returns:

  • (Boolean)


133
134
135
136
# File 'lib/caracal/core/models/style_model.rb', line 133

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