Class: MarkdownToRspec::ToRspec::Formatter::Markdown

Inherits:
Object
  • Object
show all
Defined in:
lib/markdown_to_rspec/to_rspec/formatter/markdown.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(markdown:) ⇒ Markdown

Returns a new instance of Markdown.



12
13
14
15
16
# File 'lib/markdown_to_rspec/to_rspec/formatter/markdown.rb', line 12

def initialize(markdown:)
  @markdown = markdown
  @parsed_markdown = RDoc::Markdown.parse(markdown)
  @items = []
end

Instance Attribute Details

#itemsObject (readonly)

Returns the value of attribute items.



18
19
20
# File 'lib/markdown_to_rspec/to_rspec/formatter/markdown.rb', line 18

def items
  @items
end

#markdownObject (readonly)

Returns the value of attribute markdown.



18
19
20
# File 'lib/markdown_to_rspec/to_rspec/formatter/markdown.rb', line 18

def markdown
  @markdown
end

#parsed_markdownObject (readonly)

Returns the value of attribute parsed_markdown.



18
19
20
# File 'lib/markdown_to_rspec/to_rspec/formatter/markdown.rb', line 18

def parsed_markdown
  @parsed_markdown
end

Instance Method Details

#callObject



20
21
22
23
24
25
26
27
# File 'lib/markdown_to_rspec/to_rspec/formatter/markdown.rb', line 20

def call
  parsed_markdown.parts.each do |part|
    item = format(part, find_parent(part))
    @items << item
  end
  # Each item renders a child element, so only top-level items are converted.
  items.select { |item| item.parent.nil? }.map(&:convert).join("\n")
end