Module: MakeTextSearch::StripHtmlFilter

Extended by:
StripHtmlFilter
Included in:
StripHtmlFilter
Defined in:
lib/make-text-search/filters.rb

Instance Method Summary collapse

Instance Method Details

#apply_filter(record, value) ⇒ Object



33
34
35
36
# File 'lib/make-text-search/filters.rb', line 33

def apply_filter(record, value)
  # TODO extracts the content for some attributes like alt, title and longdesc
  translate_html_entities! value.gsub(/<[^>]*>/, "")
end

#translate_html_entities!(value) ⇒ Object



26
27
28
29
30
31
# File 'lib/make-text-search/filters.rb', line 26

def translate_html_entities!(value)
  # http://gist.github.com/582351
  @entities_map ||= File.read("#{File.dirname(__FILE__)}/html_entities.dat").split("\0").inject({}) {|hash, line| line = line.split(" ", 2); hash[line[0]] = line[1]; hash };

  value.gsub!(/&(\w+);/) { @entities_map[$1] || $1 } or value
end