Class: JobCentral::Job

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

Instance Attribute Summary collapse

Class Method Summary collapse

Methods included from Helpers

open, parse_date

Instance Attribute Details

#cityObject

Returns the value of attribute city

Returns:

  • (Object)

    the current value of city



99
100
101
# File 'lib/job_central.rb', line 99

def city
  @city
end

#countryObject

Returns the value of attribute country

Returns:

  • (Object)

    the current value of country



99
100
101
# File 'lib/job_central.rb', line 99

def country
  @country
end

#descriptionObject

Returns the value of attribute description

Returns:

  • (Object)

    the current value of description



99
100
101
# File 'lib/job_central.rb', line 99

def description
  @description
end

#employer_nameObject

Returns the value of attribute employer_name

Returns:

  • (Object)

    the current value of employer_name



99
100
101
# File 'lib/job_central.rb', line 99

def employer_name
  @employer_name
end

#expiration_dateObject

Returns the value of attribute expiration_date

Returns:

  • (Object)

    the current value of expiration_date



99
100
101
# File 'lib/job_central.rb', line 99

def expiration_date
  @expiration_date
end

#guidObject

Returns the value of attribute guid

Returns:

  • (Object)

    the current value of guid



99
100
101
# File 'lib/job_central.rb', line 99

def guid
  @guid
end

Returns the value of attribute imagelink

Returns:

  • (Object)

    the current value of imagelink



99
100
101
# File 'lib/job_central.rb', line 99

def imagelink
  @imagelink
end

#industriesObject

Returns the value of attribute industries

Returns:

  • (Object)

    the current value of industries



99
100
101
# File 'lib/job_central.rb', line 99

def industries
  @industries
end

Returns the value of attribute link

Returns:

  • (Object)

    the current value of link



99
100
101
# File 'lib/job_central.rb', line 99

def link
  @link
end

#locationObject

Returns the value of attribute location

Returns:

  • (Object)

    the current value of location



99
100
101
# File 'lib/job_central.rb', line 99

def location
  @location
end

#stateObject

Returns the value of attribute state

Returns:

  • (Object)

    the current value of state



99
100
101
# File 'lib/job_central.rb', line 99

def state
  @state
end

#titleObject

Returns the value of attribute title

Returns:

  • (Object)

    the current value of title



99
100
101
# File 'lib/job_central.rb', line 99

def title
  @title
end

#zip_codeObject

Returns the value of attribute zip_code

Returns:

  • (Object)

    the current value of zip_code



99
100
101
# File 'lib/job_central.rb', line 99

def zip_code
  @zip_code
end

Class Method Details

.extract_location(element) ⇒ Object



138
139
140
141
# File 'lib/job_central.rb', line 138

def self.extract_location(element)
  location = extract_text(element, "location")
  location.gsub(/^\,\s+/, '')
end

.extract_text(element, tag) ⇒ Object



133
134
135
136
# File 'lib/job_central.rb', line 133

def self.extract_text(element, tag)
  element = element.at(tag)
  element && element.text
end

.from_xml(uri) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/job_central.rb', line 106

def self.from_xml(uri)
  xml = Nokogiri::XML open(uri)
  jobs = []
  (xml/"job").each do |element|
    location = extract_location(element)
    parsed_location = LocationParser.parse(location)
    job = Job.new
    job.guid = extract_text(element, "guid")
    job.title = extract_text(element, "title")
    job.description = extract_text(element, "description")
    job.link = extract_text(element, "link")
    job.imagelink = extract_text(element, "imagelink")
    job.expiration_date = Date.parse(extract_text(element, "expiration_date"))
    job.employer_name = extract_text(element, "employer")
    job.location = location
    job.city = parsed_location[:city]
    job.state = parsed_location[:state]
    job.zip_code = parsed_location[:zip_code]
    job.country = parsed_location[:country]
    element.css("industry").each do |industry|
      job.industries << industry.text
    end
    jobs << job
  end
  jobs
end