Class: Prosereflect::Blockquote
- Defined in:
- lib/prosereflect/blockquote.rb
Overview
It can contain other block-level content like paragraphs, lists, etc.
Constant Summary collapse
- PM_TYPE =
'blockquote'
Class Method Summary collapse
Instance Method Summary collapse
-
#add_block(content) ⇒ Object
Add a content block to the blockquote.
-
#add_blocks(blocks_content) ⇒ Object
Add multiple content blocks at once.
- #add_paragraph(text) ⇒ Object
-
#block_at(index) ⇒ Object
Get block at specific position.
-
#blocks ⇒ Object
Get all content blocks within the blockquote.
-
#citation ⇒ Object
Get citation/source of the blockquote.
-
#citation=(source) ⇒ Object
Update citation/source for the blockquote.
-
#citation? ⇒ Boolean
Check if blockquote has a citation.
-
#initialize(attributes = {}) ⇒ Blockquote
constructor
A new instance of Blockquote.
-
#remove_citation ⇒ Object
Remove citation.
Methods inherited from Node
#add_child, #find_all, #find_children, #find_first, #marks, #marks=, #parse_content, #process_attrs_data, #raw_marks, #text_content, #to_h, #to_yaml
Constructor Details
#initialize(attributes = {}) ⇒ Blockquote
Returns a new instance of Blockquote.
21 22 23 24 |
# File 'lib/prosereflect/blockquote.rb', line 21 def initialize(attributes = {}) attributes[:content] ||= [] super end |
Class Method Details
.create(attrs = nil) ⇒ Object
26 27 28 |
# File 'lib/prosereflect/blockquote.rb', line 26 def self.create(attrs = nil) new(attrs: attrs, content: []) end |
Instance Method Details
#add_block(content) ⇒ Object
Add a content block to the blockquote
38 39 40 |
# File 'lib/prosereflect/blockquote.rb', line 38 def add_block(content) add_child(content) end |
#add_blocks(blocks_content) ⇒ Object
Add multiple content blocks at once
43 44 45 46 47 |
# File 'lib/prosereflect/blockquote.rb', line 43 def add_blocks(blocks_content) blocks_content.each do |block_content| add_block(block_content) end end |
#add_paragraph(text) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/prosereflect/blockquote.rb', line 78 def add_paragraph(text) paragraph = Paragraph.new paragraph.add_text(text) add_child(paragraph) paragraph end |
#block_at(index) ⇒ Object
Get block at specific position
50 51 52 53 54 |
# File 'lib/prosereflect/blockquote.rb', line 50 def block_at(index) return nil if index.negative? blocks[index] end |
#blocks ⇒ Object
Get all content blocks within the blockquote
31 32 33 34 35 |
# File 'lib/prosereflect/blockquote.rb', line 31 def blocks return [] unless content content end |
#citation ⇒ Object
Get citation/source of the blockquote
63 64 65 |
# File 'lib/prosereflect/blockquote.rb', line 63 def citation attrs&.[]('citation') end |
#citation=(source) ⇒ Object
Update citation/source for the blockquote
57 58 59 60 |
# File 'lib/prosereflect/blockquote.rb', line 57 def citation=(source) self.attrs ||= {} attrs['citation'] = source end |
#citation? ⇒ Boolean
Check if blockquote has a citation
68 69 70 |
# File 'lib/prosereflect/blockquote.rb', line 68 def citation? !citation.nil? && !citation.empty? end |
#remove_citation ⇒ Object
Remove citation
73 74 75 76 |
# File 'lib/prosereflect/blockquote.rb', line 73 def remove_citation self.attrs ||= {} attrs.delete('citation') end |