lib/readability.rb in ruby-readability-0.5.0.pre vs lib/readability.rb in ruby-readability-0.5.0
- old
+ new
@@ -47,14 +47,19 @@
:normalizeRe => /\s{2,}/,
:killBreaksRe => /(<br\s*\/?>(\s| ?)*){1,}/,
:videoRe => /http:\/\/(www\.)?(youtube|vimeo)\.com/i
}
+ def title
+ title = @html.css("title").first
+ title ? title.text : nil
+ end
+
def content(remove_unlikely_candidates = :default)
@remove_unlikely_candidates = false if remove_unlikely_candidates == false
- @html.css("script, style").each { |i| i.remove }
+ @html.css("script, style").each(&:remove)
remove_unlikely_candidates! if @remove_unlikely_candidates
transform_misused_divs_into_paragraphs!
candidates = score_paragraphs(options[:min_text_length])
best_candidate = select_best_candidate(candidates)
@@ -125,10 +130,10 @@
best_candidate
end
def get_link_density(elem)
- link_length = elem.css("a").map {|i| i.text}.join("").length
+ link_length = elem.css("a").map(&:text).join("").length
text_length = elem.text.length
link_length / text_length.to_f
end
def score_paragraphs(min_text_length)