Class: RenderAsMarkdown::List

Inherits:
Object
  • Object
show all
Defined in:
lib/render-as-markdown/list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(list_items) ⇒ List

Returns a new instance of List.



6
7
8
9
# File 'lib/render-as-markdown/list.rb', line 6

def initialize list_items
  # list_items will be an array
  @list_items = [*list_items]
end

Instance Attribute Details

#list_itemsObject

Returns the value of attribute list_items.



4
5
6
# File 'lib/render-as-markdown/list.rb', line 4

def list_items
  @list_items
end

Instance Method Details

#add_list_item(list_item) ⇒ Object Also known as: <<



11
12
13
14
# File 'lib/render-as-markdown/list.rb', line 11

def add_list_item list_item
  # concat arrays
  list_items.concat [*list_item]
end

#renderObject Also known as: to_s



18
19
20
21
22
23
24
25
26
# File 'lib/render-as-markdown/list.rb', line 18

def render
  md = ''

  @list_items.each do |item|
    md << "- #{item.to_s}\n"
  end

  md
end