worldfactbook 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +18 -0
- data/Gemfile.lock +33 -0
- data/README.rdoc +71 -0
- data/Rakefile +57 -0
- data/TODO +7 -0
- data/VERSION +1 -0
- data/bin/worldfactbook +10 -0
- data/lib/worldfactbook.rb +12 -0
- data/lib/worldfactbook/cli.rb +66 -0
- data/lib/worldfactbook/country.rb +384 -0
- data/lib/worldfactbook/country_code.rb +241 -0
- metadata +177 -0
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "rspec", "~> 2.3.0"
|
12
|
+
gem "bundler", "~> 1.0.0"
|
13
|
+
gem "jeweler", "~> 1.6.3"
|
14
|
+
gem 'rake', '0.8.7'
|
15
|
+
gem 'nokogiri'
|
16
|
+
gem 'fakeweb'
|
17
|
+
gem "rcov", ">= 0"
|
18
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
fakeweb (1.3.0)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.6.4)
|
8
|
+
bundler (~> 1.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
nokogiri (1.5.0)
|
12
|
+
rake (0.8.7)
|
13
|
+
rcov (0.9.9)
|
14
|
+
rspec (2.3.0)
|
15
|
+
rspec-core (~> 2.3.0)
|
16
|
+
rspec-expectations (~> 2.3.0)
|
17
|
+
rspec-mocks (~> 2.3.0)
|
18
|
+
rspec-core (2.3.1)
|
19
|
+
rspec-expectations (2.3.0)
|
20
|
+
diff-lcs (~> 1.1.2)
|
21
|
+
rspec-mocks (2.3.0)
|
22
|
+
|
23
|
+
PLATFORMS
|
24
|
+
ruby
|
25
|
+
|
26
|
+
DEPENDENCIES
|
27
|
+
bundler (~> 1.0.0)
|
28
|
+
fakeweb
|
29
|
+
jeweler (~> 1.6.3)
|
30
|
+
nokogiri
|
31
|
+
rake (= 0.8.7)
|
32
|
+
rcov
|
33
|
+
rspec (~> 2.3.0)
|
data/README.rdoc
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
= Worldfactbook
|
2
|
+
|
3
|
+
Worldfactbook fetches data on countries for you from the {CIA World Factbook}[https://www.cia.gov/library/publications/the-world-factbook/index.html].
|
4
|
+
|
5
|
+
$ sudo gem install worldfactbook
|
6
|
+
|
7
|
+
= Usage
|
8
|
+
|
9
|
+
Please see the complete Worldfactbook documentation {on the wiki}[http://github.com/sayem/worldfactbook/wiki].
|
10
|
+
|
11
|
+
Library usage:
|
12
|
+
|
13
|
+
require 'worldfactbook'
|
14
|
+
w = Worldfactbook::Country.new('united states') OR w = Worldfactbook::Country.new('us')
|
15
|
+
|
16
|
+
w.population => "313,232,044 (July 2011 est.) country comparison to the world: 3"
|
17
|
+
|
18
|
+
w.gdp => "$14.66 trillion (2010 est.)"
|
19
|
+
|
20
|
+
w.major_cities => "New York-Newark 19.3 million; Los Angeles-Long Beach-Santa Ana 12.675 million;
|
21
|
+
Chicago 9.134 million; Miami 5.699 million; WASHINGTON, D.C. (capital) 4.421
|
22
|
+
million (2009)"
|
23
|
+
|
24
|
+
w.internet_users => "245 million (2009) country comparison to the world: 2"
|
25
|
+
|
26
|
+
Command line usage:
|
27
|
+
|
28
|
+
$ worldfactbook japan => returns the location, major cities, population, GDP, unemployment rate, and more for Japan
|
29
|
+
|
30
|
+
$ worldfactbook canada population => "34,030,589 (July 2011 est.) country comparison to the world: 37"
|
31
|
+
|
32
|
+
$ worldfactbook help => lists all the command line options
|
33
|
+
|
34
|
+
$ worldfactbook countries => lists all the countries available along with their two-letter country codes
|
35
|
+
|
36
|
+
== Contributing to Worldfactbook
|
37
|
+
|
38
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
39
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
40
|
+
* Fork the project
|
41
|
+
* Start a feature/bugfix branch
|
42
|
+
* Commit and push until you are happy with your contribution
|
43
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
44
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
45
|
+
|
46
|
+
== LICENSE
|
47
|
+
|
48
|
+
(The MIT License)
|
49
|
+
|
50
|
+
Copyright © 2011:
|
51
|
+
|
52
|
+
{Sayem Islam}[http://sayemislam.com]
|
53
|
+
|
54
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
55
|
+
a copy of this software and associated documentation files (the
|
56
|
+
‘Software’), to deal in the Software without restriction, including
|
57
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
58
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
59
|
+
permit persons to whom the Software is furnished to do so, subject to
|
60
|
+
the following conditions:
|
61
|
+
|
62
|
+
The above copyright notice and this permission notice shall be
|
63
|
+
included in all copies or substantial portions of the Software.
|
64
|
+
|
65
|
+
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND,
|
66
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
67
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
68
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
69
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
70
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
71
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.files = FileList['lib/**/*.rb', 'bin/*', '[A-Z]*', 'test/**/*'].to_a
|
18
|
+
gem.executables = ['worldfactbook']
|
19
|
+
gem.name = "worldfactbook"
|
20
|
+
gem.homepage = "http://github.com/sayem/worldfactbook"
|
21
|
+
gem.license = "MIT"
|
22
|
+
gem.summary = %Q{Easily access all the statistics and economic data available on the CIA World Factbook.}
|
23
|
+
gem.description = %Q{Easily use Ruby or the command line to look up any country on the CIA World Factbook.}
|
24
|
+
gem.email = "sayem.islam@gmail.com"
|
25
|
+
gem.authors = ["Sayem Islam"]
|
26
|
+
|
27
|
+
# Dependencies
|
28
|
+
gem.add_dependency('nokogiri')
|
29
|
+
|
30
|
+
# Development dependencies
|
31
|
+
gem.add_development_dependency('fakeweb')
|
32
|
+
gem.add_development_dependency('rspec')
|
33
|
+
end
|
34
|
+
Jeweler::RubygemsDotOrgTasks.new
|
35
|
+
|
36
|
+
require 'rspec/core'
|
37
|
+
require 'rspec/core/rake_task'
|
38
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
39
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
40
|
+
end
|
41
|
+
|
42
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
43
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
44
|
+
spec.rcov = true
|
45
|
+
end
|
46
|
+
|
47
|
+
task :default => :spec
|
48
|
+
|
49
|
+
require 'rake/rdoctask'
|
50
|
+
Rake::RDocTask.new do |rdoc|
|
51
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
52
|
+
|
53
|
+
rdoc.rdoc_dir = 'rdoc'
|
54
|
+
rdoc.title = "worldfactbook #{version}"
|
55
|
+
rdoc.rdoc_files.include('README*')
|
56
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
57
|
+
end
|
data/TODO
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/bin/worldfactbook
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__)) unless $LOAD_PATH.include?(File.dirname(__FILE__))
|
2
|
+
|
3
|
+
require 'open-uri'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'nokogiri'
|
6
|
+
|
7
|
+
require 'worldfactbook/country'
|
8
|
+
require 'worldfactbook/country_code'
|
9
|
+
|
10
|
+
module Worldfactbook
|
11
|
+
VERSION = File.open(File.join(File.dirname(__FILE__), '..', 'VERSION'), 'r') { |f| f.read.strip }
|
12
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Worldfactbook
|
2
|
+
class CLI
|
3
|
+
def self.execute(stdout, arguments=[])
|
4
|
+
@stdout = stdout
|
5
|
+
if !arguments.empty?
|
6
|
+
query = arguments.join(" ").strip
|
7
|
+
if !['help', 'countries'].include?(query)
|
8
|
+
begin
|
9
|
+
@country = query
|
10
|
+
Country.new(query)
|
11
|
+
rescue Worldfactbook::NoCountryAvailable
|
12
|
+
@data = arguments.pop
|
13
|
+
query = arguments.join(" ").strip
|
14
|
+
@country = query
|
15
|
+
Country.new(query)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
@stdout.puts "Worldfactbook | https://github.com/sayem/worldfactbook"
|
21
|
+
@stdout.puts
|
22
|
+
|
23
|
+
if arguments[0] == 'help'
|
24
|
+
@stdout.puts "'worldfactbook countries' => lists all the countries available in the CIA World Factbook, along with their two-letter country codes"
|
25
|
+
@stdout.puts
|
26
|
+
@stdout.puts "'worldfactbook [country or code]' => fetches the location, major cities, date of independence, population, languages, ethnic groups, religions, age structure, literacy rate, GDP, GDP (PPP), GDP growth, GDP sectors, debt, unemployment, inflation, telephone users, mobile phone users, and internet users for the given country"
|
27
|
+
@stdout.puts
|
28
|
+
@stdout.puts "'worldfactbook [country or code] [parameter]' => returns information from the given method for the country (e.g. 'worldfactbook united states population')"
|
29
|
+
@stdout.puts
|
30
|
+
@stdout.puts "List of available country methods can be found at: https://github.com/sayem/worldfactbook/wiki"
|
31
|
+
@stdout.puts
|
32
|
+
elsif arguments[0] == 'countries'
|
33
|
+
@stdout.puts "List of available countries (input 'worldfactbook [country or code]' to fetch data for that country):"
|
34
|
+
@stdout.puts
|
35
|
+
@stdout.puts CountryCode.new('xx').list
|
36
|
+
elsif @data
|
37
|
+
@stdout.puts Country.new(@country).send(@data)
|
38
|
+
@stdout.puts
|
39
|
+
elsif @country
|
40
|
+
@stdout.puts "Location: #{Country.new(@country).location}"
|
41
|
+
@stdout.puts "Major Cities: #{Country.new(@country).major_cities}"
|
42
|
+
@stdout.puts "Independence: #{Country.new(@country).independence}"
|
43
|
+
@stdout.puts
|
44
|
+
@stdout.puts "Population: #{Country.new(@country).population}"
|
45
|
+
@stdout.puts "Languages: #{Country.new(@country).languages}"
|
46
|
+
@stdout.puts "Ethnic Groups: #{Country.new(@country).ethnic_groups}"
|
47
|
+
@stdout.puts "Religions: #{Country.new(@country).religions}"
|
48
|
+
@stdout.puts "Age Structure: #{Country.new(@country).age_structure}"
|
49
|
+
@stdout.puts "Literacy: #{Country.new(@country).literacy}"
|
50
|
+
@stdout.puts
|
51
|
+
@stdout.puts "GDP: #{Country.new(@country).gdp}"
|
52
|
+
@stdout.puts "GDP (PPP): #{Country.new(@country).gdp_ppp}"
|
53
|
+
@stdout.puts "GDP growth: #{Country.new(@country).gdp_growth}"
|
54
|
+
@stdout.puts "GDP sectors: #{Country.new(@country).gdp_sectors}"
|
55
|
+
@stdout.puts "Debt: #{Country.new(@country).debt}"
|
56
|
+
@stdout.puts "Unemployment: #{Country.new(@country).unemployment}"
|
57
|
+
@stdout.puts "Inflation: #{Country.new(@country).inflation}"
|
58
|
+
@stdout.puts
|
59
|
+
@stdout.puts "Telephone Users: #{Country.new(@country).telephones}"
|
60
|
+
@stdout.puts "Mobile Phone Users: #{Country.new(@country).cellphones}"
|
61
|
+
@stdout.puts "Internet Users: #{Country.new(@country).internet_users}"
|
62
|
+
@stdout.puts
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,384 @@
|
|
1
|
+
module Worldfactbook
|
2
|
+
class Country
|
3
|
+
attr_accessor :country
|
4
|
+
|
5
|
+
def initialize(country)
|
6
|
+
@country = country.downcase
|
7
|
+
@code = CountryCode.new(@country).code
|
8
|
+
end
|
9
|
+
|
10
|
+
def countries
|
11
|
+
CountryCode.new(@country).list
|
12
|
+
end
|
13
|
+
|
14
|
+
def flag
|
15
|
+
doc.css('.flag_border').to_s.gsub(/\.\.\/graphics/,'http://rubyworldfactbook.com/graphics').gsub(/"/,'').scan(/http\S+/)[0]
|
16
|
+
end
|
17
|
+
|
18
|
+
def map_location
|
19
|
+
doc.css('#region-content td tr:nth-child(2) td:nth-child(2) img:nth-child(1)').to_s.gsub(/\.\.\/graphics/,'http://rubyworldfactbook.com/graphics').gsub(/"/,'').scan(/http\S+/)[0]
|
20
|
+
end
|
21
|
+
|
22
|
+
def map_world
|
23
|
+
return "http://rubyworldfactbook.com/graphics/maps/newmaps/#{@code}-map.gif"
|
24
|
+
end
|
25
|
+
|
26
|
+
def intro
|
27
|
+
doc.css('#CollapsiblePanel1_Intro #data .category_data').text
|
28
|
+
end
|
29
|
+
|
30
|
+
def geography
|
31
|
+
return { 'location' => self.location, 'area' => self.area, 'area_comparative' => self.area_comparative, 'climate' => self.climate, 'terrain' => self.terrain, 'elevation' => self.elevation, 'natural_resources' => self.natural_resources }
|
32
|
+
end
|
33
|
+
|
34
|
+
def people
|
35
|
+
return { 'population' => self.population, 'population_growth' => self.population_growth, 'ethnic_groups' => self.ethnic_groups, 'religions' => self.religions, 'languages' => self.languages, 'sex_ratio' => self.sex_ratio, 'age_structure' => self.age_structure, 'median_age' => self.median_age, 'birth_rate' => self.birth_rate, 'death_rate' => self.death_rate, 'net_migration' => self.net_migration, 'urbanization' => self.urbanization, 'major_cities' => self.major_cities, 'infant_mortality' => self.infant_mortality, 'life_expectancy' => self.life_expectancy, 'fertility_rate' => self.fertility_rate, 'literacy' => self.literacy }
|
36
|
+
end
|
37
|
+
|
38
|
+
def government
|
39
|
+
return { 'government_type' => government_type, 'capital' => self.capital, 'independence' => self.independence, 'legal' => self.legal, 'executive' => self.executive, 'legislative' => self.legislative, 'judicial' => self.judicial, 'political' => self.political }
|
40
|
+
end
|
41
|
+
|
42
|
+
def economy
|
43
|
+
return { 'gdp' => self.gdp, 'gdp_ppp' => self.gdp_ppp, 'gdp_growth' => self.gdp_growth, 'gdp_capita' => self.gdp_capita, 'gdp_sectors' => self.gdp_sectors, 'labor' => self.labor, 'unemployment' => self.unemployment, 'inflation' => self.inflation, 'markets' => self.markets, 'exports' => self.exports, 'imports' => self.imports, 'debt' => self.debt, 'military' => self.military }
|
44
|
+
|
45
|
+
# economy_overview not included
|
46
|
+
end
|
47
|
+
|
48
|
+
def communications
|
49
|
+
return { 'telephones' => self.telephones, 'cellphones' => self.cellphones, 'internet_users' => self.internet_users, 'internet_hosts' => self.internet_hosts }
|
50
|
+
end
|
51
|
+
|
52
|
+
def global
|
53
|
+
return { 'disputes' => self.disputes, 'refugees' => self.refugees, 'drugs' => self.drugs }
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
## GEOGRAPHY ##
|
58
|
+
|
59
|
+
def location
|
60
|
+
doc.css('#CollapsiblePanel1_Geo tr:nth-child(2) .category_data').text
|
61
|
+
end
|
62
|
+
|
63
|
+
def area
|
64
|
+
doc.css('#CollapsiblePanel1_Geo tr:nth-child(11) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
65
|
+
end
|
66
|
+
|
67
|
+
def area_comparative
|
68
|
+
doc.css('#CollapsiblePanel1_Geo tr:nth-child(14) .category_data').text
|
69
|
+
end
|
70
|
+
|
71
|
+
def climate
|
72
|
+
doc.css('#CollapsiblePanel1_Geo tr:nth-child(26) .category_data').text
|
73
|
+
end
|
74
|
+
|
75
|
+
def terrain
|
76
|
+
doc.css('#CollapsiblePanel1_Geo tr:nth-child(29) .category_data').text
|
77
|
+
end
|
78
|
+
|
79
|
+
def elevation
|
80
|
+
doc.css('#CollapsiblePanel1_Geo tr:nth-child(32) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
81
|
+
end
|
82
|
+
|
83
|
+
def natural_resources
|
84
|
+
doc.css('#CollapsiblePanel1_Geo tr:nth-child(35) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
## PEOPLE ##
|
89
|
+
|
90
|
+
def population
|
91
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(2) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
92
|
+
end
|
93
|
+
|
94
|
+
def age_structure
|
95
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(5) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
96
|
+
end
|
97
|
+
|
98
|
+
def median_age
|
99
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(8) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
100
|
+
end
|
101
|
+
|
102
|
+
def population_growth
|
103
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(11) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
104
|
+
end
|
105
|
+
|
106
|
+
def birth_rate
|
107
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(14) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
108
|
+
end
|
109
|
+
|
110
|
+
def death_rate
|
111
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(17) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
112
|
+
end
|
113
|
+
|
114
|
+
def net_migration
|
115
|
+
if ['xx'].include?(@code)
|
116
|
+
return nil
|
117
|
+
else
|
118
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(20) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def urbanization
|
123
|
+
if ['ee'].include?(@code)
|
124
|
+
return nil
|
125
|
+
elsif ['xx'].include?(@code)
|
126
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(20) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
127
|
+
else
|
128
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(23) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def major_cities
|
133
|
+
if ['ee', 'xx'].include?(@code)
|
134
|
+
return nil
|
135
|
+
else
|
136
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(26) .category_data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def sex_ratio
|
141
|
+
if ['ee', 'xx'].include?(@code)
|
142
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(23) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
143
|
+
else
|
144
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(29) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def infant_mortality
|
149
|
+
if ['ee', 'xx'].include?(@code)
|
150
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(26) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
151
|
+
else
|
152
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(32) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def life_expectancy
|
157
|
+
if ['ee', 'xx'].include?(@code)
|
158
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(29) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
159
|
+
else
|
160
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(35) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def fertility_rate
|
165
|
+
if ['ee', 'xx'].include?(@code)
|
166
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(32) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
167
|
+
else
|
168
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(38) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def ethnic_groups
|
173
|
+
if doc.to_s.match("Definitions and Notes: Major infectious diseases")
|
174
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(62) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
175
|
+
elsif ['ee', 'xx'].include?(@code)
|
176
|
+
return nil
|
177
|
+
else
|
178
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(59) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def religions
|
183
|
+
if doc.to_s.match("Definitions and Notes: Major infectious diseases")
|
184
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(65) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
185
|
+
elsif ['xx'].include?(@code)
|
186
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(50) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
187
|
+
elsif ['ee'].include?(@code)
|
188
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(44) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
189
|
+
else
|
190
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(62) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def languages
|
195
|
+
if doc.to_s.match("Definitions and Notes: Major infectious diseases")
|
196
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(68) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
197
|
+
elsif ['xx'].include?(@code)
|
198
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(53) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
199
|
+
elsif ['ee'].include?(@code)
|
200
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(47) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
201
|
+
else
|
202
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(65) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def literacy
|
207
|
+
if doc.to_s.match("Definitions and Notes: Major infectious diseases")
|
208
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(71) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
209
|
+
elsif ['xx'].include?(@code)
|
210
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(56) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
211
|
+
elsif ['ee'].include?(@code)
|
212
|
+
return nil
|
213
|
+
else
|
214
|
+
doc.css('#CollapsiblePanel1_People tr:nth-child(68) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
|
219
|
+
## GOVERNMENT ##
|
220
|
+
|
221
|
+
def government_type
|
222
|
+
doc.css('#CollapsiblePanel1_Govt tr:nth-child(5) .category_data').text
|
223
|
+
end
|
224
|
+
|
225
|
+
def capital
|
226
|
+
doc.css('#CollapsiblePanel1_Govt tr:nth-child(8) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
227
|
+
end
|
228
|
+
|
229
|
+
def independence
|
230
|
+
if doc.to_s.match("Definitions and Notes: Dependent areas")
|
231
|
+
doc.css('#CollapsiblePanel1_Govt tr:nth-child(17) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
|
232
|
+
else
|
233
|
+
doc.css('#CollapsiblePanel1_Govt tr:nth-child(14) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
def legal
|
238
|
+
if doc.to_s.match("Definitions and Notes: Dependent areas")
|
239
|
+
doc.css('#CollapsiblePanel1_Govt tr:nth-child(26) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
|
240
|
+
else
|
241
|
+
doc.css('#CollapsiblePanel1_Govt tr:nth-child(23) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
def executive
|
246
|
+
if doc.to_s.match("Definitions and Notes: Dependent areas")
|
247
|
+
doc.css('#CollapsiblePanel1_Govt tr:nth-child(35) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
|
248
|
+
else
|
249
|
+
doc.css('#CollapsiblePanel1_Govt tr:nth-child(32) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
def legislative
|
254
|
+
if doc.to_s.match("Definitions and Notes: Dependent areas")
|
255
|
+
doc.css('#CollapsiblePanel1_Govt tr:nth-child(38) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
|
256
|
+
else
|
257
|
+
doc.css('#CollapsiblePanel1_Govt tr:nth-child(35) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
def judicial
|
262
|
+
if doc.to_s.match("Definitions and Notes: Dependent areas")
|
263
|
+
doc.css('#CollapsiblePanel1_Govt tr:nth-child(41) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
|
264
|
+
else
|
265
|
+
doc.css('#CollapsiblePanel1_Govt tr:nth-child(38) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
def political
|
270
|
+
if doc.to_s.match("Definitions and Notes: Dependent areas")
|
271
|
+
doc.css('#CollapsiblePanel1_Govt tr:nth-child(44) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
|
272
|
+
else
|
273
|
+
doc.css('#CollapsiblePanel1_Govt tr:nth-child(41) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').strip
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
|
278
|
+
## ECONOMY ##
|
279
|
+
|
280
|
+
def economy_overview
|
281
|
+
doc.css('#CollapsiblePanel1_Econ tr:nth-child(2) .category_data').text
|
282
|
+
end
|
283
|
+
|
284
|
+
def gdp
|
285
|
+
doc.css('#CollapsiblePanel1_Econ tr:nth-child(8) .category_data').text
|
286
|
+
end
|
287
|
+
|
288
|
+
def gdp_ppp
|
289
|
+
doc.css('#CollapsiblePanel1_Econ tr:nth-child(5) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
290
|
+
end
|
291
|
+
|
292
|
+
def gdp_growth
|
293
|
+
doc.css('#CollapsiblePanel1_Econ tr:nth-child(11) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
294
|
+
end
|
295
|
+
|
296
|
+
def gdp_capita
|
297
|
+
doc.css('#CollapsiblePanel1_Econ tr:nth-child(14) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
298
|
+
end
|
299
|
+
|
300
|
+
def gdp_sectors
|
301
|
+
doc.css('#CollapsiblePanel1_Econ tr:nth-child(17) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
302
|
+
end
|
303
|
+
|
304
|
+
def labor
|
305
|
+
doc.css('#CollapsiblePanel1_Econ tr:nth-child(20) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
306
|
+
end
|
307
|
+
|
308
|
+
def unemployment
|
309
|
+
doc.css('#CollapsiblePanel1_Econ tr:nth-child(26) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
310
|
+
end
|
311
|
+
|
312
|
+
def inflation
|
313
|
+
doc.css('#CollapsiblePanel1_Econ tr:nth-child(47) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
314
|
+
end
|
315
|
+
|
316
|
+
def markets
|
317
|
+
doc.css('#CollapsiblePanel1_Econ tr:nth-child(65) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
318
|
+
end
|
319
|
+
|
320
|
+
def exports
|
321
|
+
doc.css('#CollapsiblePanel1_Econ tr:nth-child(122) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
322
|
+
end
|
323
|
+
|
324
|
+
def imports
|
325
|
+
doc.css('#CollapsiblePanel1_Econ tr:nth-child(131) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
326
|
+
end
|
327
|
+
|
328
|
+
def debt
|
329
|
+
doc.css('#CollapsiblePanel1_Econ tr:nth-child(143) #data').text.squeeze(' ').gsub(/ \n \n /,'; ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
330
|
+
end
|
331
|
+
|
332
|
+
def military
|
333
|
+
doc.css('#CollapsiblePanel1_Military tr:nth-child(17) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
334
|
+
end
|
335
|
+
|
336
|
+
|
337
|
+
## COMMUNICATIONS ##
|
338
|
+
|
339
|
+
def telephones
|
340
|
+
doc.css('#CollapsiblePanel1_Comm tr:nth-child(2) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
341
|
+
end
|
342
|
+
|
343
|
+
def cellphones
|
344
|
+
doc.css('#CollapsiblePanel1_Comm tr:nth-child(5) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
345
|
+
end
|
346
|
+
|
347
|
+
def internet_users
|
348
|
+
if @code == 'xx'
|
349
|
+
doc.css('#CollapsiblePanel1_Comm tr:nth-child(11) .category_data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
350
|
+
elsif @code == 'ee'
|
351
|
+
doc.css('#CollapsiblePanel1_Comm tr:nth-child(17) .category_data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
352
|
+
else
|
353
|
+
doc.css('#CollapsiblePanel1_Comm tr:nth-child(20) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
def internet_hosts
|
358
|
+
doc.css('#CollapsiblePanel1_Comm tr:nth-child(17) #data').text.squeeze(' ').gsub(/[\r\t\n]/,'').squeeze(' ').strip
|
359
|
+
end
|
360
|
+
|
361
|
+
|
362
|
+
## GLOBAL ISSUES ##
|
363
|
+
|
364
|
+
def disputes
|
365
|
+
doc.css('#CollapsiblePanel1_Issues tr:nth-child(2) .category_data').text
|
366
|
+
end
|
367
|
+
|
368
|
+
def refugees
|
369
|
+
doc.css('#CollapsiblePanel1_Issues tr:nth-child(5) .category_data').text
|
370
|
+
end
|
371
|
+
|
372
|
+
def drugs
|
373
|
+
doc.css('#CollapsiblePanel1_Issues tr:nth-child(8) .category_data').text
|
374
|
+
end
|
375
|
+
|
376
|
+
|
377
|
+
private
|
378
|
+
|
379
|
+
def doc
|
380
|
+
@document ||= Nokogiri::HTML(open("http://rubyworldfactbook.com/geos/#{@code}.html"))
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
end
|
@@ -0,0 +1,241 @@
|
|
1
|
+
module Worldfactbook
|
2
|
+
class NoCountryAvailable < StandardError; end
|
3
|
+
|
4
|
+
class CountryCode
|
5
|
+
attr_accessor :country
|
6
|
+
|
7
|
+
def initialize(country)
|
8
|
+
@country = country
|
9
|
+
@codes = { 'world' => 'xx',
|
10
|
+
'afghanistan' => 'af',
|
11
|
+
'albania' => 'al',
|
12
|
+
'algeria' => 'ag',
|
13
|
+
'andorra' => 'an',
|
14
|
+
'angola' => 'ao',
|
15
|
+
'antarctica' => 'ay',
|
16
|
+
'antigua' => 'ac',
|
17
|
+
'barbuda' => 'ac',
|
18
|
+
'antigua and barbuda' => 'ac',
|
19
|
+
'argentina' => 'ar',
|
20
|
+
'algeria' => 'ag',
|
21
|
+
'armenia' => 'am',
|
22
|
+
'algeria' => 'ag',
|
23
|
+
'australia' => 'as',
|
24
|
+
'austria' => 'au',
|
25
|
+
'azerbaijan' => 'aj',
|
26
|
+
'bahamas' => 'bf',
|
27
|
+
'the bahamas' => 'bf',
|
28
|
+
'bahrain' => 'ba',
|
29
|
+
'bangladesh' => 'bg',
|
30
|
+
'barbados' => 'bb',
|
31
|
+
'belarus' => 'bo',
|
32
|
+
'belgium' => 'be',
|
33
|
+
'belize' => 'bh',
|
34
|
+
'benin' => 'bn',
|
35
|
+
'bermuda' => 'bd',
|
36
|
+
'bhutan' => 'bt',
|
37
|
+
'bolivia' => 'bl',
|
38
|
+
'bosnia' => 'bk',
|
39
|
+
'herzegovina' => 'bk',
|
40
|
+
'bosnia and herzegovina' => 'bk',
|
41
|
+
'botswana' => 'bc',
|
42
|
+
'brazil' => 'br',
|
43
|
+
'brunei' => 'bx',
|
44
|
+
'bulgaria' => 'bu',
|
45
|
+
'burkina faso' => 'uv',
|
46
|
+
'burma' => 'bm',
|
47
|
+
'burundi' => 'by',
|
48
|
+
'cambodia' => 'cb',
|
49
|
+
'cameroon' => 'cm',
|
50
|
+
'canada' => 'ca',
|
51
|
+
'cape verde' => 'cv',
|
52
|
+
'central african republic' => 'ct',
|
53
|
+
'chad' => 'cd',
|
54
|
+
'chile' => 'ci',
|
55
|
+
'china' => 'ch',
|
56
|
+
'colombia' => 'co',
|
57
|
+
'comoros' => 'cn',
|
58
|
+
'democratic republic of the congo' => 'cg',
|
59
|
+
'republic of the congo' => 'cf',
|
60
|
+
'costa rica' => 'cs',
|
61
|
+
"cote d'ivoire" => 'iv',
|
62
|
+
'croatia' => 'hr',
|
63
|
+
'cuba' => 'cu',
|
64
|
+
'cyprus' => 'cy',
|
65
|
+
'czech republic' => 'ez',
|
66
|
+
'denmark' => 'da',
|
67
|
+
'djibouti' => 'dj',
|
68
|
+
'dominica' => 'do',
|
69
|
+
'dominican republic' => 'dr',
|
70
|
+
'ecuador' => 'ec',
|
71
|
+
'egypt' => 'eg',
|
72
|
+
'el salvador' => 'es',
|
73
|
+
'equatorial guinea' => 'ek',
|
74
|
+
'eritrea' => 'er',
|
75
|
+
'estonia' => 'en',
|
76
|
+
'ethiopia' => 'et',
|
77
|
+
'fiji' => 'fj',
|
78
|
+
'finland' => 'fi',
|
79
|
+
'france' => 'fr',
|
80
|
+
'gabon' => 'gb',
|
81
|
+
'the gambia' => 'gb',
|
82
|
+
'gaza strip' => 'gz',
|
83
|
+
'georgia' => 'gg',
|
84
|
+
'germany' => 'gm',
|
85
|
+
'ghana' => 'gh',
|
86
|
+
'greece' => 'gr',
|
87
|
+
'greenland' => 'gl',
|
88
|
+
'grenada' => 'gj',
|
89
|
+
'guatemala' => 'gt',
|
90
|
+
'guinea' => 'gv',
|
91
|
+
'guinea-bissau' => 'pu',
|
92
|
+
'guyana' => 'gy',
|
93
|
+
'haiti' => 'ha',
|
94
|
+
'honduras' => 'ho',
|
95
|
+
'hong kong' => 'hk',
|
96
|
+
'hungary' => 'hu',
|
97
|
+
'iceland' => 'ic',
|
98
|
+
'india' => 'in',
|
99
|
+
'iran' => 'ir',
|
100
|
+
'iraq' => 'iz',
|
101
|
+
'ireland' => 'ei',
|
102
|
+
'israel' => 'is',
|
103
|
+
'italy' => 'it',
|
104
|
+
'jamaica' => 'jm',
|
105
|
+
'japan' => 'ja',
|
106
|
+
'jordan' => 'jo',
|
107
|
+
'kazakhstan' => 'kz',
|
108
|
+
'kenya' => 'ke',
|
109
|
+
'kiribati' => 'kr',
|
110
|
+
'north korea' => 'kn',
|
111
|
+
'south korea' => 'ks',
|
112
|
+
'kosovo' => 'kv',
|
113
|
+
'kuwait' => 'ku',
|
114
|
+
'kyrgyzstan' => 'kg',
|
115
|
+
'laos' => 'la',
|
116
|
+
'latvia' => 'lg',
|
117
|
+
'lebanon' => 'le',
|
118
|
+
'lesotho' => 'lt',
|
119
|
+
'liberia' => 'li',
|
120
|
+
'libya' => 'ly',
|
121
|
+
'liechtenstein' => 'ls',
|
122
|
+
'lithuania' => 'lh',
|
123
|
+
'luxembourg' => 'lu',
|
124
|
+
'macedonia' => 'mk',
|
125
|
+
'madagascar' => 'ma',
|
126
|
+
'malawi' => 'mi',
|
127
|
+
'malaysia' => 'my',
|
128
|
+
'maldives' => 'mv',
|
129
|
+
'mali' => 'ml',
|
130
|
+
'malta' => 'mt',
|
131
|
+
'marshall islands' => 'rm',
|
132
|
+
'mauritania' => 'mr',
|
133
|
+
'mauritius' => 'mp',
|
134
|
+
'mexico' => 'mx',
|
135
|
+
'micronesia' => 'fm',
|
136
|
+
'moldova' => 'md',
|
137
|
+
'monaco' => 'mn',
|
138
|
+
'mongolia' => 'mg',
|
139
|
+
'montenegro' => 'mj',
|
140
|
+
'morocco' => 'mo',
|
141
|
+
'moldova' => 'md',
|
142
|
+
'mozambique' => 'mz',
|
143
|
+
'nambia' => 'wa',
|
144
|
+
'nauru' => 'nr',
|
145
|
+
'nepal' => 'np',
|
146
|
+
'netherlands' => 'nl',
|
147
|
+
'new zealand' => 'nz',
|
148
|
+
'nicaragua' => 'nu',
|
149
|
+
'niger' => 'ng',
|
150
|
+
'nigeria' => 'ni',
|
151
|
+
'norway' => 'no',
|
152
|
+
'oman' => 'mu',
|
153
|
+
'pakistan' => 'pk',
|
154
|
+
'palau' => 'ps',
|
155
|
+
'panama' => 'pm',
|
156
|
+
'papua new guinea' => 'pp',
|
157
|
+
'paraguay' => 'pa',
|
158
|
+
'peru' => 'pe',
|
159
|
+
'philippines' => 'rp',
|
160
|
+
'poland' => 'pl',
|
161
|
+
'portugal' => 'po',
|
162
|
+
'puerto rico' => 'rq',
|
163
|
+
'qatar' => 'qa',
|
164
|
+
'romania' => 'ro',
|
165
|
+
'russia' => 'rs',
|
166
|
+
'rwanda' => 'rw',
|
167
|
+
'saint kitts and nevis' => 'sc',
|
168
|
+
'saint lucia' => 'st',
|
169
|
+
'saint vincent' => 'vc',
|
170
|
+
'the grenadines' => 'vc',
|
171
|
+
'saint vincent and the grenadines' => 'vc',
|
172
|
+
'samoa' => 'ws',
|
173
|
+
'san marino' => 'sm',
|
174
|
+
'sao tome' => 'tp',
|
175
|
+
'principe' => 'tp',
|
176
|
+
'sao tome and principe' => 'tp',
|
177
|
+
'saudi arabia' => 'sa',
|
178
|
+
'senegal' => 'sg',
|
179
|
+
'serbia' => 'ri',
|
180
|
+
'seychelles' => 'se',
|
181
|
+
'sierra leone' => 'sl',
|
182
|
+
'singapore' => 'sn',
|
183
|
+
'slovakia' => 'lo',
|
184
|
+
'slovenia' => 'si',
|
185
|
+
'solomon islands' => 'bp',
|
186
|
+
'somalia' => 'so',
|
187
|
+
'south africa' => 'sf',
|
188
|
+
'spain' => 'sp',
|
189
|
+
'sri lanka' => 'ce',
|
190
|
+
'sudan' => 'su',
|
191
|
+
'suriname' => 'ns',
|
192
|
+
'swaziland' => 'wz',
|
193
|
+
'sweden' => 'sw',
|
194
|
+
'switzerland' => 'sz',
|
195
|
+
'syria' => 'sy',
|
196
|
+
'taiwan' => 'tw',
|
197
|
+
'tajikistan' => 'ti',
|
198
|
+
'tanzania' => 'tz',
|
199
|
+
'thailand' => 'th',
|
200
|
+
'timor-leste' => 'tt',
|
201
|
+
'togo' => 'to',
|
202
|
+
'tonga' => 'tn',
|
203
|
+
'trinidad' => 'td',
|
204
|
+
'tobago' => 'td',
|
205
|
+
'tunisia' => 'ts',
|
206
|
+
'turkey' => 'tu',
|
207
|
+
'turkmenistan' => 'tx',
|
208
|
+
'tuvalu' => 'tv',
|
209
|
+
'uganda' => 'ug',
|
210
|
+
'ukraine' => 'up',
|
211
|
+
'united arab emirates' => 'ae',
|
212
|
+
'united kingdom' => 'uk',
|
213
|
+
'united states' => 'us',
|
214
|
+
'uruguay' => 'uy',
|
215
|
+
'uzbekistan' => 'uz',
|
216
|
+
'vanuatu' => 'nh',
|
217
|
+
'venezuela' => 've',
|
218
|
+
'vietnam' => 'vm',
|
219
|
+
'west bank' => 'we',
|
220
|
+
'yemen' => 'ym',
|
221
|
+
'zambia' => 'za',
|
222
|
+
'zimbabwe' => 'zi',
|
223
|
+
'european union' => 'ee' }
|
224
|
+
end
|
225
|
+
|
226
|
+
def code
|
227
|
+
if @codes.has_key?(@country)
|
228
|
+
@codes.fetch(@country)
|
229
|
+
elsif @codes.has_value?(@country)
|
230
|
+
return @country
|
231
|
+
else
|
232
|
+
raise NoCountryAvailable.new("#{@country} isn't available in the CIA World Factbook.")
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def list
|
237
|
+
return @codes
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
end
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: worldfactbook
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sayem Islam
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-07-14 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.3.0
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: bundler
|
28
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: jeweler
|
39
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 1.6.3
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rake
|
50
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - "="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.8.7
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: nokogiri
|
61
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *id005
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: fakeweb
|
72
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: "0"
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: *id006
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: rcov
|
83
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: "0"
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: *id007
|
92
|
+
- !ruby/object:Gem::Dependency
|
93
|
+
name: nokogiri
|
94
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: "0"
|
100
|
+
type: :runtime
|
101
|
+
prerelease: false
|
102
|
+
version_requirements: *id008
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: fakeweb
|
105
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: "0"
|
111
|
+
type: :development
|
112
|
+
prerelease: false
|
113
|
+
version_requirements: *id009
|
114
|
+
- !ruby/object:Gem::Dependency
|
115
|
+
name: rspec
|
116
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: "0"
|
122
|
+
type: :development
|
123
|
+
prerelease: false
|
124
|
+
version_requirements: *id010
|
125
|
+
description: Easily use Ruby or the command line to look up any country on the CIA World Factbook.
|
126
|
+
email: sayem.islam@gmail.com
|
127
|
+
executables:
|
128
|
+
- worldfactbook
|
129
|
+
extensions: []
|
130
|
+
|
131
|
+
extra_rdoc_files:
|
132
|
+
- README.rdoc
|
133
|
+
- TODO
|
134
|
+
files:
|
135
|
+
- Gemfile
|
136
|
+
- Gemfile.lock
|
137
|
+
- README.rdoc
|
138
|
+
- Rakefile
|
139
|
+
- TODO
|
140
|
+
- VERSION
|
141
|
+
- bin/worldfactbook
|
142
|
+
- lib/worldfactbook.rb
|
143
|
+
- lib/worldfactbook/cli.rb
|
144
|
+
- lib/worldfactbook/country.rb
|
145
|
+
- lib/worldfactbook/country_code.rb
|
146
|
+
homepage: http://github.com/sayem/worldfactbook
|
147
|
+
licenses:
|
148
|
+
- MIT
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
|
152
|
+
require_paths:
|
153
|
+
- lib
|
154
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
155
|
+
none: false
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
hash: -1046849416912465840
|
160
|
+
segments:
|
161
|
+
- 0
|
162
|
+
version: "0"
|
163
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
164
|
+
none: false
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: "0"
|
169
|
+
requirements: []
|
170
|
+
|
171
|
+
rubyforge_project:
|
172
|
+
rubygems_version: 1.7.2
|
173
|
+
signing_key:
|
174
|
+
specification_version: 3
|
175
|
+
summary: Easily access all the statistics and economic data available on the CIA World Factbook.
|
176
|
+
test_files: []
|
177
|
+
|