Class: Jaleb::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/jaleb/data.rb

Overview

this class is responsible for fetching and parsing data

Class Method Summary collapse

Class Method Details

.read(url) ⇒ Object

Get read url and get data object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/jaleb/data.rb', line 9

def self.read(url )
   opt= {}
   opt['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36'
   response = open(url, opt)
  doc = ::Nokogiri::HTML(response.read)
   # Save contents of URL/Remote File for debugging
   response.rewind
   last_response_file = File.expand_path(File.join("..", "..", "last_response"), File.dirname(__FILE__))
   File.new(last_response_file, "w+").write(response.read)
  return doc	
end