Method: DiceSearch.parse_listings

Defined in:
lib/dice/dice.rb

.parse_listings(query) ⇒ Object

Parse the provided query data

Parameters:

  • query (String, #read)

    the html web page data



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
70
71
72
73
74
75
# File 'lib/dice/dice.rb', line 24

def self.parse_listings(query)

	# Create the listings
	listings = Array.new

	# Filter the data with Hpricot
	doc = Hpricot(query)

	# Get the table
	table = (doc/"//table[@class=summary]")
	
	# Get the rows
	rows = (table/"tr")
	
	# Retrieve the table rows that contain the job listings
	rows.each { |row|
	
		# Get the individual cells
		cells = (row/"td")
	
		# If this is a job listing
		if cells.size == CELL_COUNT

			# Get the fields
			name = (cells[TITLE_CELL]/"a").inner_html
			link = DICE_LINK + (cells[TITLE_CELL]/"a").attr("href")
			company = (cells[COMPANY_CELL]/"a").inner_html
			company_link = DICE_LINK + (cells[COMPANY_CELL]/"a").attr("href")
			location = cells[LOCATION_CELL].inner_html
			date = cells[DATE_CELL].inner_html

			if DEBUG
				puts "Row: count #{cells.size}"
				puts "Name: #{name}"
				puts "Link: #{link}"
				puts "Company: #{company}"
				puts "Company Link: #{company_link}"
				puts "Location: #{location}"
				puts "Date: #{date}"
			end

			# Create the job listing
			listings << JobListing.new(name, link, company, company_link, location, date, nil)

		end

	}

	# Return the listings
	return listings

end