Class: Homepage

Inherits:
Object
  • Object
show all
Defined in:
app/models/homepage.rb

Overview

Get the HTML code from a given home page URL Do some cleaning and UTF-8 conversion

Author:

  • guillaumeh

Defined Under Namespace

Classes: NotAccessibleError

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Homepage

Returns a new instance of Homepage.


14
15
16
# File 'app/models/homepage.rb', line 14

def initialize(url)
  @url = url
end

Instance Method Details

#fetchString

Fetch the given home page remove all Hyphen if any and convert to UTF-8

Returns:

  • (String)

    Homepage content


22
23
24
25
26
27
28
# File 'app/models/homepage.rb', line 22

def fetch
  content = fetch_content_from(@url)
  content = follow_http_equiv_refresh(content)
  clean_hyphen_and_non_utf8!(content)
rescue OpenURI::HTTPError => error
  raise NotAccessibleError, error.message
end