class SlackTransformer::Html::Lists

Attributes

input[R]

Public Class Methods

new(input) click to toggle source
# File lib/slack_transformer/html/lists.rb, line 8
def initialize(input)
  @input = input
end

Public Instance Methods

to_slack() click to toggle source
# File lib/slack_transformer/html/lists.rb, line 12
def to_slack
  fragment = Nokogiri::HTML.fragment(input)

  fragment.children.each do |child|
    case child.name
    when 'ul'
      list = child.children.map do |c|
        "• #{c.children.to_html}"
      end

      child.replace(list.join("\n"))
    when 'ol'
      list = child.children.map.with_index do |c, i|
        "#{i + 1}. #{c.children.to_html}"
      end

      child.replace(list.join("\n"))
    end
  end

  fragment.to_html
end