Sha256: 51d7edfb06b22373f6bc8c349c96031c3241395aab3d68919b5e69df506a6ed8

Contents?: true

Size: 487 Bytes

Versions: 2

Compression:

Stored size: 487 Bytes

Contents

module RenderAsMarkdown
  class List

    attr_accessor :list_items

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

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

    alias_method  '<<', :add_list_item

    def render
      md = ''

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

      md
    end

    alias_method :to_s, :render

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
render-as-markdown-0.0.6 lib/render-as-markdown/list.rb
render-as-markdown-0.0.5 lib/render-as-markdown/markdown-list.rb