Class: MarkdownToRspec::ToRspec::Item::Paragraph

Inherits:
Base
  • Object
show all
Defined in:
lib/markdown_to_rspec/to_rspec/item/paragraph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#indent

Constructor Details

#initialize(text:, parent: nil, children: []) ⇒ Paragraph

Returns a new instance of Paragraph.



7
8
9
10
11
12
# File 'lib/markdown_to_rspec/to_rspec/item/paragraph.rb', line 7

def initialize(text:, parent: nil, children: [])
  @text = text
  @parent = parent
  @children = children
  @depth = parent ? parent.depth + 1 : 0
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



14
15
16
# File 'lib/markdown_to_rspec/to_rspec/item/paragraph.rb', line 14

def children
  @children
end

#depthObject (readonly)

Returns the value of attribute depth.



14
15
16
# File 'lib/markdown_to_rspec/to_rspec/item/paragraph.rb', line 14

def depth
  @depth
end

#parentObject (readonly)

Returns the value of attribute parent.



14
15
16
# File 'lib/markdown_to_rspec/to_rspec/item/paragraph.rb', line 14

def parent
  @parent
end

#textObject (readonly)

Returns the value of attribute text.



14
15
16
# File 'lib/markdown_to_rspec/to_rspec/item/paragraph.rb', line 14

def text
  @text
end

Instance Method Details

#convertObject



16
17
18
19
# File 'lib/markdown_to_rspec/to_rspec/item/paragraph.rb', line 16

def convert
  lines = text.split("\n").map { |line| template(line) }
  lines.map { |line| indent(line) }.join("\n")
end