what_a_world 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/NOTES.md +71 -0
- data/README.md +45 -0
- data/Rakefile +6 -0
- data/bin/console +11 -0
- data/bin/setup +7 -0
- data/bin/what-a-world +7 -0
- data/lib/.DS_Store +0 -0
- data/lib/what_a_world/cli.rb +147 -0
- data/lib/what_a_world/country.rb +21 -0
- data/lib/what_a_world/issues.rb +22 -0
- data/lib/what_a_world/scraper.rb +131 -0
- data/lib/what_a_world/version.rb +3 -0
- data/lib/what_a_world.rb +10 -0
- data/spec.md +7 -0
- data/what-a-world-cli-gem.gemspec +41 -0
- metadata +137 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9dfb9c52e2cfa0684595cdae320557266d649bfc
|
4
|
+
data.tar.gz: dcbfe7e70af52fea12ea5e3c75f54fee4a58765d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ed7a2b99309782d25d93abd88df5703682f92f6e1a3fa8f5cf446f7ab1285556b1e65c64dbc80f7a554c0c3c7d7b925421aba6f29e1c523feb7b472f98c259ab
|
7
|
+
data.tar.gz: f0410b1e3e69446432458fa6bfef31ff779aebd16ef0fdf4526126092a327e67401e66f673e9ae4a320da8c09af73ecb8d2522359ed904a8cd69959fbe0a35a7
|
data/.DS_Store
ADDED
Binary file
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at gregbenj@hotmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 gb23
|
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/NOTES.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
CLI
|
2
|
+
-ScraperCLI
|
3
|
+
-Country
|
4
|
+
-ScraperCountry
|
5
|
+
-Issues
|
6
|
+
-ScraperIssues
|
7
|
+
|
8
|
+
|
9
|
+
class CLIScraper
|
10
|
+
get_countries_by_letter
|
11
|
+
=> countries_by_letter []
|
12
|
+
|
13
|
+
create_country_by_number
|
14
|
+
=> countryObj
|
15
|
+
|
16
|
+
class Country
|
17
|
+
def intialize
|
18
|
+
instantiate ScraperCountry
|
19
|
+
instantiate TransnationalIssues
|
20
|
+
attr name, last updated, region
|
21
|
+
|
22
|
+
|
23
|
+
class TransnationalIssues
|
24
|
+
attr :regugee :drug :etc
|
25
|
+
def initialize
|
26
|
+
instantiate ScraperTrIssues
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
CLI CLASS
|
34
|
+
welcomes user
|
35
|
+
[
|
36
|
+
Asks user to select country by choosing a letter
|
37
|
+
*instantiate SCRAPERCLI obj to get countries of that letter
|
38
|
+
Lists countries found array from letter, enumerated
|
39
|
+
Asks user to select corresponding number
|
40
|
+
*instantiates country obj with name from number
|
41
|
+
COUNTRY CLASS
|
42
|
+
set name attr
|
43
|
+
instantiate SCRAPERCOUNTRY to get lastupdated, region
|
44
|
+
set lastupdated, region
|
45
|
+
*instantiate TransnationalIssues
|
46
|
+
TRANSNATIONAL ISSUES
|
47
|
+
instantiate SCRAPERTI to get :refugee, :crime etc
|
48
|
+
set refugee, crime, etc
|
49
|
+
return transnational issues obj
|
50
|
+
add transnationalissues obj to country object
|
51
|
+
return country obj
|
52
|
+
Display country and issues from data in country obj
|
53
|
+
Ask to continue or exit
|
54
|
+
]
|
55
|
+
Goodbye!
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# WhatAWorld
|
2
|
+
|
3
|
+
Welcome to `What a World!` gem. Exploring the world is always an adventure. This gem provides C.I.A. data on transnational issues from various locations arould the planet. Locations are first searched by first letter, and then are chosen from an enumerated, alphabetized list. Caution: Results may be shocking. The idea behind this gem is to present the user with troubling issues with the intent of raising awareness of global issues. Hopefully, you will learn something new!
|
4
|
+
|
5
|
+
Peace to the planet.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'what_a_world'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install what_a_world
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
1. Select a location by its first letter. That is, type in any letter A through Z and press return
|
26
|
+
2. An enumerated list will appear on the screen. Type in a number corresponding to the location listed and press return
|
27
|
+
3. Data will display on screen
|
28
|
+
4. To continue exploring, type 'yes' when prompted about continuing. To stop exploring, type 'no' and press return.
|
29
|
+
|
30
|
+
## Development
|
31
|
+
|
32
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
33
|
+
|
34
|
+
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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
35
|
+
|
36
|
+
## Contributing
|
37
|
+
|
38
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/gb23/what_a_world. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
39
|
+
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
44
|
+
|
45
|
+
# what-a-world--cli-gem
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/bin/what-a-world
ADDED
data/lib/.DS_Store
ADDED
Binary file
|
@@ -0,0 +1,147 @@
|
|
1
|
+
class WhatAWorld::CLI
|
2
|
+
def call
|
3
|
+
welcome
|
4
|
+
again = true
|
5
|
+
while again
|
6
|
+
letter = select_letter
|
7
|
+
if letter != "X"
|
8
|
+
scraper = WhatAWorld::Scraper::ScraperCli.new(letter)
|
9
|
+
scraper.find_all_countries
|
10
|
+
scraper.find_countries_by_letter
|
11
|
+
letter_countries = scraper.letter_countries
|
12
|
+
letter_url_extensions = scraper.letter_url_extensions
|
13
|
+
|
14
|
+
country_hash = get_country(letter_countries, letter_url_extensions)
|
15
|
+
country = WhatAWorld::Country.new(country_hash)
|
16
|
+
country.scrape
|
17
|
+
|
18
|
+
country.get_issues
|
19
|
+
|
20
|
+
print_results(country)
|
21
|
+
else
|
22
|
+
puts "No locations start with 'X'!".colorize(:red)
|
23
|
+
end
|
24
|
+
again = again?
|
25
|
+
end
|
26
|
+
goodbye
|
27
|
+
end
|
28
|
+
|
29
|
+
def welcome
|
30
|
+
puts "What A World!"
|
31
|
+
sleep(1.0)
|
32
|
+
puts "Explore transnational issues on a location-by-location basis."
|
33
|
+
sleep(1.0)
|
34
|
+
puts "Information provided by the C.I.A."
|
35
|
+
end
|
36
|
+
|
37
|
+
def goodbye
|
38
|
+
puts ""
|
39
|
+
puts "Goodbye, and" + " peace".colorize(:blue) + " to the " + "world!".colorize(:green)
|
40
|
+
puts ""
|
41
|
+
end
|
42
|
+
|
43
|
+
def select_letter
|
44
|
+
letter = nil
|
45
|
+
puts ""
|
46
|
+
while !(/\A[A-Z]\z/.match(letter))
|
47
|
+
sleep(0.5)
|
48
|
+
puts "Select a location by typing its first letter, A to Z".colorize(:red)
|
49
|
+
print ":"
|
50
|
+
letter = gets.strip.upcase
|
51
|
+
end
|
52
|
+
puts ""
|
53
|
+
letter
|
54
|
+
end
|
55
|
+
|
56
|
+
def whole?(number)
|
57
|
+
regex = /\A[1-9][0-9]*\z/
|
58
|
+
regex.match(number)
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_country(letter_countries, letter_url_extensions)
|
62
|
+
country_hash = {}
|
63
|
+
index = 0
|
64
|
+
letter_countries.each{|country|
|
65
|
+
index += 1
|
66
|
+
puts "#{index}. #{country}"
|
67
|
+
}
|
68
|
+
|
69
|
+
number = ""
|
70
|
+
puts ""
|
71
|
+
loop do
|
72
|
+
puts "Choose a country by number".colorize(:red)
|
73
|
+
print ":"
|
74
|
+
number = gets.strip
|
75
|
+
break if (number.to_i.between?(1, index) && whole?(number))
|
76
|
+
end
|
77
|
+
|
78
|
+
puts ""
|
79
|
+
country_hash[letter_countries[number.to_i - 1]] = letter_url_extensions[number.to_i - 1]
|
80
|
+
country_hash
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
def print_results(country)
|
86
|
+
name = country.name
|
87
|
+
last_updated = country.last_updated
|
88
|
+
region = country.region
|
89
|
+
trafficking_label = country.issues.trafficking_hash.keys.join
|
90
|
+
trafficking = country.issues.trafficking_hash.values.join
|
91
|
+
drugs_label = country.issues.drugs_hash.keys.join
|
92
|
+
drugs = country.issues.drugs_hash.values.join
|
93
|
+
refugees_label = country.issues.refugees_hash.keys.join
|
94
|
+
refugees = country.issues.refugees_hash.values.join
|
95
|
+
disputes_label = country.issues.disputes_hash.keys.join
|
96
|
+
disputes = country.issues.disputes_hash.values.join
|
97
|
+
|
98
|
+
puts "##################################".colorize(:blue)
|
99
|
+
puts "#{name.upcase}".colorize(:light_blue)
|
100
|
+
puts "Region: #{region}".colorize(:light_blue)
|
101
|
+
puts "##################################".colorize(:blue)
|
102
|
+
puts "#{last_updated}"
|
103
|
+
if !trafficking.empty?
|
104
|
+
puts "__________________________________"
|
105
|
+
puts "#{trafficking_label}".colorize(:red)
|
106
|
+
puts trafficking
|
107
|
+
end
|
108
|
+
if !drugs.empty?
|
109
|
+
puts "__________________________________"
|
110
|
+
puts "#{drugs_label}".colorize(:red)
|
111
|
+
puts drugs
|
112
|
+
end
|
113
|
+
if !refugees.empty?
|
114
|
+
puts "__________________________________"
|
115
|
+
puts "#{refugees_label}".colorize(:red)
|
116
|
+
puts refugees
|
117
|
+
end
|
118
|
+
if !disputes.empty?
|
119
|
+
puts "__________________________________"
|
120
|
+
puts "#{disputes_label}".colorize(:red)
|
121
|
+
puts disputes
|
122
|
+
end
|
123
|
+
if disputes.empty? && refugees.empty? && drugs.empty? && trafficking.empty?
|
124
|
+
puts "__________________________________"
|
125
|
+
puts "Sorry, unable to locate information.".colorize(:red)
|
126
|
+
puts "Please try a different country."
|
127
|
+
end
|
128
|
+
puts "__________________________________"
|
129
|
+
end
|
130
|
+
|
131
|
+
def again?
|
132
|
+
repeat = true
|
133
|
+
puts ""
|
134
|
+
while repeat
|
135
|
+
puts "Would you like to search for other data?".colorize(:red)
|
136
|
+
puts "Type 'yes' or 'no'"
|
137
|
+
print ":"
|
138
|
+
input = gets.strip.to_s.upcase
|
139
|
+
if input != "YES" && input != "NO" && input != "Y" && input != "N"
|
140
|
+
repeat = true
|
141
|
+
else
|
142
|
+
repeat = false
|
143
|
+
end
|
144
|
+
end
|
145
|
+
input == "YES" || input == "Y" ? true : false
|
146
|
+
end
|
147
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class WhatAWorld::Country
|
2
|
+
attr_accessor :last_updated, :region, :issues
|
3
|
+
attr_reader :name, :url_extension
|
4
|
+
def initialize(hash)
|
5
|
+
@name = hash.keys.join
|
6
|
+
@url_extension = hash.values.join
|
7
|
+
end
|
8
|
+
|
9
|
+
def scrape
|
10
|
+
scraper = WhatAWorld::Scraper::ScraperCountry.new(self.url_extension)
|
11
|
+
|
12
|
+
self.last_updated = scraper.find_date
|
13
|
+
self.region = scraper.find_region
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
def get_issues
|
18
|
+
self.issues = WhatAWorld::Issues.new(self.url_extension)
|
19
|
+
self.issues.scrape
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class WhatAWorld::Issues
|
2
|
+
attr_accessor :trafficking_hash, :drugs_hash, :refugees_hash, :disputes_hash
|
3
|
+
attr_reader :url_extension
|
4
|
+
def initialize(url_extension)
|
5
|
+
@url_extension = url_extension
|
6
|
+
@trafficking_hash = {}
|
7
|
+
@drugs_hash = {}
|
8
|
+
@refugees_hash = {}
|
9
|
+
@disputes_hash = {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def scrape
|
13
|
+
scraper = WhatAWorld::Scraper::ScraperIssues.new(self.url_extension)
|
14
|
+
scraper.scrape_issues
|
15
|
+
self.trafficking_hash = scraper.trafficking_hash
|
16
|
+
self.drugs_hash = scraper.drugs_hash
|
17
|
+
self.refugees_hash = scraper.refugees_hash
|
18
|
+
self.disputes_hash = scraper.disputes_hash
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
|
@@ -0,0 +1,131 @@
|
|
1
|
+
class WhatAWorld::Scraper
|
2
|
+
URL = "https://www.cia.gov/library/publications/the-world-factbook/"
|
3
|
+
class ScraperCli
|
4
|
+
attr_accessor :all_countries, :all_url_extensions
|
5
|
+
attr_reader :letter, :letter_countries,:letter_url_extensions
|
6
|
+
|
7
|
+
def initialize(letter)
|
8
|
+
@letter = letter
|
9
|
+
@all_countries = []
|
10
|
+
@all_url_extensions = []
|
11
|
+
@letter_countries = []
|
12
|
+
@letter_url_extensions = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def find_all_countries
|
16
|
+
html = open(URL)
|
17
|
+
all_countries_page = Nokogiri::HTML(html)
|
18
|
+
country_names = ""
|
19
|
+
country_names = all_countries_page.css(".selecter_links option[value^='geos']").text.strip
|
20
|
+
self.all_countries = country_names.split(" ")
|
21
|
+
self.all_url_extensions = all_countries_page.css(".selecter_links option").collect{ |link|
|
22
|
+
link.attr('value') unless link.attr('value') === ""
|
23
|
+
}
|
24
|
+
self.all_url_extensions.reject!{|url| url.nil?}
|
25
|
+
end
|
26
|
+
|
27
|
+
def find_countries_by_letter
|
28
|
+
indices = []
|
29
|
+
self.all_countries.each.with_index{ |country, index|
|
30
|
+
if country[0] == self.letter && country.gsub(" ", "") != "EuropeanUnion"
|
31
|
+
indices << index
|
32
|
+
self.letter_countries << country
|
33
|
+
end
|
34
|
+
}
|
35
|
+
iterator = indices.first
|
36
|
+
while iterator <= indices.last
|
37
|
+
self.letter_url_extensions << self.all_url_extensions[iterator]
|
38
|
+
iterator += 1
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class ScraperCountry
|
44
|
+
attr_accessor :country_page
|
45
|
+
attr_writer :region
|
46
|
+
def initialize(url_extension)
|
47
|
+
country_url = URL + url_extension
|
48
|
+
html = open(country_url)
|
49
|
+
@country_page = Nokogiri::HTML(html)
|
50
|
+
end
|
51
|
+
|
52
|
+
def find_date
|
53
|
+
self.country_page.css("div.lastMod").text.strip
|
54
|
+
end
|
55
|
+
def find_region
|
56
|
+
str = self.country_page.css("div.region1.geos_title").text.strip
|
57
|
+
self.region = str.split(" ")[0]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class ScraperIssues
|
62
|
+
@@disputes = "Disputes - international:"
|
63
|
+
@@refugees = "Refugees and internally displaced persons:"
|
64
|
+
@@trafficking = "Trafficking in persons:"
|
65
|
+
@@drugs = "Illicit drugs:"
|
66
|
+
attr_accessor :country_page, :trafficking_hash, :disputes_hash, :drugs_hash, :refugees_hash
|
67
|
+
attr_reader :disputes_content, :refugees_content, :trafficking_content, :drugs_content
|
68
|
+
def initialize(url_extension)
|
69
|
+
@disputes_content = []
|
70
|
+
@refugees_content = []
|
71
|
+
@trafficking_content = []
|
72
|
+
@drugs_content = []
|
73
|
+
@trafficking_hash = {}
|
74
|
+
@disputes_hash = {}
|
75
|
+
@drugs_hash = {}
|
76
|
+
@refugees_hash = {}
|
77
|
+
country_url = URL + modify_extension(url_extension)
|
78
|
+
html = open(country_url)
|
79
|
+
@country_page = Nokogiri::HTML(html)
|
80
|
+
end
|
81
|
+
|
82
|
+
def modify_extension(url_extension)
|
83
|
+
mod_extension = url_extension.split("/")
|
84
|
+
mod_extension = mod_extension.insert(1, "/")
|
85
|
+
mod_extension = mod_extension.insert(2, "print_")
|
86
|
+
mod_extension = mod_extension.join
|
87
|
+
end
|
88
|
+
|
89
|
+
def create_string(iterator)
|
90
|
+
"//ul[last()]/li[last()]/div[" + iterator.to_s + "]"
|
91
|
+
end
|
92
|
+
|
93
|
+
def scraped_string(iterator)
|
94
|
+
@country_page.xpath(create_string(iterator)).text.strip
|
95
|
+
end
|
96
|
+
|
97
|
+
def scrape_issues
|
98
|
+
iterator = 1
|
99
|
+
scraped_string(iterator)
|
100
|
+
unfamiliar_setup = false
|
101
|
+
while scraped_string(iterator) != "" && !unfamiliar_setup
|
102
|
+
if @@disputes == scraped_string(iterator)
|
103
|
+
iterator = add_content(iterator, self.disputes_content)
|
104
|
+
elsif @@refugees == scraped_string(iterator)
|
105
|
+
iterator = add_content(iterator, self.refugees_content)
|
106
|
+
elsif @@trafficking == scraped_string(iterator)
|
107
|
+
iterator = add_content(iterator, self.trafficking_content)
|
108
|
+
elsif @@drugs == scraped_string(iterator)
|
109
|
+
iterator = add_content(iterator, self.drugs_content)
|
110
|
+
else
|
111
|
+
unfamiliar_setup = true
|
112
|
+
end
|
113
|
+
end
|
114
|
+
self.disputes_hash[@@disputes] = self.disputes_content
|
115
|
+
self.refugees_hash[@@refugees] = self.refugees_content
|
116
|
+
self.trafficking_hash[@@trafficking] = self.trafficking_content
|
117
|
+
self.drugs_hash[@@drugs] = self.drugs_content
|
118
|
+
end
|
119
|
+
|
120
|
+
def add_content(iterator, content)
|
121
|
+
iterator +=1
|
122
|
+
scraped = scraped_string(iterator)
|
123
|
+
while scraped != @@disputes && scraped != @@refugees && scraped != @@trafficking && scraped != @@drugs && scraped != ""
|
124
|
+
content << scraped
|
125
|
+
iterator +=1
|
126
|
+
scraped = scraped_string(iterator)
|
127
|
+
end
|
128
|
+
iterator
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
data/lib/what_a_world.rb
ADDED
data/spec.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'what_a_world/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "what_a_world"
|
8
|
+
spec.version = WhatAWorld::VERSION
|
9
|
+
spec.author = ["Greg B"]
|
10
|
+
spec.authors = ["gb23"]
|
11
|
+
spec.email = ["gregbenj@hotmail.com"]
|
12
|
+
spec.files = ["lib/what_a_world.rb"]
|
13
|
+
spec.summary = %q{What a world! Displays transnational issues by country}
|
14
|
+
spec.description = %q{What a world! Choose a country to learn about various transnational issues that hinder global progress, as recognized by the CIA }
|
15
|
+
spec.homepage = "https://github.com/gb23/what-a-world-cli-gem/"
|
16
|
+
spec.license = "MIT"
|
17
|
+
spec.require_paths = ["lib" "lib/what_a_world"]
|
18
|
+
spec.platform = Gem::Platform::RUBY
|
19
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
20
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
21
|
+
# if spec.respond_to?(:metadata)
|
22
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
23
|
+
# else
|
24
|
+
# raise "RubyGems 2.0 or newer is required to protect against " \
|
25
|
+
# "public gem pushes."
|
26
|
+
# end
|
27
|
+
|
28
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
29
|
+
f.match(%r{^(test|spec|features)/})
|
30
|
+
end
|
31
|
+
spec.bindir = "exe"
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
38
|
+
|
39
|
+
spec.add_dependency 'nokogiri'
|
40
|
+
spec.add_dependency 'require_all'
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: what_a_world
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- gb23
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-12 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.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
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: require_all
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: 'What a world! Choose a country to learn about various transnational
|
84
|
+
issues that hinder global progress, as recognized by the CIA '
|
85
|
+
email:
|
86
|
+
- gregbenj@hotmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".DS_Store"
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rspec"
|
94
|
+
- ".travis.yml"
|
95
|
+
- CODE_OF_CONDUCT.md
|
96
|
+
- Gemfile
|
97
|
+
- LICENSE.txt
|
98
|
+
- NOTES.md
|
99
|
+
- README.md
|
100
|
+
- Rakefile
|
101
|
+
- bin/console
|
102
|
+
- bin/setup
|
103
|
+
- bin/what-a-world
|
104
|
+
- lib/.DS_Store
|
105
|
+
- lib/what_a_world.rb
|
106
|
+
- lib/what_a_world/cli.rb
|
107
|
+
- lib/what_a_world/country.rb
|
108
|
+
- lib/what_a_world/issues.rb
|
109
|
+
- lib/what_a_world/scraper.rb
|
110
|
+
- lib/what_a_world/version.rb
|
111
|
+
- spec.md
|
112
|
+
- what-a-world-cli-gem.gemspec
|
113
|
+
homepage: https://github.com/gb23/what-a-world-cli-gem/
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
metadata: {}
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 2.6.12
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: What a world! Displays transnational issues by country
|
137
|
+
test_files: []
|