Sha256: 4c10ecf9aff56e5094baa51effb6e3bdef0d5a7f993be81b65bde66206697f66

Contents?: true

Size: 713 Bytes

Versions: 2

Compression:

Stored size: 713 Bytes

Contents

# encoding: utf-8

class MarkdownString
  # Return markdown heading level1-6 from text
  #
  # === Example
  #
  # case list
  #
  #   MarkdownString.ul(%w{a b c})
  #
  # result
  #
  #   * a
  #   * b
  #   * c
  #
  # case not list
  #
  #   MarkdownString.ul("test") # => "test"
  #
  # case nil list
  #
  #   MarkdownString.ul([nil, nil])
  #
  # result
  #
  #   *
  #   *
  #
  # case empty list
  #
  #   MarkdownString.ul([]) # => ""
  #
  def self.ul(list)
    return list unless list.is_a?(Array)
    return '' if list.empty?
    list.reduce([]) do |ret, elm|
      elm = '' if elm.nil?
      ret << "* #{elm}"
      ret
    end.join("\n") + "\n"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tbpgr_utils-0.0.108 lib/markdown/ul.rb
tbpgr_utils-0.0.107 lib/markdown/ul.rb