Class: Region

Inherits:
Object
  • Object
show all
Defined in:
lib/study_the_map/regions.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region) ⇒ Region

Returns a new instance of Region.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/study_the_map/regions.rb', line 7

def initialize(region)

  doc = Nokogiri::XML(open("https://skimap.org/Regions/view/#{LookupIDS.find_region_id(region)}.xml"))
  self.region_id = doc.search("region").attr('id').text

  puts "Here are the ski resorts in #{region}:"

  self.ski_areas = doc.search("skiArea").collect do |ski_area|
    "#{ski_area.text}"
  end

end

Instance Attribute Details

#region_idObject

Returns the value of attribute region_id.



5
6
7
# File 'lib/study_the_map/regions.rb', line 5

def region_id
  @region_id
end

#ski_areasObject

Returns the value of attribute ski_areas.



5
6
7
# File 'lib/study_the_map/regions.rb', line 5

def ski_areas
  @ski_areas
end

Class Method Details

.regions_listObject



43
44
45
46
47
48
49
50
51
# File 'lib/study_the_map/regions.rb', line 43

def self.regions_list

  regions_list_array = []
  LookupIDS.index.css("regions region").each do |region|
    regions_list_array << region.text.strip
  end
  regions_list_array.uniq

end

.ski_area_listObject



53
54
55
56
57
# File 'lib/study_the_map/regions.rb', line 53

def self.ski_area_list

  LookupIDS.index.search("skiArea name").map {|ski_area| ski_area.text}
  
end

.starts_with(letter) ⇒ Object



20
21
22
23
24
25
# File 'lib/study_the_map/regions.rb', line 20

def self.starts_with(letter)
  # regions that start with
  regions_starts_with_letter = self.regions_list.select {|region_name| region_name.start_with?(letter.upcase)}
  regions_starts_with_letter.each.with_index(1) {|region_name, index| puts "#{index}. #{region_name}"}

end

Instance Method Details

#full_listObject



37
38
39
40
41
# File 'lib/study_the_map/regions.rb', line 37

def full_list

  self.ski_areas.each.with_index(1){|area, i| puts "#{i}. #{area}"}

end

#starts_with(letter) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/study_the_map/regions.rb', line 27

def starts_with(letter)

  results = self.ski_areas.select do |area| 
    area.start_with?("#{letter}", "#{letter.upcase}")
  end

  results.each.with_index(1){|area, i| puts "#{i}. #{area}"}

end