top-travel-destinations-cli-gem 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e8a820e99855dde9db204f393c40bbedd3d730c
4
- data.tar.gz: 255dfa7e4d16aabe03daddb76f40cb81aa53027d
3
+ metadata.gz: 41c5b40a871276d4b88a3596a8ad47927f4e05db
4
+ data.tar.gz: d98d9d4c25ba8a46f7a1531df6520fb2b6440c54
5
5
  SHA512:
6
- metadata.gz: 974d7ee2b07c7e9a2e7e9b89f09bc6edfc8824766cfe038fd887a4df0ed463ff9eb04c51d9bc5dd31fe47095c26102c32f41af2434b695673d9953b50a68c0ee
7
- data.tar.gz: d1ca9ac4d7384d9fa29373480eadfff7c209454fe229abde580cd8b27e447fe714886c4a27b60e18835dc8118be7cae898722ab04c98e76012ee5c8849e7145b
6
+ metadata.gz: ddac693af27ea32d6c9a9c642f41f7b9619592a1fa68cb350cbe40b51ea7d8890c951ff5903e13fa8c1b748cc83cfe9e5058e1ee9d1b44753ed91d5fb13ca988
7
+ data.tar.gz: 7479d3c7c958a724e847a40204d20b5b948e52cc274e9ff76d59914ef12dde84ce8ee317bd4598288489ce9867693a18f0cdaf4577c7aaf1cd50031df37ab8d1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- top-travel-destinations-cli-gem (1.2.0)
4
+ top-travel-destinations-cli-gem (1.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # TopTravelDestinations
2
2
 
3
- Welcome to the Top Travel Destinations CLI gem! This gem was inspired by a love for traveling the world and learning about new cultures and experiences. The gem uses information from the TripAdvisor Travelers' Choice Destinations website (http://www.tripadvisor.com/TravelersChoice-Destinations) to provide you with easy-access to two levels of information: (1) the regions of the world; and (2) the top destinations of that region, as provided by TripAdvisor. The world is your oyster. Safe travels and thank you for using the Top Travel Destinations CLI gem.
3
+ Welcome to the Top Travel Destinations CLI gem! This gem was inspired by a love for traveling the world and learning about new cultures and experiences. The gem uses information from the TripAdvisor Travelers' Choice Destinations website (http://www.tripadvisor.com/TravelersChoice-Destinations) to provide you with easy-access to three levels of information: (1) the regions of the world; (2) the top destinations of that region; and (3) a description of each top destination, as provided by TripAdvisor. The world is your oyster. Safe travels and thank you for using the Top Travel Destinations CLI gem.
4
4
 
5
5
  ## Installation
6
6
 
@@ -22,10 +22,11 @@ Or install it yourself as:
22
22
 
23
23
  The Top Travel Destinations CLI gem has simple instructions:
24
24
  1) At the "Here are the Regions of the World" prompt, enter an alphanumeric number (i.e., 1-9) to select a region.
25
- 2) The gem will automatically generate the Top Travel Destinations for that region.
26
- 3) After viewing Top Destinations for one region, either enter:
27
- (a)'list' to return to the list of regions;
28
- (b) 'exit' to leave the gem.
25
+ 2) At the "Here are the Top Travel Destinations For the Region" prompt, enter an alphanumeric number to select a destination.
26
+ 3) Other options for viewing various menus, include:
27
+ (a) 'regions' to return to the list of regions;
28
+ (b) 'destinations' to return to the list of destinations for a region;
29
+ (c) 'exit' to leave the gem.
29
30
 
30
31
  ## Development
31
32
 
@@ -5,4 +5,5 @@ require 'open-uri'
5
5
  require_relative "../lib/top_travel_destinations/version"
6
6
  require_relative '../lib/top_travel_destinations/cli'
7
7
  require_relative '../lib/top_travel_destinations/scraper'
8
- require_relative '../lib/top_travel_destinations/region'
8
+ require_relative '../lib/top_travel_destinations/region'
9
+ require_relative '../lib/top_travel_destinations/destination'
@@ -2,9 +2,8 @@ class TopTravelDestinations::CLI
2
2
 
3
3
  def call
4
4
  welcome_screen
5
- make_regions
5
+ make_regions_and_destinations
6
6
  list_regions
7
- select_region
8
7
  end
9
8
 
10
9
  def welcome_screen
@@ -21,9 +20,10 @@ class TopTravelDestinations::CLI
21
20
  puts " `-....-'"
22
21
  end
23
22
 
