Class: JobCentral::Employer

Inherits:
Struct
  • Object
show all
Extended by:
Helpers
Includes:
Helpers
Defined in:
lib/job_central.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

open, parse_date

Instance Attribute Details

#date_updatedObject

Returns the value of attribute date_updated

Returns:

  • (Object)

    the current value of date_updated



41
42
43
# File 'lib/job_central.rb', line 41

def date_updated
  @date_updated
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



41
42
43
# File 'lib/job_central.rb', line 41

def name
  @name
end

Class Method Details

.allObject



48
49
50
# File 'lib/job_central.rb', line 48

def all
  parse(BASE_URI + "/index.asp")
end

.membersObject



52
53
54
# File 'lib/job_central.rb', line 52

def members
  parse(BASE_URI + "/index.asp?member=member")
end

.parse(uri) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/job_central.rb', line 56

def parse(uri)
  html = Nokogiri::HTML open(uri)
  employer_rows = ((html/"table")[-1]/"tr")
  employer_hash = Hash.new { |h, k| h[k] = Employer.new }

  employer_rows.each_with_index do |element, idx|
    next unless idx >= 2 # skip header rows
    attributes = element/"td"
    name = attributes[0].text.strip

    employer = employer_hash[name]
    employer.name = name
    employer.date_updated = [employer.date_updated, parse_date(attributes[3].text)].compact.max
    employer.feeds << BASE_URI + (attributes[1]/"a").attr('href')

  end
  employers = employer_hash.values
  employers.extend Finders
  employers
end

Instance Method Details

#feedsObject



85
86
87
# File 'lib/job_central.rb', line 85

def feeds
  @feeds ||= []
end

#jobsObject



79
80
81
82
83
# File 'lib/job_central.rb', line 79

def jobs
  feeds.map do |feed|
    Job.from_xml(feed)
  end.flatten
end