Skip to content
Permalink
Browse files

Start work on to_geojson method for Stack Jobs

  • Loading branch information...
tuckerrc committed Apr 13, 2018
1 parent 5c5b472 commit 161b82951958af635d10c5b2bc38376d9924bda4
Showing with 33 additions and 40 deletions.
  1. +3 −2 app/controllers/stack_jobs_controller.rb
  2. +28 −5 app/models/stack_job.rb
  3. +2 −33 app/views/stack_jobs/index.html.erb
@@ -1,9 +1,10 @@
class StackJobsController < ApplicationController
def index
@search_term = params[:search] || '[ruby-on-rails]'
@search_term = params[:search] || '[gis]'
@min_experience = params[:min] || ''
@max_experience = params[:max] || ''
@job_type = params[:type] || ''
@stack_jobs = StackJob.for( @search_term, @min_experience, @max_experience, @job_type )

@stack_jobs = StackJob.new( @search_term, @min_experience, @max_experience, @job_type )
end
end
@@ -1,16 +1,39 @@
class StackJob
attr_accessor :url, :xml, :geojson

require 'active_support/core_ext/hash/conversions'
require 'pp'

def self.for( term, min_ex, max_ex, job_type )
url = "https://stackoverflow.com/jobs/feed?"\
def initialize( term, min_ex, max_ex, job_type )
@url = "https://stackoverflow.com/jobs/feed?"\
"q=#{term}"\
"&ms=#{min_ex}"\
"&mxs=#{max_ex}"\
"&j=#{job_type}"\
"&l=United%20States&d=20&u=Miles" # Currently the application only supports US
xml = Nokogiri::XML(open(url))
hash = Hash.from_xml(xml.to_s)
hash["rss"]["channel"]["item"]
@xml = Nokogiri::XML(open(url))
self.to_geojson
@geojson
end

def to_geojson
hash = Hash.from_xml(@xml.to_s)
items = hash['rss']['channel']['item']
json = '{ "type": "FeatureCollection","features" : ['
items.each do | item |
json << '{"type": "Feature", "properties": {'
json << '"show_on_map" : true,'
json << '"name" : "' << item['title'] << '",'
json << '"link" : "' << item['link'] << '",'
json << '"company" : "' << item['author']['name'] << '",'
json << '"city" : "' << item['location'] << '",'
json << '"date" : "' << item['pubDate'] << '",'

json << '},'
end
json = json[0...-1]
json << ']}'
@geojson = json
puts @geojson
end
end
@@ -27,39 +27,8 @@
/* Create the GeoJSON objects */
var geojson_jobs = {
"type": "FeatureCollection",
"features" : [
<% @stack_jobs.each do |job| %>
<% scs = split_city_state job["location"] %>
<% city_loc = find_coordinates(scs[0],scs[1]) %>
<% if city_loc.nil? then city_loc = find_coordinates("not found", "us") end %>
{
"type" : "Feature",
"properties": {
"show_on_map" : true,
"name" : "<%= job["title"] %>",
"link" : "<%= job["link"] %>",
"company" : "<%= job["author"]["name"] %>",
"city" : "<%= job["location"] %>",
"date" : "<%= job["pubDate"] %>",
<% categories = job["category"].presence || ["none"] %>
<% categories.is_a?(Array) ? categories = categories : categories = [categories] %>
"category" : <%= raw categories %>,
},
"geometry" : {
"type" : "Point",
"coordinates" : [ <%= city_loc.long %>, <%= city_loc.lat %> ]
}
},
<% end unless @stack_jobs.blank? %>
]};
<% if @stack_jobs.blank? %>
alert("No Jobs found try a new search")
<% end %>
var geojson_jobs = <%= puts @stack_jobs %>
</script>
<script>

0 comments on commit 161b829

Please sign in to comment.
You can’t perform that action at this time.