24
- def make_regions
25
- region_array = TopTravelDestinations::Region.get_regions
26
- TopTravelDestinations::Region.create_from_array(region_array)
23
+ def make_regions_and_destinations
24
+ regions_array = TopTravelDestinations::Region.get_regions
25
+ TopTravelDestinations::Region.create_from_array(regions_array)
26
+ #Destination instances are instantiated within the Region Class, after each Region instance is instantiated
27
27
  end
28
28
 
29
29
  def list_regions
@@ -32,40 +32,69 @@ class TopTravelDestinations::CLI
32
32
  TopTravelDestinations::Region.all.each_with_index do |region, index|
33
33
  puts "#{index+1}. #{region.name}"
34
34
  end
35
+ select_region
35
36
  end
36
37
 
37
38
  def select_region
38
- input = nil
39
- while input != "exit"
39
+ #input = nil
40
+ #while input != "exit"
40
41
  puts "\n"
41
- puts "Enter the number of the region for which you would like the Top Travel Destinations."
42
- puts "Enter 'list' to see the regions again OR type 'exit'."
42
+ puts "Enter the number of the region (1-#{TopTravelDestinations::Region.all.count}) for which you would like the Top Travel Destinations."
43
+ puts "Enter 'regions' to see the regions again OR type 'exit'."
43
44
  input = gets.strip.downcase
44
45
  if (1..TopTravelDestinations::Region.all.count).to_a.include?(input.to_i)
45
- index_value = input.to_i-1
46
- show_top_destinations(index_value)
47
- elsif input == "list"
46
+ region_index = input.to_i-1
47
+ list_destinations(region_index)
48
+ elsif input == "regions"
48
49
  list_regions
50
+ select_region
49
51
  elsif input == "exit"
50
52
  goodbye
51
53
  else
52
54
  puts "\n"
53
55
  puts "Please input a valid command."
54
- end #end case
55
- end #end while loop
56
+ select_region
57
+ end #end if statement
58
+ #end #end while loop
56
59
  end #end method
57
60
 
58
- def show_top_destinations(index_value)
59
- #refactored calling the specific region and set equal to local variable 'region_instance'
60
- region_instance = TopTravelDestinations::Region.all[index_value]
61
+ def list_destinations(region_index)
62
+ region = TopTravelDestinations::Region.all[region_index]
61
63
  puts "\n"
62
- puts "The Top Destinations For the #{region_instance.name} region are:"
64
+ puts "Here are the Top #{region.destinations.count} Travel Destinations For the #{region.name} Region:"
63
65
  counter = 1
64
- region_instance.destinations.each do |destination|
66
+ region.destination_names.each do |destination|
65
67
  puts "#{counter}. #{destination}"
66
68
  counter +=1
67
69
  end
70
+ select_destination(region_index)
68
71
  end
72
+
73
+ def select_destination(region_index)
74
+ region = TopTravelDestinations::Region.all[region_index]
75
+ puts "\n"
76
+ puts "Enter the number of the Top #{region.name} Travel Destination (1-#{region.destinations.count}) for which you would like a description."
77
+ puts "Enter 'destinations' to see the list of #{region.name} destinations again OR 'regions' to go back to the regions OR 'exit'."
78
+ input = gets.strip.downcase
79
+ if input == "regions"
80
+ list_regions
81
+ elsif input == "destinations"
82
+ list_destinations(region_index)
83
+ elsif input == "exit"
84
+ goodbye
85
+ elsif (1..region.destinations.count).to_a.include?(input.to_i)
86
+ destination_index = input.to_i-1
87
+ puts "\n"
88
+ puts "Destination: #{region.destinations[destination_index].name}, Region: #{region.name}"
89
+ puts "\n"
90
+ puts "Summary: #{region.destinations[destination_index].description}"
91
+ select_destination(region_index)
92
+ else
93
+ puts "\n"
94
+ puts "Please input a valid command."
95
+ select_destination(region_index)
96
+ end #end if statement
97
+ end #end method
69
98
 
70
99
  def goodbye
71
100
  puts "\n"
@@ -80,6 +109,7 @@ class TopTravelDestinations::CLI
80
109
  _/____/
81
110
 
82
111
  DOC
112
+ puts " Information from TripAdvisor"
83
113
  end
84
114
 
85
115
  end
@@ -0,0 +1,23 @@
1
+ class TopTravelDestinations::Destination
2
+
3
+ #creates "belongs to" relationship to instance of Region
4
+ attr_accessor :name, :region, :description
5
+
6
+ @@all = []
7
+
8
+ def initialize(destination_hash)
9
+ self.create_attributes_from_hash(destination_hash)
10
+ self.class.all << self
11
+ end
12
+
13
+ def create_attributes_from_hash(destination_hash)
14
+ destination_hash.each do |key, value|
15
+ self.send(("#{key}="), value)
16
+ end
17
+ end
18
+
19
+ def self.all
20
+ @@all
21
+ end
22
+
23
+ end
@@ -11,8 +11,8 @@ class TopTravelDestinations::Region
11
11
  self.class.all << self
