Class: Destinations::TravelDestinations

Inherits:
Object
  • Object
show all
Defined in:
lib/destinations/travel_destinations_info.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

Returns the value of attribute link_url.



5
6
7
# File 'lib/destinations/travel_destinations_info.rb', line 5

def link_url
  @link_url
end

#list_numberObject

Returns the value of attribute list_number.



5
6
7
# File 'lib/destinations/travel_destinations_info.rb', line 5

def list_number
  @list_number
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/destinations/travel_destinations_info.rb', line 5

def name
  @name
end

#summaryObject

Returns the value of attribute summary.



5
6
7
# File 'lib/destinations/travel_destinations_info.rb', line 5

def summary
  @summary
end

Class Method Details

.allObject



53
54
55
# File 'lib/destinations/travel_destinations_info.rb', line 53

def self.all
    @@all
end

.find_input_to_index(input, more_input) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/destinations/travel_destinations_info.rb', line 64

def self.find_input_to_index(input, more_input)
  if input.to_i == 1
    self.all[more_input.to_i-1]
  elsif input.to_i == 2
    self.all[10 + more_input.to_i-1]
  elsif input.to_i == 3
    self.all[20 + more_input.to_i-1]
  elsif input.to_i == 4
    self.all[30 + more_input.to_i-1]
  end
end

.new_citiesObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/destinations/travel_destinations_info.rb', line 20

def self.new_cities
  Destinations::TravelDestinationsLists.scrape_cities.each do |city|
    new_city = self.new
    new_city.name = city.css(".marketing-article__header h1").text.scan(/[a-zA-Z]+.*/).join
    new_city.link_url = city.css("a").attribute("href").text
    new_city.list_number = city.css(".marketing-article__header h1").text.scan(/\d+/).join.to_i
    new_city.summary = city.css("p.marketing-article__content").text
    self.all << new_city
  end
end

.new_countriesObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/destinations/travel_destinations_info.rb', line 9

def self.new_countries
 Destinations::TravelDestinationsLists.scrape_countries.each do |country|
   new_country = self.new
   new_country.name = country.css(".marketing-article__header h1").text.scan(/[a-zA-Z]+.*/).join
   new_country.link_url = country.css("a").attribute("href").text
   new_country.list_number = country.css(".marketing-article__header h1").text.scan(/\d+/).join.to_i
   new_country.summary = country.css("p.marketing-article__content").text
   self.all << new_country
 end
end

.new_regionsObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/destinations/travel_destinations_info.rb', line 31

def self.new_regions
 Destinations::TravelDestinationsLists.scrape_regions.each do |region|
   new_region = self.new
   new_region.name = region.css(".marketing-article__header h1").text.scan(/[a-zA-Z]+.*/).join
   new_region.link_url = region.css("a").attribute("href").text
   new_region.list_number = region.css(".marketing-article__header h1").text.scan(/\d+/).join.to_i
   new_region.summary = region.css("p.marketing-article__content").text
   self.all << new_region
 end
end

.new_valueObject



42
43
44
45
46
47
48
49
50
51
# File 'lib/destinations/travel_destinations_info.rb', line 42

def self.new_value
 Destinations::TravelDestinationsLists.scrape_value.each do |value|
   new_value = self.new
   new_value.name = value.css(".marketing-article__header h1").text.scan(/[a-zA-Z]+.*/).join
   new_value.link_url = value.css("a").attribute("href").text
   new_value.list_number = value.css(".marketing-article__header h1").text.scan(/\d+/).join.to_i
   new_value.summary = value.css("p.marketing-article__content").text
   self.all << new_value
 end
end

.put_allObject



57
58
59
60
61
# File 'lib/destinations/travel_destinations_info.rb', line 57

def self.put_all
  self.all.each_with_index do |destination, index|
    puts "#{index+1}. #{destination.name}"
  end
end