Class: WebStat::FetchAsWeb

Inherits:
Fetch
  • Object
show all
Defined in:
lib/web_stat/fetch/fetch_as_web.rb

Instance Attribute Summary

Attributes inherited from Fetch

#html, #nokogiri, #url, #userdic

Instance Method Summary collapse

Methods inherited from Fetch

#content, #eyecatch_image_path, #get_url, #save_local_path, #site_name, #stat, #title

Constructor Details

#initialize(url) ⇒ FetchAsWeb

initialize class

Parameters:

  • url (String)


7
8
9
10
11
12
13
14
# File 'lib/web_stat/fetch/fetch_as_web.rb', line 7

def initialize(url)
  unless url_valid?(url)
    raise WebStat::INVALID_URL, url
  end
  @url = original_url(url)
  @html = get_url(@url)
  @nokogiri = ::Nokogiri::HTML(@html)
end

Instance Method Details

#url_valid?(url) ⇒ Boolean

Validation url

Returns:

  • (Boolean)


17
18
19
20
# File 'lib/web_stat/fetch/fetch_as_web.rb', line 17

def url_valid?(url)
  regexp = Regexp.new("^https?://([a-zA-Z0-9][a-zA-Z0-9\\\-\.]{1,61}[a-zA-Z0-9])\\\.([a-zA-Z]{2,})(.*)?$", Regexp::IGNORECASE)
  regexp.match?(url)
end