12
12
  end
13
13
 
14
- def self.create_from_array(region_array)
15
- region_array.each do |region_hash|
14
+ def self.create_from_array(regions_array)
15
+ regions_array.each do |region_hash|
16
16
  TopTravelDestinations::Region.new(region_hash)
17
17
  end
18
18
  end
@@ -31,18 +31,57 @@ class TopTravelDestinations::Region
31
31
  @@all
32
32
  end
33
33
 
34
+ def self.get_regions
35
+ TopTravelDestinations::Scraper.scrape_regions_array
36
+ end
37
+
34
38
  def get_destinations
39
+ destinations_array = self.scrape_destinations_array
40
+ self.add_destinations(destinations_array)
41
+ end
42
+
43
+ def scrape_destinations_array
35
44
  html = open(self.region_url)
36
45
  doc = Nokogiri::HTML(html)
37
-
38
- doc.search("div.winnerName div.mainName a").collect do |destination|
39
- name = destination.text
40
- self.destinations << name
41
- end#end iterator
46
+
47
+ destinations_array = []
48
+
49
+ doc.css("div#WINNERVIEWER").children.each do |destination|
50
+ name = destination.search("div.mainName a").text
51
+ description = destination.search("div.descr_lb").text
52
+
53
+ if name != "" && description !=""
54
+ destinations_array << {
55
+ :name => name,
56
+ :description => description}
57
+ end
58
+ end #end iterator
59
+ destinations_array
60
+ end #end method
61
+
62
+ #creates "has many" relationship to instance of Region
63
+ def add_destinations(destinations_array)
64
+ destinations_array.each do |destination_hash|
65
+ destination = TopTravelDestinations::Destination.new(destination_hash)
66
+ self.destinations << destination
67
+ destination.region = self
68
+ end
42
69
  end
43
70
 
44
- def self.get_regions
45
- TopTravelDestinations::Scraper.scrape_regions_array
71
+ def destination_names
72
+ destinations_names_array = []
73
+ self.destinations.each do |destination|
74
+ destinations_names_array << destination.name
75
+ end
76
+ destinations_names_array
77
+ end
78
+
79
+ def destination_descriptions
80
+ destinations_descriptions_array = []
81
+ self.destinations.each do |destination|
82
+ destinations_descriptions_array << destination.description
83
+ end
84
+ destinations_descriptions_array
46
85
  end
47
86
 
48
87
  end
@@ -5,17 +5,17 @@ class TopTravelDestinations::Scraper
5
5
  html = open(index_url)
6
6
  doc = Nokogiri::HTML(html)
7
7
 
8
- region_array = []
8
+ regions_array = []
9
9
 
10
- doc.search("#tcRegions .tocContainer a").collect do |regionnode|
10
+ doc.search("div.cont a").collect do |regionnode|
11
11
  name = regionnode.text
12
12
  sub_url = regionnode.attribute("href").value
13
- region_array << {
13
+ regions_array << {
14
14
  :name => name,
15
15
  :region_url => "https://www.tripadvisor.com#{sub_url}"
16
16
  }
17
17
  end #end iterator
18
- region_array
18
+ regions_array
19
19
  end #end method
20
20
 
21
21
  end #end Class
@@ -1,3 +1,3 @@
1
1
  module TopTravelDestinations
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: top-travel-destinations-cli-gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antonio David
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-18 00:00:00.000000000 Z
11
+ date: 2016-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -99,12 +99,13 @@ files:
99
99
  - bin/top-travel-destinations
100
100
  - config/environment.rb
101
101
  - lib/top_travel_destinations/cli.rb
102
+ - lib/top_travel_destinations/destination.rb
102
103
  - lib/top_travel_destinations/region.rb
103
104
  - lib/top_travel_destinations/scraper.rb
104
105
  - lib/top_travel_destinations/version.rb
105
- - pkg/top-travel-destinations-cli-gem-1.2.0.gem
106
106
  - top-travel-destinations-cli-gem-1.0.0.gem
107
107
  - top-travel-destinations-cli-gem-1.1.0.gem
108
+ - top-travel-destinations-cli-gem-1.2.0.gem
108
109
  - top_travel_destinations.gemspec
109
110
  homepage: https://github.com/agdavid/top-travel-destinations-cli-gem
110
111
  licenses: