Class: Crags::Country
- Inherits:
-
Object
show all
- Includes:
- Fetcher
- Defined in:
- lib/crags/country.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Fetcher
#fetch_doc, #fetch_request, #fetch_xml
Constructor Details
#initialize(code) ⇒ Country
Returns a new instance of Country.
14
15
16
|
# File 'lib/crags/country.rb', line 14
def initialize(code)
@code = code
end
|
Instance Attribute Details
#code ⇒ Object
Returns the value of attribute code.
4
5
6
|
# File 'lib/crags/country.rb', line 4
def code
@code
end
|
Class Method Details
.all ⇒ Object
10
11
12
|
# File 'lib/crags/country.rb', line 10
def self.all
codes.collect {|code| new(code)}
end
|
.codes ⇒ Object
6
7
8
|
# File 'lib/crags/country.rb', line 6
def self.codes
Config.country_codes
end
|
Instance Method Details
#doc ⇒ Object
22
23
24
|
# File 'lib/crags/country.rb', line 22
def doc
fetch_doc(url)
end
|
#links ⇒ Object
30
31
32
|
# File 'lib/crags/country.rb', line 30
def links
doc.search("#list a")
end
|
#locations ⇒ Object
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/crags/country.rb', line 34
def locations
if links.empty?
str = request.last_effective_url
[Location.new(str.strip_http)]
else
links.collect do |link|
Location.new(link["href"].strip_http)
end
end
end
|
#request ⇒ Object
26
27
28
|
# File 'lib/crags/country.rb', line 26
def request
fetch_request(url)
end
|
#url ⇒ Object
18
19
20
|
# File 'lib/crags/country.rb', line 18
def url
"#{Config.country_url}/#{code}"
end
|