Class: Sites::Base
- Inherits:
-
Object
- Object
- Sites::Base
- Defined in:
- lib/sites/base.rb
Direct Known Subclasses
ElixirRadar, JobsRails42, RailsJobs, RemoteOk, WeWorkRemotely
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#job_type ⇒ Object
readonly
Returns the value of attribute job_type.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(job_type: :programming) ⇒ Base
constructor
A new instance of Base.
- #open_page(url) ⇒ Object
Constructor Details
#initialize(job_type: :programming) ⇒ Base
Returns a new instance of Base.
6 7 8 9 10 11 12 13 |
# File 'lib/sites/base.rb', line 6 def initialize(job_type: :programming) @job_type = job_type @url = build_url @doc = Nokogiri::HTML(open_page(@url)) @current_time = Time.new @timestamp = @current_time.strftime("%Y%m%d%H%M%S") @count = get_count end |
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
4 5 6 |
# File 'lib/sites/base.rb', line 4 def doc @doc end |
#job_type ⇒ Object (readonly)
Returns the value of attribute job_type.
4 5 6 |
# File 'lib/sites/base.rb', line 4 def job_type @job_type end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
4 5 6 |
# File 'lib/sites/base.rb', line 4 def url @url end |
Instance Method Details
#open_page(url) ⇒ Object
15 16 17 18 19 20 21 22 23 |
# File 'lib/sites/base.rb', line 15 def open_page(url) sleep(rand(0..2.0)) unless ENV['RAILS_ENV'] == 'test' # less mechanical behaviour if ENV['RAILS_ENV'] == 'test' open(url) else open(url, 'User-Agent' => user_agent) end end |