Class: HtmlToTextConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/rallycat/html_to_text_converter.rb

Instance Method Summary collapse

Constructor Details

#initialize(html_string) ⇒ HtmlToTextConverter

Returns a new instance of HtmlToTextConverter.



5
6
7
# File 'lib/rallycat/html_to_text_converter.rb', line 5

def initialize(html_string)
  @html_string = html_string
end

Instance Method Details

#parseObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rallycat/html_to_text_converter.rb', line 9

def parse
  return '' unless @html_string

  html = pre_parse

  @fragment = Nokogiri::HTML.fragment(html)

  add_newline_after_block_elements
  parse_whitespace
  parse_lists

  @fragment.content
end