Module: UrlTitleGetter

Defined in:
lib/url_title_getter.rb,
lib/url_title_getter/version.rb

Constant Summary collapse

VERSION =
"0.1.4"

Class Method Summary collapse

Class Method Details

.get_decode_url(raw_url) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/url_title_getter.rb', line 20

def self.get_decode_url(raw_url)
  url = URI.decode(raw_url)
  begin
    url.count('?')
    url
  rescue
    raw_url
  end
end

.get_title(url, time_out_sec = 5) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/url_title_getter.rb', line 7

def self.get_title(url, time_out_sec = 5)
  begin
    Timeout::timeout(time_out_sec) do
      url.strip!
      title = Nokogiri::HTML.parse(open(url).read).xpath('//title').text
      title.strip!
      title
    end
  rescue
    nil
  end
end