UNESCO_World_Heritage_Sites 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aa33705b055d141fdefd07cfa0fccacb3c592f19
4
+ data.tar.gz: ae261906bf5bd227e367239b110be2cc3f1e39fc
5
+ SHA512:
6
+ metadata.gz: bb00b375080c4a692df1bdb01e286bc1678584368e0ce2053b0ae4a2dcd17c9f3335a4a52fae04dbb090808a9bd51f08cec325f1628af5144e1b237c26422d5e
7
+ data.tar.gz: 45239fe50042ddb11fd2901448b950cbabed9da52d2d76edd961e89d7439146841bb25e1463766e1ebb7add716d98a034cec45b8b9c0be5371db1d08d56b4dcf
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in UNESCO_World_Heritage_Sites.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 matthewpaulmcgowan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # UNESCOWorldHeritageSites
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/UNESCO_World_Heritage_Sites`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'UNESCO_World_Heritage_Sites'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install UNESCO_World_Heritage_Sites
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/UNESCO_World_Heritage_Sites/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'UNESCO_World_Heritage_Sites/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "UNESCO_World_Heritage_Sites"
8
+ spec.version = UNESCOWorldHeritageSites::VERSION
9
+ spec.authors = ["Matthew McGowan"]
10
+ spec.email = ["matthewpaulmcgowan@gmail.com"]
11
+
12
+ spec.summary = %q{A CLI to search through UNESCO World Heritage Sites}
13
+ spec.description = %q{Scrapes many pages throughout the whc.unesco.org website, organizes sites by country and allows the user to select which site they would like to learn more about.}
14
+ spec.homepage = "https://github.com/matthewpaulmcgowan/UNESCO_World_Heritage_Sites_CLI_Data_Gem"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.8"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "pry"
25
+
26
+ spec.add_dependency "nokogiri"
27
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "UNESCO_World_Heritage_Sites"
5
+
6
+ UNESCOWorldHeritageSites::CLI.new.call
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "UNESCO_World_Heritage_Sites"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,12 @@
1
+ require 'pry'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+ require_relative "./UNESCO_World_Heritage_Sites/version"
6
+ require_relative "./UNESCO_World_Heritage_Sites/cli"
7
+ require_relative "./UNESCO_World_Heritage_Sites/scraper"
8
+ require_relative "./UNESCO_World_Heritage_Sites/countries"
9
+ require_relative "./UNESCO_World_Heritage_Sites/sites"
10
+ require_relative "./UNESCO_World_Heritage_Sites/user_favorites"
11
+ module UNESCOWorldHeritageSites
12
+ end
@@ -0,0 +1,111 @@
1
+ class UNESCOWorldHeritageSites::CLI
2
+ attr_accessor :input, :chosen_country, :site
3
+
4
+ def call
5
+ introduction
6
+ call_country
7
+ end
8
+
9
+ def introduction
10
+ puts "Hello, we are learning about UNESCO World Heritage Sites!"
11
+ puts "UNESCO, began their list of heritage sites in 1978 and now counts over 1100 from over 160 countries."
12
+ puts "The heritage sites are listed by country so please select the id of a country to begin to learn!"
13
+ end
14
+
15
+ def call_country
16
+ UNESCOWorldHeritageSites::Countries.clear
17
+ UNESCOWorldHeritageSites::Sites.clear
18
+ UNESCOWorldHeritageSites::Scraper.scrape_main_page
19
+ UNESCOWorldHeritageSites::Countries.print_countries
20
+ puts ""
21
+ puts "Please select the id of the country you would like to search about"
22
+ @input=gets.strip
23
+ puts ""
24
+ response_checker(UNESCOWorldHeritageSites::Countries.number_of_countries)
25
+ @chosen_country=UNESCOWorldHeritageSites::Countries.find_country(@input)
26
+ @chosen_country.country_specific_sites
27
+ printing_sites
28
+ end
29
+
30
+ def printing_sites
31
+ puts "These are the heritage sites of #{@chosen_country.name}."
32
+ UNESCOWorldHeritageSites::Sites.print_all_sites
33
+ puts ""
34
+ puts "Which site would you like to learn more about?"
35
+ @input=gets.strip
36
+ puts ""
37
+ response_checker(UNESCOWorldHeritageSites::Sites.number_of_sites)
38
+ @site=UNESCOWorldHeritageSites::Sites.find_site(@input)
39
+ @site.print_site_data
40
+ puts ""
41
+ puts "Would you like to add this site to your favorites?"
42
+ puts "Please enter 1 for yes or 2 for no."
43
+ @input=gets.strip
44
+ response_checker(2)
45
+ add_to_favorites
46
+ puts ""
47
+ puts "Enter the number of the option you would like from the list below."
48
+ puts "1: to look at the same country's heritage sites"
49
+ puts "2: to pick a new country"
50
+ puts "3: to print your favorite heritage sites"
51
+ puts "4: to exit"
52
+ @input=gets.strip
53
+ puts ""
54
+ response_checker(4)
55
+ if @input=="1"
56
+ printing_sites
57
+ elsif @input=="2"
58
+ call_country
59
+ elsif @input=="3"
60
+ UNESCOWorldHeritageSites::User_Favorites.print_favorites
61
+ puts ""
62
+ what_is_next_move
63
+ else
64
+ goodbye
65
+ abort
66
+ end
67
+ end
68
+
69
+ def response_checker(high_limit)
70
+ if !(@input.to_i>0)||!(@input.to_i<=high_limit)
71
+ puts "Please enter a valid response."
72
+ @input=gets.strip
73
+ puts ""
74
+ response_checker(high_limit)
75
+ end
76
+ end
77
+
78
+ def add_to_favorites
79
+ if @input=="1"
80
+ UNESCOWorldHeritageSites::User_Favorites.save(@site)
81
+ end
82
+ end
83
+
84
+ def what_is_next_move
85
+ puts "Enter the number of the option you would like from the list below."
86
+ puts "1: to look at the same country's heritage sites"
87
+ puts "2: to pick a new country"
88
+ puts "3: to exit"
89
+ @input=gets.strip
90
+ puts ""
91
+ response_checker(3)
92
+ if @input=="1"
93
+ printing_sites
94
+ elsif @input=="2"
95
+ call_country
96
+ else
97
+ goodbye
98
+ abort
99
+ end
100
+ end
101
+
102
+ def goodbye
103
+ puts "I hope you enjoyed yourself and learned something new!"
104
+ puts "All of this information was found throughout the whc.unesco.org website!"
105
+ puts "Have a swell day!"
106
+ end
107
+ end
108
+ #could have it so the user could enter something and a random number would be chosen, I think it would be easy to implement,
109
+ #but i'm not sure how to have the user select because right now all of the user input is number based, it can't be 0 because
110
+ #all letters are transformed to 0 in the valididity check, i could have it be one greater than the largest number in the series,
111
+ #but I don't really love that idea, so right now I will leave it out
@@ -0,0 +1,70 @@
1
+ class UNESCOWorldHeritageSites::Countries
2
+ attr_accessor :id, :name, :url, :sites, :doc
3
+
4
+ @@all=[]
5
+
6
+ def initialize(id,name,url)
7
+ @id=id
8
+ @name=name
9
+ @url=url
10
+ end
11
+
12
+ def save
13
+ @@all << self
14
+ end
15
+
16
+ def self.create_from_index(id,name,url)
17
+ new_country=UNESCOWorldHeritageSites::Countries.new(id,name,url)
18
+ new_country.save
19
+ new_country
20
+ end
21
+
22
+ def scrape_countrys
23
+ @doc=Nokogiri::HTML(open(self.url))
24
+ end
25
+
26
+ def country_specific_sites
27
+ scrape_countrys
28
+ @sites=[]
29
+ descriptors_array=[".cultural_danger>a",".cultural>a",".natural>a",".natural_danger>a",".mixed>a"]
30
+ descriptors_array.each do |descriptor|
31
+ @doc.css(descriptor).each do |site|
32
+ name=site.text
33
+ url="http://whc.unesco.org#{site.attr("href")}"
34
+ @sites << [name,url]
35
+ end
36
+ end
37
+ create_sites #not sure if I should call the create_sites method here or to call it alone in the CLI method
38
+ end
39
+
40
+ def create_sites
41
+ @sites.each_with_index do |site,i|
42
+ id=i+1
43
+ country=self.name
44
+ name=site[0]
45
+ url=site[1]
46
+ UNESCOWorldHeritageSites::Sites.create_from_country(id,country,name,url)
47
+ end
48
+ return
49
+ end
50
+
51
+ def self.find_country(id)
52
+ @@all.detect do |country|
53
+ country.id==id.to_i
54
+ end
55
+ end
56
+
57
+ def self.print_countries
58
+ @@all.each do |country|
59
+ puts "#{country.id}. #{country.name}"
60
+ end
61
+ end
62
+
63
+ def self.number_of_countries
64
+ @@all.length
65
+ end
66
+
67
+ def self.clear
68
+ @@all=[]
69
+ end
70
+ end
@@ -0,0 +1,13 @@
1
+ class UNESCOWorldHeritageSites::Scraper
2
+ def self.scrape_main_page
3
+ doc=Nokogiri::HTML(open("http://whc.unesco.org/en/list"))
4
+ doc.css("#acc>h4>a").each_with_index do |country,i|
5
+ name=country.text
6
+ url="http://whc.unesco.org#{country.attr("href")}"
7
+ index=i+1
8
+ UNESCOWorldHeritageSites::Countries.create_from_index(index,name,url)
9
+ end
10
+ end
11
+ end
12
+
13
+
@@ -0,0 +1,55 @@
1
+ class UNESCOWorldHeritageSites::Sites
2
+ attr_accessor :id,:country, :name, :url, :doc
3
+
4
+ @@all=[]
5
+
6
+ def initialize(id,country,name,url)
7
+ @id=id
8
+ @country=country
9
+ @name=name
10
+ @url=url
11
+ end
12
+
13
+ def save
14
+ @@all << self
15
+ end
16
+
17
+ def self.create_from_country(id,country,name,url)
18
+ new_site=UNESCOWorldHeritageSites::Sites.new(id,country,name,url)
19
+ new_site.save
20
+ new_site
21
+ end
22
+
23
+ def self.print_all_sites
24
+ @@all.each do |site|
25
+ puts "#{site.id}. #{site.name}"
26
+ end
27
+ end
28
+
29
+ def self.find_site(input_id)
30
+ @@all.detect do |site|
31
+ site.id==input_id.to_i
32
+ end
33
+ end
34
+
35
+ def scrape_sites
36
+ @doc=Nokogiri::HTML(open(url))
37
+ end
38
+
39
+ def print_site_data
40
+ scrape_sites
41
+ overview=@doc.css("#contentdes_en>p").text
42
+ puts self.name
43
+ puts self.country
44
+ puts overview
45
+ puts self.url
46
+ end
47
+
48
+ def self.number_of_sites
49
+ @@all.length
50
+ end
51
+
52
+ def self.clear
53
+ @@all=[]
54
+ end
55
+ end
@@ -0,0 +1,19 @@
1
+ class UNESCOWorldHeritageSites::User_Favorites
2
+
3
+ @@all=[]
4
+
5
+ def self.save(site)
6
+ @@all << site
7
+ end
8
+
9
+ def self.print_favorites
10
+ puts "List of favorites!"
11
+ @@all.each_with_index do |site,i|
12
+ puts "#{i+1}. #{site.name}, #{site.country}"
13
+ end
14
+ end
15
+
16
+ def self.clear_favorites #this is not yet implemented, not sure when is a good time and I am already asking so many questions, don't want to constancly be asking if they want to clear favorites
17
+ @@all=[]
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module UNESCOWorldHeritageSites
2
+ VERSION = "0.1.1"
3
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: UNESCO_World_Heritage_Sites
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthew McGowan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-01-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Scrapes many pages throughout the whc.unesco.org website, organizes sites
70
+ by country and allows the user to select which site they would like to learn more
71
+ about.
72
+ email:
73
+ - matthewpaulmcgowan@gmail.com
74
+ executables: []
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - UNESCO_World_Heritage_Sites.gemspec
85
+ - bin/UNESCO_World_Heritage_Sites
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/UNESCO_World_Heritage_Sites.rb
89
+ - lib/UNESCO_World_Heritage_Sites/cli.rb
90
+ - lib/UNESCO_World_Heritage_Sites/countries.rb
91
+ - lib/UNESCO_World_Heritage_Sites/scraper.rb
92
+ - lib/UNESCO_World_Heritage_Sites/sites.rb
93
+ - lib/UNESCO_World_Heritage_Sites/user_favorites.rb
94
+ - lib/UNESCO_World_Heritage_Sites/version.rb
95
+ homepage: https://github.com/matthewpaulmcgowan/UNESCO_World_Heritage_Sites_CLI_Data_Gem
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.4.6
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: A CLI to search through UNESCO World Heritage Sites
119
+ test_files: []