class Kudzu::Agent::Util::TitleParser

Public Class Methods

parse(response) click to toggle source
# File lib/kudzu/agent/util/title_parser.rb, line 6
def parse(response)
  if response.html?
    from_html(response.parsed_doc)
  else
    Addressable::URI.parse(response.url).basename
  end
rescue => e
  Kudzu.log :warn, "failed to parse title: #{response.url}", error: e
  nil
end

Private Class Methods

from_html(doc) click to toggle source
# File lib/kudzu/agent/util/title_parser.rb, line 19
def from_html(doc)
  if (node = doc.xpath('//head/title').first)
    node.inner_text.to_s
  else
    ''
  end
end