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
76
77
|
# File 'lib/casento.rb', line 25
def self.get_page( page, opts )
opts.symbolize_keys!
url = "http://researcharchive.calacademy.org/research/entomology/EntInv/index.asp?"
params = {
"Page" => page,
"xAction" => "Search"
}
params["Country"] = opts[:country] if opts[:country]
params["StateProv"] = opts[:state] if opts[:state]
params["County"] = opts[:county] if opts[:county]
params["Ord"] = opts[:order] if opts[:order]
%w(Family Genus Species Subspecies).each do |rank|
val = opts[rank.to_sym] || opts[rank.downcase.to_sym]
params[rank] = val if val
end
url = "#{url}#{URI.encode_www_form( params )}"
= %w(
order
family
genus
species
subspecies
country
state
county
url
)
occurrences = []
open( url ) do |response|
html = Nokogiri::HTML(response.read)
html.xpath("//tr[td[@class='tdata']]").each do |tr|
occ = Occurrence.new
tr.css("td").each_with_index do |td, i|
val = if [i] == "url"
td.at("a")[:href]
else
td.inner_text.to_s
end
val = val.gsub(/[[:space:]]+$/, "").strip
next if val.blank?
next if val =~ /not entered/
occ.send("#{[i]}=", val)
end
occurrences << occ
end
end
occurrences
end
|