class Caracal::Core::Models::ParagraphModel

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

Attributes

paragraph_align[R]
paragraph_bgcolor[R]
paragraph_bold[R]
paragraph_color[R]
paragraph_italic[R]
paragraph_size[R]
paragraph_style[R]

readers

paragraph_underline[R]

Public Class Methods

new(options={}, &block) click to toggle source

initialization

Calls superclass method Caracal::Core::Models::BaseModel::new
# File lib/caracal/core/models/paragraph_model.rb, line 32
def initialize(options={}, &block)
  content = options.delete(:content) { "" }
  text content, options.dup, &block
  super options, &block
end

Public Instance Methods

bookmark_end(*args, &block) click to toggle source
# File lib/caracal/core/models/paragraph_model.rb, line 109
def bookmark_end(*args, &block)
  options = Caracal::Utilities.extract_options!(args)
  options.merge!({ start: false})

  model = Caracal::Core::Models::BookmarkModel.new(options, &block)
  if model.valid?
    runs << model
  else
    raise Caracal::Errors::InvalidModelError, 'Bookmark ending tags require an id.'
  end
  model
end
bookmark_start(*args, &block) click to toggle source

.bookmarks

# File lib/caracal/core/models/paragraph_model.rb, line 97
def bookmark_start(*args, &block)
  options = Caracal::Utilities.extract_options!(args)
  options.merge!({ start: true})

  model = Caracal::Core::Models::BookmarkModel.new(options, &block)
  if model.valid?
    runs << model
  else
    raise Caracal::Errors::InvalidModelError, 'Bookmark starting tags require an id and a name.'
  end
  model
end
br() click to toggle source

.br

# File lib/caracal/core/models/paragraph_model.rb, line 123
def br
  model = Caracal::Core::Models::LineBreakModel.new()
  runs << model
  model
end
page() click to toggle source

.page

# File lib/caracal/core/models/paragraph_model.rb, line 145
def page
  model = Caracal::Core::Models::PageBreakModel.new({ wrap: false })
  runs << model
  model
end
run_attributes() click to toggle source

.run_attributes

# File lib/caracal/core/models/paragraph_model.rb, line 51
def run_attributes
  {
    color:      paragraph_color,
    size:       paragraph_size,
    bold:       paragraph_bold,
    italic:     paragraph_italic,
    underline:  paragraph_underline,
    bgcolor:    paragraph_bgcolor
  }
end
runs() click to toggle source

.runs

# File lib/caracal/core/models/paragraph_model.rb, line 46
def runs
  @runs ||= []
end
text(*args, &block) click to toggle source

.text

# File lib/caracal/core/models/paragraph_model.rb, line 152
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?() click to toggle source
VALIDATION ============================
# File lib/caracal/core/models/paragraph_model.rb, line 168
def valid?
  runs.size > 0
end

Private Instance Methods

option_keys() click to toggle source
# File lib/caracal/core/models/paragraph_model.rb, line 178
def option_keys
  [:content, :style, :align, :color, :size, :bold, :italic, :underline, :bgcolor]
end