2013-03-08 15:04:37 -05:00
|
|
|
# Summarize a HTML field into regular text. Used currently
|
|
|
|
# for meta tags
|
|
|
|
|
2013-03-22 07:32:56 -04:00
|
|
|
require 'sanitize'
|
2013-03-08 15:04:37 -05:00
|
|
|
|
2013-03-22 07:32:56 -04:00
|
|
|
class Summarize
|
2014-09-01 03:04:40 -04:00
|
|
|
|
2013-03-08 15:04:37 -05:00
|
|
|
def initialize(text)
|
|
|
|
@text = text
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.max_length
|
|
|
|
500
|
|
|
|
end
|
|
|
|
|
|
|
|
def summary
|
|
|
|
return nil if @text.blank?
|
|
|
|
|
2013-03-22 07:32:56 -04:00
|
|
|
result = Sanitize.clean(@text)
|
2013-03-08 15:04:37 -05:00
|
|
|
result.gsub!(/\n/, ' ')
|
|
|
|
result.strip!
|
|
|
|
|
|
|
|
return result if result.length <= Summarize.max_length
|
|
|
|
"#{result[0..Summarize.max_length]}..."
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|