Class: Crags::Country

Inherits:
Object
  • 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_html, #fetch_request

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

#codeObject (readonly)

Returns the value of attribute code.



4
5
6
# File 'lib/crags/country.rb', line 4

def code
  @code
end

Class Method Details

.allObject



10
11
12
# File 'lib/crags/country.rb', line 10

def self.all
  codes.collect {|code| new(code)}
end

.codesObject



6
7
8
# File 'lib/crags/country.rb', line 6

def self.codes
  Config.country_codes
end

Instance Method Details

#docObject



22
23
24
# File 'lib/crags/country.rb', line 22

def doc
  fetch_doc(url)
end


30
31
32
# File 'lib/crags/country.rb', line 30

def links
  doc.search("#list a")
end

#locationsObject



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

#requestObject



26
27
28
# File 'lib/crags/country.rb', line 26

def request
  fetch_request(url)
end

#urlObject



18
19
20
# File 'lib/crags/country.rb', line 18

def url
  "#{Config.country_url}/#{code}"
end