Class: MarkdownFormatter::ASTNode::List

Inherits:
Base
  • Object
show all
Defined in:
lib/markdown_formatter/nodes/list.rb

Instance Attribute Summary

Attributes inherited from Base

#node

Instance Method Summary collapse

Constructor Details

#initialize(node, nest_level = 0) ⇒ List

Returns a new instance of List.



4
5
6
7
# File 'lib/markdown_formatter/nodes/list.rb', line 4

def initialize(node, nest_level = 0)
  super(node)
  @nest_level = nest_level
end

Instance Method Details

#to_sObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/markdown_formatter/nodes/list.rb', line 9

def to_s
  node[:children].map do |c|
    case c[:type]
      when :blank
        ""
      when :li
        ListItem.new(c, @nest_level).to_s
      else
        raise "Unexpected type. #{c[:type]}"
    end
  end.join("\n") + "\n"
end