Class: Caracal::Core::Models::ParagraphModel
- 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
Instance Attribute Summary collapse
-
#paragraph_align ⇒ Object
readonly
Returns the value of attribute paragraph_align.
-
#paragraph_bgcolor ⇒ Object
readonly
Returns the value of attribute paragraph_bgcolor.
-
#paragraph_bold ⇒ Object
readonly
Returns the value of attribute paragraph_bold.
-
#paragraph_color ⇒ Object
readonly
Returns the value of attribute paragraph_color.
-
#paragraph_italic ⇒ Object
readonly
Returns the value of attribute paragraph_italic.
-
#paragraph_size ⇒ Object
readonly
Returns the value of attribute paragraph_size.
-
#paragraph_style ⇒ Object
readonly
readers.
-
#paragraph_underline ⇒ Object
readonly
Returns the value of attribute paragraph_underline.
Instance Method Summary collapse
- #bookmark_end(*args, &block) ⇒ Object
-
#bookmark_start(*args, &block) ⇒ Object
.bookmarks.
-
#br ⇒ Object
.br.
-
#field(*args, &block) ⇒ Object
.page_num.
-
#initialize(options = {}, &block) ⇒ ParagraphModel
constructor
initialization.
-
#link(*args, &block) ⇒ Object
.link.
-
#page ⇒ Object
.page.
-
#run_attributes ⇒ Object
.run_attributes.
-
#runs ⇒ Object
.runs.
-
#text(*args, &block) ⇒ Object
.text.
-
#valid? ⇒ Boolean
VALIDATION ============================.
Constructor Details
#initialize(options = {}, &block) ⇒ ParagraphModel
initialization
33 34 35 36 37 |
# File 'lib/caracal/core/models/paragraph_model.rb', line 33 def initialize(={}, &block) content = .delete(:content) { "" } text content, .dup, &block super , &block end |
Instance Attribute Details
#paragraph_align ⇒ Object (readonly)
Returns the value of attribute paragraph_align.
24 25 26 |
# File 'lib/caracal/core/models/paragraph_model.rb', line 24 def paragraph_align @paragraph_align end |
#paragraph_bgcolor ⇒ Object (readonly)
Returns the value of attribute paragraph_bgcolor.
30 31 32 |
# File 'lib/caracal/core/models/paragraph_model.rb', line 30 def paragraph_bgcolor @paragraph_bgcolor end |
#paragraph_bold ⇒ Object (readonly)
Returns the value of attribute paragraph_bold.
27 28 29 |
# File 'lib/caracal/core/models/paragraph_model.rb', line 27 def paragraph_bold @paragraph_bold end |
#paragraph_color ⇒ Object (readonly)
Returns the value of attribute paragraph_color.
25 26 27 |
# File 'lib/caracal/core/models/paragraph_model.rb', line 25 def paragraph_color @paragraph_color end |
#paragraph_italic ⇒ Object (readonly)
Returns the value of attribute paragraph_italic.
28 29 30 |
# File 'lib/caracal/core/models/paragraph_model.rb', line 28 def paragraph_italic @paragraph_italic end |
#paragraph_size ⇒ Object (readonly)
Returns the value of attribute paragraph_size.
26 27 28 |
# File 'lib/caracal/core/models/paragraph_model.rb', line 26 def paragraph_size @paragraph_size end |
#paragraph_style ⇒ Object (readonly)
readers
23 24 25 |
# File 'lib/caracal/core/models/paragraph_model.rb', line 23 def paragraph_style @paragraph_style end |
#paragraph_underline ⇒ Object (readonly)
Returns the value of attribute paragraph_underline.
29 30 31 |
# File 'lib/caracal/core/models/paragraph_model.rb', line 29 def paragraph_underline @paragraph_underline end |
Instance Method Details
#bookmark_end(*args, &block) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/caracal/core/models/paragraph_model.rb', line 110 def bookmark_end(*args, &block) = Caracal::Utilities.(args) .merge!({ start: false}) model = Caracal::Core::Models::BookmarkModel.new(, &block) if model.valid? runs << model else raise Caracal::Errors::InvalidModelError, 'Bookmark ending tags require an id.' end model end |
#bookmark_start(*args, &block) ⇒ Object
.bookmarks
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/caracal/core/models/paragraph_model.rb', line 98 def bookmark_start(*args, &block) = Caracal::Utilities.(args) .merge!({ start: true}) model = Caracal::Core::Models::BookmarkModel.new(, &block) if model.valid? runs << model else raise Caracal::Errors::InvalidModelError, 'Bookmark starting tags require an id and a name.' end model end |
#br ⇒ Object
.br
124 125 126 127 128 |
# File 'lib/caracal/core/models/paragraph_model.rb', line 124 def br model = Caracal::Core::Models::LineBreakModel.new() runs << model model end |
#field(*args, &block) ⇒ Object
.page_num
131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/caracal/core/models/paragraph_model.rb', line 131 def field(*args, &block) = Caracal::Utilities.(args) = .merge({ type: args[0] }) model = Caracal::Core::Models::FieldModel.new(, &block) if model.valid? runs << model else raise Caracal::Errors::InvalidModelError, ':page_num method must receive a string for the display text.' end model end |
#link(*args, &block) ⇒ Object
.link
145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/caracal/core/models/paragraph_model.rb', line 145 def link(*args, &block) = Caracal::Utilities.(args) .merge!({ content: args[0] }) if args[0] .merge!({ href: args[1] }) if args[1] model = Caracal::Core::Models::LinkModel.new(, &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 |
#page ⇒ Object
.page
160 161 162 163 164 |
# File 'lib/caracal/core/models/paragraph_model.rb', line 160 def page model = Caracal::Core::Models::PageBreakModel.new({ wrap: false }) runs << model model end |
#run_attributes ⇒ Object
.run_attributes
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/caracal/core/models/paragraph_model.rb', line 52 def run_attributes { color: paragraph_color, size: paragraph_size, bold: paragraph_bold, italic: paragraph_italic, underline: paragraph_underline, bgcolor: paragraph_bgcolor } end |
#runs ⇒ Object
.runs
47 48 49 |
# File 'lib/caracal/core/models/paragraph_model.rb', line 47 def runs @runs ||= [] end |
#text(*args, &block) ⇒ Object
.text
167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/caracal/core/models/paragraph_model.rb', line 167 def text(*args, &block) = Caracal::Utilities.(args) .merge!({ content: args.first }) if args.first model = Caracal::Core::Models::TextModel.new(, &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 ============================
183 184 185 |
# File 'lib/caracal/core/models/paragraph_model.rb', line 183 def valid? runs.size > 0 end |