Class: Chico::Fetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/chico/fetcher.rb

Overview

How it works: When given a domain w/o a path, try to find /favicon.ico If not found (or given a path), load the home page and search for one of:

  • <link rel=“shortcut icon” href=“example.com/myicon.ico” />

  • <link rel=“icon” type=“image/vnd.microsoft.icon” href=“example.com/image.ico” />

  • <link rel=“icon” type=“image/png” href=“” />

  • <link rel=“icon” type=“image/gif” href=“” />

If given a path, and the above didn’t work, retry on the domain’s index page

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Fetcher

Returns a new instance of Fetcher.



16
17
18
19
# File 'lib/chico/fetcher.rb', line 16

def initialize(url)
  @url = url
  @uri = GoGetter.parse_url @url
end

Instance Attribute Details

#searched_iconObject (readonly)

Returns the value of attribute searched_icon.



14
15
16
# File 'lib/chico/fetcher.rb', line 14

def searched_icon
  @searched_icon
end

#urlObject (readonly)

Returns the value of attribute url.



14
15
16
# File 'lib/chico/fetcher.rb', line 14

def url
  @url
end

Instance Method Details

#fetch(uri = @uri) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/chico/fetcher.rb', line 21

def fetch(uri=@uri)
  if @uri.path == '/'
    fetch_default || fetch_link_on_page(@url)
  else
    # try to find a favicon for the specific path first
    if path = fetch_link_on_page(@url)
      fetch_icon path
    else
    # if failed, try again with the root path

    end
  end
end