class MusicStory::Utils::HTMLToText

Converts HTML to plain text, converting
‘s into newlines but stripping all other tags. May want to add support for other things like <p> into nn if they crop up; MusicStory only seems to use
though

Public Class Methods

convert(html) click to toggle source
# File lib/music_story/utils/html_to_text.rb, line 7
def self.convert(html)
  doc = new
  Nokogiri::HTML::SAX::Parser.new(doc).parse(html)
  doc.to_s
end
new() click to toggle source
# File lib/music_story/utils/html_to_text.rb, line 13
def initialize
  @result = ''
end

Public Instance Methods

cdata_block(string)
Alias for: characters
characters(string) click to toggle source
# File lib/music_story/utils/html_to_text.rb, line 17
def characters(string)
  @result << string
end
Also aliased as: cdata_block
start_element(name, attributes=nil) click to toggle source
# File lib/music_story/utils/html_to_text.rb, line 22
def start_element(name, attributes=nil)
  @result << "\n" if name.downcase == 'br'
end
to_s() click to toggle source
# File lib/music_story/utils/html_to_text.rb, line 26
def to_s
  @result.strip
end