Class: JobsCrawler::Robots::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/jobs_crawler/robots/base.rb

Direct Known Subclasses

AtooJob, EmploiSenegal, PagesJaunesSenegal, Senjob

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Base

Returns a new instance of Base.



5
6
7
8
# File 'lib/jobs_crawler/robots/base.rb', line 5

def initialize(url)
  @url = url
  @engine = Mechanize.new
end

Instance Attribute Details

#urlObject (readonly)

Returns the value of attribute url.



3
4
5
# File 'lib/jobs_crawler/robots/base.rb', line 3

def url
  @url
end

Instance Method Details

#crawlObject



10
11
12
13
# File 'lib/jobs_crawler/robots/base.rb', line 10

def crawl
  set_html
  to_json
end

#extract_content(css_selector) ⇒ Object



15
16
17
# File 'lib/jobs_crawler/robots/base.rb', line 15

def extract_content(css_selector)
  @html.css(css_selector).text
end

#set_htmlObject



23
24
25
# File 'lib/jobs_crawler/robots/base.rb', line 23

def set_html
  @html = Nokogiri::HTML(body)
end

#to_jsonObject

Raises:

  • (NotImplemetedError)


19
20
21
# File 'lib/jobs_crawler/robots/base.rb', line 19

def to_json
  raise NotImplemetedError, 'You need to provide a concrete implemetatioen'
end