Class: Caracal::Core::Models::ParagraphModel

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

Overview

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

Direct Known Subclasses

ListItemModel

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

initialization



31
32
33
34
35
# File 'lib/caracal/core/models/paragraph_model.rb', line 31

def initialize(options={}, &block)
  content = options.delete(:content) { "" }
  text content, options.dup
  super options, &block
end

Instance Attribute Details

#paragraph_alignObject (readonly)

Returns the value of attribute paragraph_align.



22
23
24
# File 'lib/caracal/core/models/paragraph_model.rb', line 22

def paragraph_align
  @paragraph_align
end

#paragraph_bgcolorObject (readonly)

Returns the value of attribute paragraph_bgcolor.



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

def paragraph_bgcolor
  @paragraph_bgcolor
end

#paragraph_boldObject (readonly)

Returns the value of attribute paragraph_bold.



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

def paragraph_bold
  @paragraph_bold
end

#paragraph_colorObject (readonly)

Returns the value of attribute paragraph_color.



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

def paragraph_color
  @paragraph_color
end

#paragraph_italicObject (readonly)

Returns the value of attribute paragraph_italic.



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

def paragraph_italic
  @paragraph_italic
end

#paragraph_sizeObject (readonly)

Returns the value of attribute paragraph_size.



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

def paragraph_size
  @paragraph_size
end

#paragraph_styleObject (readonly)

readers



21
22
23
# File 'lib/caracal/core/models/paragraph_model.rb', line 21

def paragraph_style
  @paragraph_style
end

#paragraph_underlineObject (readonly)

Returns the value of attribute paragraph_underline.



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

def paragraph_underline
  @paragraph_underline
end

Instance Method Details

#brObject

.br



96
97
98
99
100
# File 'lib/caracal/core/models/paragraph_model.rb', line 96

def br
  model = Caracal::Core::Models::LineBreakModel.new()
  runs << model
  model
end

.link



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/caracal/core/models/paragraph_model.rb', line 103

def link(*args, &block)
  options = Caracal::Utilities.extract_options!(args)
  options.merge!({ content: args[0] }) if args[0]
  options.merge!({ href:    args[1] }) if args[1]

  model = Caracal::Core::Models::LinkModel.new(options, &block)
  if model.valid?
    runs << model
  else
    raise Caracal::Errors::InvalidModelError, ':link method must receive strings for the display text and the external href.'
  end
  model
end

#pageObject

.page



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

def page
  model = Caracal::Core::Models::PageBreakModel.new({ wrap: false })
  runs << model
  model
end

#run_attributesObject

.run_attributes



50
51
52
53
54
55
56
57
58
59
# File 'lib/caracal/core/models/paragraph_model.rb', line 50

def run_attributes
  {
    color:      paragraph_color,
    size:       paragraph_size,
    bold:       paragraph_bold,
    italic:     paragraph_italic,
    underline:  paragraph_underline,
    bgcolor:    paragraph_bgcolor
  }
end

#runsObject

.runs



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

def runs
  @runs ||= []
end

#text(*args, &block) ⇒ Object

.text



125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/caracal/core/models/paragraph_model.rb', line 125

def text(*args, &block)
  options = Caracal::Utilities.extract_options!(args)
  options.merge!({ content: args.first }) if args.first

  model = Caracal::Core::Models::TextModel.new(options, &block)
  if model.valid?
    runs << model
  else
    raise Caracal::Errors::InvalidModelError, ':text method must receive a string for the display text.'
  end
  model
end

#valid?Boolean

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

Returns:

  • (Boolean)


141
142
143
# File 'lib/caracal/core/models/paragraph_model.rb', line 141

def valid?
  runs.size > 0
end