Class: Prosereflect::Blockquote

Inherits:
Node
  • Object
show all
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

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

#blocksObject

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

#citationObject

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

Returns:

  • (Boolean)


68
69
70
# File 'lib/prosereflect/blockquote.rb', line 68

def citation?
  !citation.nil? && !citation.empty?
end

#remove_citationObject

Remove citation



73
74
75
76
# File 'lib/prosereflect/blockquote.rb', line 73

def remove_citation
  self.attrs ||= {}
  attrs.delete('citation')
end