class SeoApp::LinkParser
Attributes
geo[R]
headers[R]
links[R]
time[R]
url[R]
Public Class Methods
new(url)
click to toggle source
# File lib/seo_app/link_parser.rb, line 13 def initialize(url) @url = URI.parse(url) @links = [] @headers = [] @geo = {} @time = Time.now.strftime('%Y.%d.%m_%H-%M-%S') end
say_hello()
click to toggle source
# File lib/seo_app/link_parser.rb, line 69 def self.say_hello puts 'Hello' end
Public Instance Methods
check_url()
click to toggle source
# File lib/seo_app/link_parser.rb, line 64 def check_url @url = !@url.scheme ? URI.parse('http://' + @url.to_s) : @url @url.is_a?(URI::HTTP) ? true : false end
gather_links!(body)
click to toggle source
# File lib/seo_app/link_parser.rb, line 41 def gather_links!(body) ::Nokogiri::HTML(body).css('a').each do |link| @links << { name: link.text || 'None', url: link['href'] || 'None', rel: link['rel'] || 'None', target: link['target'] || 'None' } end end
generate_file_name()
click to toggle source
# File lib/seo_app/link_parser.rb, line 52 def generate_file_name "#{@url.host}__#{@time}.html" end
generate_report()
click to toggle source
# File lib/seo_app/link_parser.rb, line 56 def generate_report Slim::Template.new('views/reports.slim').render(self) end
parse!()
click to toggle source
# File lib/seo_app/link_parser.rb, line 21 def parse! return false unless check_url begin _response = HTTParty.get @url rescue return false end procces_response _response end
procces_response(response)
click to toggle source
# File lib/seo_app/link_parser.rb, line 33 def procces_response(response) @headers = response.headers @geo = retrieve_geo_params gather_links! response.body SeoApp::Storage.save_report(generate_report, generate_file_name) end
retrieve_geo_params()
click to toggle source
# File lib/seo_app/link_parser.rb, line 60 def retrieve_geo_params GeoIP.new(SeoApp.root_path.join('db/GeoLiteCity.dat')).city(@url.host.to_s) end