Class: TravelLeisure::Destination

Inherits:
Object
  • Object
show all
Defined in:
lib/travel_leisure/destination.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(city = nil, country = nil, url = nil) ⇒ Destination

Returns a new instance of Destination.



13
14
15
16
17
18
# File 'lib/travel_leisure/destination.rb', line 13

def initialize(city=nil,country=nil,url=nil)
  @city = city
  @country = country
  @url = url
  save
end

Instance Attribute Details

#best_time_to_visitObject

Returns the value of attribute best_time_to_visit.



3
4
5
# File 'lib/travel_leisure/destination.rb', line 3

def best_time_to_visit
  @best_time_to_visit
end

#cityObject

Returns the value of attribute city.



3
4
5
# File 'lib/travel_leisure/destination.rb', line 3

def city
  @city
end

#countryObject

Returns the value of attribute country.



3
4
5
# File 'lib/travel_leisure/destination.rb', line 3

def country
  @country
end

#currencyObject

Returns the value of attribute currency.



3
4
5
# File 'lib/travel_leisure/destination.rb', line 3

def currency
  @currency
end

#descriptionObject

Returns the value of attribute description.



3
4
5
# File 'lib/travel_leisure/destination.rb', line 3

def description
  @description
end

#know_before_visitingObject

Returns the value of attribute know_before_visiting.



3
4
5
# File 'lib/travel_leisure/destination.rb', line 3

def know_before_visiting
  @know_before_visiting
end

#languageObject

Returns the value of attribute language.



3
4
5
# File 'lib/travel_leisure/destination.rb', line 3

def language
  @language
end

#transportationObject

Returns the value of attribute transportation.



3
4
5
# File 'lib/travel_leisure/destination.rb', line 3

def transportation
  @transportation
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/travel_leisure/destination.rb', line 3

def url
  @url
end

#weatherObject

Returns the value of attribute weather.



3
4
5
# File 'lib/travel_leisure/destination.rb', line 3

def weather
  @weather
end

Class Method Details

.allObject



20
21
22
# File 'lib/travel_leisure/destination.rb', line 20

def self.all
  @@all
end

.find(index) ⇒ Object



28
29
30
# File 'lib/travel_leisure/destination.rb', line 28

def self.find(index)
  self.all[index-1]
end

.new_from_website(r) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/travel_leisure/destination.rb', line 5

def self.new_from_website(r)
  self.new(
    r.css("span.grid__item__title").text,
    r.css("span.grid__item__cat").text,
    r.css("a").attribute("href")
  )
end

Instance Method Details

#docObject



32
33
34
# File 'lib/travel_leisure/destination.rb', line 32

def doc
  @doc ||= Nokogiri::HTML(open(self.url))
end

#saveObject



24
25
26
# File 'lib/travel_leisure/destination.rb', line 24

def save
  @@all << self
end