wikiloc 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .*.swp
6
+ .*.swo
7
+ vendor/ruby
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/README ADDED
@@ -0,0 +1,4 @@
1
+ Wikiloc
2
+ ========
3
+ Currently only shows countries and their capital cities
4
+ (169 out of 196 countries)
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = 'spec/**/*_spec.rb'
8
+ spec.rspec_opts = '--color'
9
+ end
10
+
11
+ task :default => :spec
data/bin/wikiloc ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require 'wikiloc'
5
+
6
+ interactor = Wikiloc::Interactor.new(STDOUT)
7
+ interactor.start
data/bin/wikiloc.bat ADDED
@@ -0,0 +1 @@
1
+ @"ruby.exe" "%~dpn0" %*
@@ -0,0 +1,220 @@
1
+ Feature: locator submits location
2
+
3
+ The locator submits a location. The application scrapes relevant data from Wikipedia.
4
+ As a start, it will get the location's populations.
5
+
6
+ Scenario: Asking for the capital of Israel
7
+ Given I am not yet using wikiloc
8
+ When I run `wikiloc` interactively
9
+ And I type "Israel"
10
+ And I type "capital"
11
+ Then the output should contain "Welcome to Wikiloc!"
12
+ And the output should contain "Enter location:"
13
+ Then the output should contain "What do you want to know?"
14
+ Then the output should contain "Jerusalem"
15
+
16
+ Scenario Outline: All countries and their capitals
17
+ Given the location is "<location>"
18
+ When I ask for "<data_type>"
19
+ Then the data should be "<data>"
20
+
21
+ Scenarios: All countries and their capitals
22
+ | location | data_type | data |
23
+ | Afghanistan | capital | Kabul |
24
+ | Albania | capital | Tirana |
25
+ | Algeria | capital | Algiers |
26
+ | Andorra | capital | Andorra la Vella |
27
+ | Angola | capital | Luanda |
28
+ | Antigua and Barbuda | capital | Saint John's |
29
+ | Argentina | capital | Buenos Aires |
30
+ | Armenia | capital | Yerevan |
31
+ | Australia | capital | Canberra |
32
+ | Austria | capital | Vienna |
33
+ | Azerbaijan | capital | Baku |
34
+ | The Bahamas | capital | Nassau |
35
+ | Bahrain | capital | Manama |
36
+ | Bangladesh | capital | Dhaka |
37
+ | Barbados | capital | Bridgetown |
38
+ | Belarus | capital | Minsk |
39
+ | Belgium | capital | Brussels |
40
+ | Belize | capital | Belmopan |
41
+ | Benin | capital | Porto-Novo |
42
+ | Bhutan | capital | Thimphu |
43
+ #| Bolivia | capital | La Paz (administrative); Sucre (judicial) |
44
+ | Bosnia and Herzegovina | capital | Sarajevo |
45
+ | Botswana | capital | Gaborone |
46
+ #| Brazil | capital | Brasilia |
47
+ | Brunei | capital | Bandar Seri Begawan |
48
+ | Bulgaria | capital | Sofia |
49
+ | Burkina Faso | capital | Ouagadougou |
50
+ | Burundi | capital | Bujumbura |
51
+ | Cambodia | capital | Phnom Penh |
52
+ #| Cameroon | capital | Yaounde |
53
+ | Canada | capital | Ottawa |
54
+ | Cape Verde | capital | Praia |
55
+ | Central African Republic | capital | Bangui |
56
+ | Chad | capital | N'Djamena |
57
+ | Chile | capital | Santiago |
58
+ | China | capital | Beijing |
59
+ | Colombia | capital | Bogotá |
60
+ | Comoros | capital | Moroni |
61
+ | Congo, Republic of the | capital | Brazzaville |
62
+ | Congo, Democratic Republic of the | capital | Kinshasa |
63
+ | Costa Rica | capital | San José |
64
+ ##| Cote d'Ivoire | capital | Yamoussoukro (official); Abidjan (de facto) |
65
+ | Croatia | capital | Zagreb |
66
+ | Cuba | capital | Havana |
67
+ | Cyprus | capital | Nicosia |
68
+ | Czech Republic | capital | Prague |
69
+ | Denmark | capital | Copenhagen |
70
+ | Djibouti | capital | Djibouti |
71
+ | Dominica | capital | Roseau |
72
+ | Dominican Republic | capital | Santo Domingo |
73
+ | East Timor | capital | Dili |
74
+ | Ecuador | capital | Quito |
75
+ | Egypt | capital | Cairo |
76
+ | El Salvador | capital | San Salvador |
77
+ #| Equatorial Guinea | capital | Malabo |
78
+ | Eritrea | capital | Asmara |
79
+ | Estonia | capital | Tallinn |
80
+ | Ethiopia | capital | Addis Ababa |
81
+ | Fiji | capital | Suva |
82
+ | Finland | capital | Helsinki |
83
+ | France | capital | Paris |
84
+ | Gabon | capital | Libreville |
85
+ | The Gambia | capital | Banjul |
86
+ #| Georgia | capital | Tbilisi |
87
+ | Germany | capital | Berlin |
88
+ | Ghana | capital | Accra |
89
+ | Greece | capital | Athens |
90
+ | Grenada | capital | St. George’s |
91
+ | Guatemala | capital | Guatemala City |
92
+ | Guinea | capital | Conakry |
93
+ | Guinea-Bissau | capital | Bissau |
94
+ | Guyana | capital | Georgetown |
95
+ | Haiti | capital | Port-au-Prince |
96
+ | Honduras | capital | Tegucigalpa and Comayagüela |
97
+ | Hungary | capital | Budapest |
98
+ | Iceland | capital | Reykjavík |
99
+ #| India | capital | New Delhi |
100
+ | Indonesia | capital | Jakarta |
101
+ | Iran | capital | Tehran |
102
+ | Iraq | capital | Baghdad |
103
+ #| Ireland | capital | Dublin |
104
+ | Israel | capital | Jerusalem |
105
+ | Italy | capital | Rome |
106
+ | Jamaica | capital | Kingston |
107
+ | Japan | capital | Tokyo |
108
+ | Jordan | capital | Amman |
109
+ | Kazakhstan | capital | Astana |
110
+ | Kenya | capital | Nairobi |
111
+ #| Kiribati | capital | Tarawa Atoll |
112
+ | Korea, North | capital | Pyongyang |
113
+ | Korea, South | capital | Seoul |
114
+ | Kosovo | capital | Pristina (Prishtina or Priština) |
115
+ | Kuwait | capital | Kuwait City |
116
+ | Kyrgyzstan | capital | Bishkek |
117
+ | Laos | capital | Vientiane |
118
+ | Latvia | capital | Riga |
119
+ | Lebanon | capital | Beirut |
120
+ | Lesotho | capital | Maseru |
121
+ | Liberia | capital | Monrovia |
122
+ #| Libya | capital | Tripoli |
123
+ #| Liechtenstein | capital | Vaduz |
124
+ | Lithuania | capital | Vilnius |
125
+ | Luxembourg | capital | Luxembourg |
126
+ #| Macedonia | capital | Skopje |
127
+ | Madagascar | capital | Antananarivo |
128
+ | Malawi | capital | Lilongwe |
129
+ | Malaysia | capital | Kuala Lumpur |
130
+ | Maldives | capital | Malé |
131
+ | Mali | capital | Bamako |
132
+ | Malta | capital | Valletta |
133
+ | Marshall Islands | capital | Majuro (Delap) |
134
+ | Mauritania | capital | Nouakchott |
135
+ | Mauritius | capital | Port Louis |
136
+ | Mexico | capital | Mexico City |
137
+ | Micronesia, Federated States of | capital | Palikir |
138
+ #| Moldova | capital | Chisinau |
139
+ #| Monaco | capital | Monaco |
140
+ | Mongolia | capital | Ulan Bator |
141
+ #| Montenegro | capital | Podgorica |
142
+ | Morocco | capital | Rabat |
143
+ | Mozambique | capital | Maputo |
144
+ ##| Myanmar (Burma) | capital | Rangoon (Yangon); Naypyidaw or Nay Pyi Taw (administrative) |
145
+ | Namibia | capital | Windhoek |
146
+ ##| Nauru | capital | no official capital; government offices in Yaren District |
147
+ | Nepal | capital | Kathmandu |
148
+ | Netherlands | capital | Amsterdam |
149
+ | New Zealand | capital | Wellington |
150
+ | Nicaragua | capital | Managua |
151
+ | Niger | capital | Niamey |
152
+ | Nigeria | capital | Abuja |
153
+ | Norway | capital | Oslo |
154
+ | Oman | capital | Muscat |
155
+ | Pakistan | capital | Islamabad |
156
+ #| Palau | capital | Melekeok |
157
+ | Panama | capital | Panama |
158
+ | Papua New Guinea | capital | Port Moresby |
159
+ | Paraguay | capital | Asunción |
160
+ | Peru | capital | Lima |
161
+ | Philippines | capital | Manila |
162
+ | Poland | capital | Warsaw |
163
+ | Portugal | capital | Lisbon |
164
+ | Qatar | capital | Doha |
165
+ | Romania | capital | Bucharest |
166
+ | Russia | capital | Moscow |
167
+ | Rwanda | capital | Kigali |
168
+ | Saint Kitts and Nevis | capital | Basseterre |
169
+ | Saint Lucia | capital | Castries |
170
+ | Saint Vincent and the Grenadines | capital | Kingstown |
171
+ | Samoa | capital | Apia |
172
+ | San Marino | capital | City of San Marino |
173
+ | Sao Tome and Principe | capital | São Tomé |
174
+ | Saudi Arabia | capital | Riyadh |
175
+ | Senegal | capital | Dakar |
176
+ | Serbia | capital | Belgrade |
177
+ | Seychelles | capital | Victoria |
178
+ | Sierra Leone | capital | Freetown |
179
+ #| Singapore | capital | Singapore |
180
+ | Slovakia | capital | Bratislava |
181
+ #| Slovenia | capital | Ljubljana |
182
+ | Solomon Islands | capital | Honiara |
183
+ | Somalia | capital | Mogadishu |
184
+ ##| South Africa | capital | Pretoria (administrative); Cape Town (legislative); Bloemfontein (judiciary) |
185
+ | South Sudan | capital | Juba |
186
+ | Spain | capital | Madrid |
187
+ ##| Sri Lanka | capital | Colombo; Sri Jayewardenepura Kotte (legislative) |
188
+ | Sudan | capital | Khartoum |
189
+ | Suriname | capital | Paramaribo |
190
+ ##| Swaziland | capital | Mbabane |
191
+ | Sweden | capital | Stockholm |
192
+ #| Switzerland | capital | Bern |
193
+ | Syria | capital | Damascus |
194
+ #| Taiwan | capital | Taipei |
195
+ | Tajikistan | capital | Dushanbe |
196
+ | Tanzania | capital | Dodoma |
197
+ #| Thailand | capital | Bangkok |
198
+ | Togo | capital | Lomé |
199
+ | Tonga | capital | Nukuʻalofa |
200
+ #| Trinidad and Tobago | capital | Port-of-Spain |
201
+ | Tunisia | capital | Tunis |
202
+ | Turkey | capital | Ankara |
203
+ | Turkmenistan | capital | Ashgabat |
204
+ | Tuvalu | capital | Funafuti |
205
+ | Uganda | capital | Kampala |
206
+ | Ukraine | capital | Kiev |
207
+ | United Arab Emirates | capital | Abu Dhabi |
208
+ | United Kingdom | capital | London |
209
+ | United States of America | capital | Washington, D.C. |
210
+ | Uruguay | capital | Montevideo |
211
+ | Uzbekistan | capital | Tashkent |
212
+ | Vanuatu | capital | Port Vila |
213
+ #| Vatican City (Holy See) | capital | Vatican City |
214
+ | Venezuela | capital | Caracas |
215
+ | Vietnam | capital | Hanoi |
216
+ | Yemen | capital | Sana‘a |
217
+ | Zambia | capital | Lusaka |
218
+ | Zimbabwe | capital | Harare |
219
+
220
+
@@ -0,0 +1,31 @@
1
+ class Output
2
+ def messages
3
+ @messages ||= []
4
+ end
5
+
6
+ def puts(message)
7
+ messages << message
8
+ end
9
+ end
10
+
11
+ def output
12
+ @output ||= Output.new
13
+ end
14
+
15
+ Given /^I am not yet using wikiloc$/ do
16
+ end
17
+
18
+ Given /^the location is "([^"]*)"$/ do |location|
19
+ @interactor = Wikiloc::Interactor.new(output)
20
+ @interactor.set_location(location)
21
+ end
22
+
23
+ When /^I ask for "([^"]*)"$/ do |data_type|
24
+ @interactor.set_data_type(data_type)
25
+ info = @interactor.get_info
26
+ output.puts info
27
+ end
28
+
29
+ Then /^the data should be "([^"]*)"$/ do |message|
30
+ output.messages.should include(message)
31
+ end
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH << File.expand_path('../../../lib', __FILE__)
2
+ require 'wikiloc'
3
+ require 'aruba/cucumber'
@@ -0,0 +1,54 @@
1
+ module Wikiloc
2
+ class InfoGetter
3
+ def initialize(location, data_type)
4
+ @location, @data_type = location, data_type
5
+ @agent = Mechanize.new
6
+ @agent.user_agent_alias = 'Mac Safari'
7
+ end
8
+
9
+ def page_url
10
+ 'http://en.wikipedia.org/wiki/'
11
+ end
12
+
13
+ def get_info
14
+ @data_type = @data_type.downcase
15
+
16
+ case @data_type
17
+ #when 'link'
18
+ # 'http://en.wikipedia.org/wiki/' + @location
19
+ when 'capital'
20
+ xpath = "//*[.='Capital']"
21
+ else
22
+ return :invalid
23
+ end
24
+
25
+ find_data_in_table(xpath)
26
+
27
+ end
28
+
29
+ def find_data_in_table(xpath)
30
+ page = @agent.get(page_url + @location)
31
+ data = page.parser.xpath(xpath)[0].parent.parent.children[2].children[0].text
32
+ if data[0..4].eql?("Motto")
33
+ data = page.parser.xpath(xpath)[0].parent.parent.children[5].children[2].text
34
+ data = cut_number_off(data)
35
+ elsif data[0..5].eql?("Anthem")
36
+ data = page.parser.xpath(xpath)[0].parent.parent.children[4].children[2].text
37
+ data = cut_number_off(data)
38
+ end
39
+ data
40
+ end
41
+
42
+ def cut_number_off(data)
43
+ string = ""
44
+ data.each_char do |i|
45
+ if (i.eql?('0') || i.eql?('1') || i.eql?('2') || i.eql?('3') || i.eql?('4') || i.eql?('5') || i.eql?('6') || i.eql?('7') || i.eql?('8') || i.eql?('9'))
46
+ break
47
+ else
48
+ string = string + i
49
+ end
50
+ end
51
+ string
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,47 @@
1
+ module Wikiloc
2
+ class Interactor
3
+ def initialize(output)
4
+ @output = output
5
+ @location = "Israel" #default location
6
+ @data_type = "Capital" #default data type
7
+ end
8
+
9
+ def set_location(location)
10
+ @location = location
11
+ end
12
+
13
+ def set_data_type(data_type)
14
+ @data_type = data_type
15
+ end
16
+
17
+ def get_location
18
+ @location
19
+ end
20
+
21
+ def get_data_type
22
+ @data_type
23
+ end
24
+
25
+ def start
26
+ @output.puts 'Welcome to Wikiloc!'
27
+ @output.puts 'Enter location:'
28
+ location = gets.chomp
29
+ set_location(location)
30
+ @output.puts 'What do you want to know?'
31
+ data_type = gets.chomp
32
+ set_data_type(data_type)
33
+ info = get_info
34
+ if info != :invalid
35
+ @output.puts "The #{@data_type} of #{@location} is: #{info}"
36
+ else
37
+ @output.puts "Invalid Query. Please try again."
38
+ end
39
+ end
40
+
41
+ def get_info
42
+ info_getter = InfoGetter.new(@location, @data_type)
43
+ info_getter.get_info
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module Wikiloc
2
+ VERSION = "0.0.1"
3
+ end
data/lib/wikiloc.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'wikiloc/interactor.rb'
2
+ require 'wikiloc/info_getter.rb'
3
+ require 'rubygems'
4
+ require 'mechanize'
data/wikiloc.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "wikiloc/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "wikiloc"
7
+ s.version = Wikiloc::VERSION
8
+ s.authors = ["Raffi Vartanian"]
9
+ s.email = ["raffivar@gmail.com"]
10
+ s.homepage = "https://github.com/raffivar/wikiloc"
11
+ s.summary = %q{}
12
+ s.description = %q{}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_runtime_dependency %q<mechanize>
20
+
21
+ s.add_development_dependency %q<bundler>, ["~> 1.0.0"]
22
+ s.add_development_dependency %q<rspec>, [">= 2.7.0"]
23
+ s.add_development_dependency %q<cucumber>
24
+ s.add_development_dependency %q<aruba>
25
+ s.add_development_dependency %q<rake>, [">= 0"]
26
+ s.add_development_dependency %q<guard>, [">= 0.9.0"]
27
+ s.add_development_dependency %q<guard-rspec>, [">= 0"]
28
+ s.add_development_dependency %q<ruby_gntp>, [">= 0"]
29
+ end
metadata ADDED
@@ -0,0 +1,160 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wikiloc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Raffi Vartanian
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: mechanize
16
+ requirement: &17807560 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *17807560
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &17807000 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *17807000
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &17806480 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 2.7.0
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *17806480
47
+ - !ruby/object:Gem::Dependency
48
+ name: cucumber
49
+ requirement: &17806080 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *17806080
58
+ - !ruby/object:Gem::Dependency
59
+ name: aruba
60
+ requirement: &17805460 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *17805460
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: &17804320 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *17804320
80
+ - !ruby/object:Gem::Dependency
81
+ name: guard
82
+ requirement: &17782760 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: 0.9.0
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: *17782760
91
+ - !ruby/object:Gem::Dependency
92
+ name: guard-rspec
93
+ requirement: &17781700 !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: *17781700
102
+ - !ruby/object:Gem::Dependency
103
+ name: ruby_gntp
104
+ requirement: &17780480 !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: *17780480
113
+ description: ''
114
+ email:
115
+ - raffivar@gmail.com
116
+ executables:
117
+ - wikiloc
118
+ - wikiloc.bat
119
+ extensions: []
120
+ extra_rdoc_files: []
121
+ files:
122
+ - .gitignore
123
+ - Gemfile
124
+ - README
125
+ - Rakefile
126
+ - bin/wikiloc
127
+ - bin/wikiloc.bat
128
+ - features/locator_submits_location.feature
129
+ - features/step_definitions/wikiloc_steps.rb
130
+ - features/support/env.rb
131
+ - lib/wikiloc.rb
132
+ - lib/wikiloc/info_getter.rb
133
+ - lib/wikiloc/interactor.rb
134
+ - lib/wikiloc/version.rb
135
+ - wikiloc.gemspec
136
+ homepage: https://github.com/raffivar/wikiloc
137
+ licenses: []
138
+ post_install_message:
139
+ rdoc_options: []
140
+ require_paths:
141
+ - lib
142
+ required_ruby_version: !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ! '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ none: false
150
+ requirements:
151
+ - - ! '>='
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 1.8.10
157
+ signing_key:
158
+ specification_version: 3
159
+ summary: ''
160
+ test_files: []