Class: Devry::Job
- Inherits:
-
Object
- Object
- Devry::Job
- Extended by:
- Helpers
- Includes:
- Helpers
- Defined in:
- lib/devry.rb
Constant Summary collapse
- BASE_URI =
'https://devryuniversity-devry.icims.com/jobs/search?pr='
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#posted_date ⇒ Object
readonly
Returns the value of attribute posted_date.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #city ⇒ Object
- #country ⇒ Object
- #description ⇒ Object
-
#initialize(attributes = {}) ⇒ Job
constructor
A new instance of Job.
- #state ⇒ Object
Methods included from Helpers
agent, extract_text, extract_time, extract_url, fetch_page
Constructor Details
#initialize(attributes = {}) ⇒ Job
Returns a new instance of Job.
73 74 75 76 77 |
# File 'lib/devry.rb', line 73 def initialize(attributes = {}) attributes.each do |k, v| instance_variable_set(:"@#{k}", v) end end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
71 72 73 |
# File 'lib/devry.rb', line 71 def id @id end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
71 72 73 |
# File 'lib/devry.rb', line 71 def location @location end |
#posted_date ⇒ Object (readonly)
Returns the value of attribute posted_date.
71 72 73 |
# File 'lib/devry.rb', line 71 def posted_date @posted_date end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
71 72 73 |
# File 'lib/devry.rb', line 71 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
71 72 73 |
# File 'lib/devry.rb', line 71 def url @url end |
Class Method Details
.all ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/devry.rb', line 39 def self.all page = fetch_page("#{BASE_URI}1") page.body =~ /Page (\d+) of (\d+)/ page_count = $2.to_i jobs = [] (1..page_count).each do |page_number| page = fetch_page("#{BASE_URI}#{page_number}") page.search(".iCIMS_JobsTable tr").each_with_index do |row, idx| next if idx == 0 # skip header details = row.search("td") job = Job.new(:id => extract_text(details[0]), :title => extract_text(details[1]), :location => extract_text(details[2]), :posted_date => extract_time(details[3]), :url => extract_url(details[1])) jobs << job end end jobs end |
Instance Method Details
#city ⇒ Object
79 80 81 |
# File 'lib/devry.rb', line 79 def city split_location[2] end |
#country ⇒ Object
87 88 89 |
# File 'lib/devry.rb', line 87 def country split_location[0] end |
#description ⇒ Object
91 92 93 94 95 96 |
# File 'lib/devry.rb', line 91 def description page = fetch_page(url) ["tr:nth-child(11)", "tr:nth-child(13)", "tr:nth-child(15)"].map do |selector| extract_text page.at(selector) end.join("\n\n") end |
#state ⇒ Object
83 84 85 |
# File 'lib/devry.rb', line 83 def state split_location[1] end |