Class: Uniword::Builder::CommentBuilder
- Inherits:
-
Object
- Object
- Uniword::Builder::CommentBuilder
- Defined in:
- lib/uniword/builder/comment_builder.rb
Overview
Builds and configures Comment objects.
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Class Method Summary collapse
-
.from_model(model) ⇒ Object
Wrap an existing Comment model.
Instance Method Summary collapse
-
#<<(element) ⇒ self
Append text to the comment (creates a paragraph).
-
#build ⇒ Object
Return the underlying Comment model.
-
#initialize(author:, comment_id: nil, date: nil, initials: nil) ⇒ CommentBuilder
constructor
A new instance of CommentBuilder.
Constructor Details
#initialize(author:, comment_id: nil, date: nil, initials: nil) ⇒ CommentBuilder
Returns a new instance of CommentBuilder.
14 15 16 17 18 19 20 21 |
# File 'lib/uniword/builder/comment_builder.rb', line 14 def initialize(author:, comment_id: nil, date: nil, initials: nil) @model = Comment.new( author: , comment_id: comment_id, date: date, initials: initials, ) end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
12 13 14 |
# File 'lib/uniword/builder/comment_builder.rb', line 12 def model @model end |
Class Method Details
.from_model(model) ⇒ Object
Wrap an existing Comment model
24 25 26 27 28 |
# File 'lib/uniword/builder/comment_builder.rb', line 24 def self.from_model(model) builder = allocate builder.instance_variable_set(:@model, model) builder end |
Instance Method Details
#<<(element) ⇒ self
Append text to the comment (creates a paragraph)
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/uniword/builder/comment_builder.rb', line 34 def <<(element) case element when String para = Wordprocessingml::Paragraph.new para.runs << Wordprocessingml::Run.new(text: element) @model.paragraphs << para when Wordprocessingml::Paragraph @model.paragraphs << element else raise ArgumentError, "Cannot add #{element.class} to comment" end self end |
#build ⇒ Object
Return the underlying Comment model
49 50 51 |
# File 'lib/uniword/builder/comment_builder.rb', line 49 def build @model end |