soccer_quiz 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/config/environment.rb +13 -0
- data/lib/quiz.rb +7 -0
- data/lib/quiz/balon_d_or.rb +15 -0
- data/lib/quiz/champion_league.rb +16 -0
- data/lib/quiz/cli.rb +163 -0
- data/lib/quiz/scraper.rb +52 -0
- data/lib/quiz/version.rb +3 -0
- data/lib/quiz/world_cup.rb +16 -0
- metadata +121 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 4cf307ab549907145df23b9bd244064a1a189edc76a5b1268caa8295f6f07dd3
|
|
4
|
+
data.tar.gz: 7d1905c8f396b3cfe9d7ff73aa7630c43ff3fd19468b2fbd64052ff8a164ec8f
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 151c253af25c4582e0d26a17eb2965264e63814be4f2b5287375656b9fa64264cb070760cdff7a9bd8dcf8a7b5c320dac5bded0cee2da0534e037e206effe424
|
|
7
|
+
data.tar.gz: 232cd8e9a4fc88bffde91d608bd06cffc0199e6c216c96ef18c68c1a86d568f8a276e53338a699d22cfe4bc734d9c897389a8a490a90e6b45689030541f9b452
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require 'pry'
|
|
2
|
+
require 'nokogiri'
|
|
3
|
+
require 'open-uri'
|
|
4
|
+
|
|
5
|
+
require_relative '../lib/quiz'
|
|
6
|
+
|
|
7
|
+
require_relative '../lib/quiz/scraper'
|
|
8
|
+
require_relative '../lib/quiz/balon_d_or'
|
|
9
|
+
require_relative '../lib/quiz/champion_league'
|
|
10
|
+
# require_relative '../lib/quiz/multiple_choice'
|
|
11
|
+
require_relative '../lib/quiz/world_cup'
|
|
12
|
+
require_relative '../lib/quiz/cli'
|
|
13
|
+
require_relative '../lib/quiz/version'
|
data/lib/quiz.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class Quiz::BALONDOR
|
|
2
|
+
attr_accessor :winner, :year, :host, :runner_up
|
|
3
|
+
@@all = []
|
|
4
|
+
def initialize(file)
|
|
5
|
+
@@all << self
|
|
6
|
+
file.each{|key,value|
|
|
7
|
+
self.send("#{key}=", value)}
|
|
8
|
+
end
|
|
9
|
+
def self.balon_d_or(file)
|
|
10
|
+
file.each{|e|Quiz::BALONDOR.new(e)}
|
|
11
|
+
end
|
|
12
|
+
def self.all
|
|
13
|
+
@@all
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class Quiz::CHAMPIONLEAGUE
|
|
2
|
+
attr_accessor :year, :winner, :runner_up, :host, :score
|
|
3
|
+
@@all = []
|
|
4
|
+
def initialize(file)
|
|
5
|
+
@@all << self
|
|
6
|
+
file.each{|key,value|
|
|
7
|
+
self.send("#{key}=", value)}
|
|
8
|
+
|
|
9
|
+
end
|
|
10
|
+
def self.champion_league_files(file)
|
|
11
|
+
file.each{|e|Quiz::CHAMPIONLEAGUE.new(e)}
|
|
12
|
+
end
|
|
13
|
+
def self.all
|
|
14
|
+
@@all
|
|
15
|
+
end
|
|
16
|
+
end
|
data/lib/quiz/cli.rb
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
|
|
2
|
+
class Quiz::CLI
|
|
3
|
+
@@points = []
|
|
4
|
+
def call
|
|
5
|
+
puts "Welcome to football soccer quiz."
|
|
6
|
+
champion_league_url = "https://en.wikipedia.org/wiki/List_of_European_Cup_and_UEFA_Champions_League_finals"
|
|
7
|
+
champion_league_file = Quiz::Scraper.champion_league(champion_league_url,"tbody")
|
|
8
|
+
Quiz::CHAMPIONLEAGUE.champion_league_files(champion_league_file)
|
|
9
|
+
champion_league = Quiz::CHAMPIONLEAGUE.all
|
|
10
|
+
|
|
11
|
+
world_cup_url = "https://www.foxsports.com/soccer/fifa-world-cup/history"
|
|
12
|
+
world_cup = Quiz::Scraper.world_cup(world_cup_url,"tbody")
|
|
13
|
+
Quiz::Worldcup.world_cup_file(world_cup)
|
|
14
|
+
world_cup = Quiz::Worldcup.all
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
balon_d_or_url = "https://www.goal.com/es/noticias/todos-los-ganadores-del-balon-de-oro/wn19xivn1eh91t0jrslbzz5kq"
|
|
18
|
+
players = Quiz::Scraper.balon_d_or_players(balon_d_or_url,".tableizer-table")
|
|
19
|
+
Quiz::BALONDOR.balon_d_or(players)
|
|
20
|
+
balon_d_or = Quiz::BALONDOR.all
|
|
21
|
+
|
|
22
|
+
start_quiz(balon_d_or,champion_league,world_cup)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def start_quiz(balon_d_or,champion_league,world_cup)
|
|
26
|
+
puts "Take this 10 question quiz to find out how much you know about soccer."
|
|
27
|
+
puts "You pass the test if you score 6 or more points."
|
|
28
|
+
puts "To take the quiz press enter, to exit press 1 and enter."
|
|
29
|
+
input = gets
|
|
30
|
+
while input.to_i != 1
|
|
31
|
+
question_processor(balon_d_or,champion_league,world_cup)
|
|
32
|
+
puts "To take the quiz one more time press enter. to exit press 1 and enter."
|
|
33
|
+
input = gets
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def multiple_choice(answer,winners)
|
|
38
|
+
multiple_choice = []
|
|
39
|
+
multiple_choice << answer
|
|
40
|
+
until multiple_choice.size == 4
|
|
41
|
+
multiple_choice << winners.sample
|
|
42
|
+
multiple_choice = multiple_choice.uniq
|
|
43
|
+
end
|
|
44
|
+
multiple_choice = multiple_choice.shuffle
|
|
45
|
+
multiple_choice.each_with_index{|item,index| puts "#{index + 1}: #{item}"}
|
|
46
|
+
input = ""
|
|
47
|
+
loop do
|
|
48
|
+
input = gets
|
|
49
|
+
if !(1..4).include?(input.to_i)
|
|
50
|
+
puts "Invalid choice, enter a number from 1 to 4"
|
|
51
|
+
else break
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
if multiple_choice.index(answer) == input.to_i - 1
|
|
55
|
+
@@points << 1
|
|
56
|
+
puts "Right"
|
|
57
|
+
else
|
|
58
|
+
puts "Wrong. Right answer is #{multiple_choice.index(answer) + 1}: #{answer}."
|
|
59
|
+
end
|
|
60
|
+
puts "Press enter for next question"
|
|
61
|
+
gets
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def question_selector(objects,question)
|
|
65
|
+
years = objects.map{|item| item.year}
|
|
66
|
+
winners = objects.map{|item|item.winner}
|
|
67
|
+
hosts = objects.map{|item|item.host}
|
|
68
|
+
runner_ups = objects.map{|item|item.runner_up}
|
|
69
|
+
random_year = years.sample
|
|
70
|
+
random_winner = winners.sample
|
|
71
|
+
answer = objects.select{|item|item.year == random_year}
|
|
72
|
+
titles_amount = objects.select{|item|item.winner == random_winner}.size
|
|
73
|
+
winner = answer[0].winner
|
|
74
|
+
host = answer[0].host
|
|
75
|
+
runner_up = answer[0].runner_up
|
|
76
|
+
|
|
77
|
+
if all_question("none",random_year)[question].include?("host")
|
|
78
|
+
puts all_question(host,random_year)[question]
|
|
79
|
+
multiple_choice(host,hosts)
|
|
80
|
+
elsif all_question("none",random_year)[question].include?("runner-up")
|
|
81
|
+
runner_ups = runner_ups.reject{|item| item == winner}
|
|
82
|
+
puts all_question(winner,random_year)[question]
|
|
83
|
+
multiple_choice(runner_up,runner_ups)
|
|
84
|
+
elsif all_question("none",random_year)[question].include?("How many")
|
|
85
|
+
puts all_question(random_winner,'none')[question]
|
|
86
|
+
obtions = []
|
|
87
|
+
counter = 1
|
|
88
|
+
while obtions.size < 13
|
|
89
|
+
obtions << counter
|
|
90
|
+
counter += 1
|
|
91
|
+
end
|
|
92
|
+
multiple_choice(titles_amount,obtions)
|
|
93
|
+
else
|
|
94
|
+
puts all_question(winner,random_year)[question]
|
|
95
|
+
multiple_choice(winner,winners)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def all_question(team, year)
|
|
100
|
+
["Who won the world cup in #{year}?",
|
|
101
|
+
"Who was the host in #{year} world cup",
|
|
102
|
+
"#{team} won the World cup final in #{year}. Who was the runner-up?",
|
|
103
|
+
"How many world cup #{team} has won?",
|
|
104
|
+
"Who won the champion leage in #{year}?",
|
|
105
|
+
"#{team} won the Champion leage final in #{year}. Who was the runner-up?",
|
|
106
|
+
"Who hosted champion league final in #{year}?",
|
|
107
|
+
"Who won the balon d'Or in #{year}?",
|
|
108
|
+
"How many balon de'or #{team} has won?",
|
|
109
|
+
"How many Champion league #{team} has won?"
|
|
110
|
+
]
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def question_processor(balon_d_or,champion_leage,world_cup)
|
|
115
|
+
last_20_champions = []
|
|
116
|
+
counter = 44
|
|
117
|
+
while counter < champion_leage.size
|
|
118
|
+
last_20_champions << champion_leage[counter]
|
|
119
|
+
counter += 1
|
|
120
|
+
end
|
|
121
|
+
# question_counter = 0
|
|
122
|
+
# until question_counter == 9
|
|
123
|
+
# if question_counter < 4
|
|
124
|
+
# question_selector(world_cup,question_counter)
|
|
125
|
+
# elsif question_counter > 4 && question_counter < 7
|
|
126
|
+
# question_selector(last_20_champions,question_counter)
|
|
127
|
+
# elsif question_counter > 6 && question_counter < 9
|
|
128
|
+
# question_selector(balon_d_or,question_counter)
|
|
129
|
+
# else question_selector(champion_leage,question_counter)
|
|
130
|
+
# question_counter += 1
|
|
131
|
+
# end
|
|
132
|
+
question_selector(world_cup,0)
|
|
133
|
+
question_selector(world_cup,1)
|
|
134
|
+
question_selector(world_cup,2)
|
|
135
|
+
question_selector(world_cup,3)
|
|
136
|
+
question_selector(last_20_champions,4)
|
|
137
|
+
question_selector(last_20_champions,5)
|
|
138
|
+
question_selector(last_20_champions,6)
|
|
139
|
+
question_selector(balon_d_or,7)
|
|
140
|
+
question_selector(balon_d_or,8)
|
|
141
|
+
question_selector(champion_leage,9)
|
|
142
|
+
points = 0
|
|
143
|
+
@@points.each{|i|points += i }
|
|
144
|
+
if points > 5
|
|
145
|
+
puts "Congratulation you score #{points} of 10 points."
|
|
146
|
+
else puts "Sorry you failed. you score #{points} of 10 points."
|
|
147
|
+
end
|
|
148
|
+
Quiz::CLI.clear
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def self.points
|
|
152
|
+
@@points
|
|
153
|
+
end
|
|
154
|
+
def self.clear
|
|
155
|
+
@@points.clear
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
data/lib/quiz/scraper.rb
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# require 'nokogiri'
|
|
2
|
+
# require 'open-uri'
|
|
3
|
+
|
|
4
|
+
#scraper Class
|
|
5
|
+
class Quiz::Scraper
|
|
6
|
+
def self.scraper(url,clas)
|
|
7
|
+
doc = Nokogiri::HTML(open(url))
|
|
8
|
+
doc.css(clas)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def self.balon_d_or_players(url,clas)
|
|
12
|
+
players = self.scraper(url,clas).map{|l|l.text.split(/\t|\*/).reject{|e|e.empty? || e.include?("(FIFA Balón de Oro)")}}
|
|
13
|
+
2.times{players[0].shift}
|
|
14
|
+
players[0][16] = "Lionel Messi"
|
|
15
|
+
counter = 0
|
|
16
|
+
all_players = []
|
|
17
|
+
while counter < players[0].size
|
|
18
|
+
all_players << {:winner => players[0][counter],:year => players[0][counter + 1]}
|
|
19
|
+
counter += 2
|
|
20
|
+
end
|
|
21
|
+
all_players
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def self.world_cup(url,clas)
|
|
26
|
+
world_cup = self.scraper(url,clas).map{|l|l.text.split(/\r\n|\s{2,}/).reject{|e|e.empty?}}
|
|
27
|
+
counter = 0
|
|
28
|
+
all_countries = []
|
|
29
|
+
while counter < world_cup[0].size
|
|
30
|
+
all_countries << {:year => world_cup[0][counter], :host => world_cup[0][counter + 1], :winner => world_cup[0][counter + 2], :runner_up => world_cup[0][counter + 3], :thirth_place => world_cup[0][counter + 4]}
|
|
31
|
+
counter += 9
|
|
32
|
+
end
|
|
33
|
+
all_countries
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.champion_league(url,clas)
|
|
37
|
+
champions = self.scraper(url,clas).map{|l|l.text.split("\n").reject{|e|e.empty?}}
|
|
38
|
+
2.times{champions.shift}
|
|
39
|
+
10.times{champions[0].shift}
|
|
40
|
+
22.times{champions[0].pop}
|
|
41
|
+
champions[0].map{|item|item.strip}
|
|
42
|
+
counter = 0
|
|
43
|
+
all_teams = []
|
|
44
|
+
while counter < champions[0].size
|
|
45
|
+
all_teams << {:year => champions[0][counter], :winner => champions[0][counter + 2], :score => champions[0][counter + 3], :runner_up => champions[0][counter + 5], :host => champions[0][counter + 6]}
|
|
46
|
+
counter += 8
|
|
47
|
+
end
|
|
48
|
+
all_teams
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
data/lib/quiz/version.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
class Quiz::Worldcup
|
|
2
|
+
attr_accessor :winner, :year, :host, :runner_up, :thirth_place
|
|
3
|
+
@@all = []
|
|
4
|
+
def initialize(file)
|
|
5
|
+
@@all << self
|
|
6
|
+
file.each{|key,value|
|
|
7
|
+
self.send("#{key}=", value)}
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def self.world_cup_file(file)
|
|
11
|
+
file.each{|e|Quiz::Worldcup.new(e)}
|
|
12
|
+
end
|
|
13
|
+
def self.all
|
|
14
|
+
@@all
|
|
15
|
+
end
|
|
16
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: soccer_quiz
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Yarvin Hernandez
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2020-05-31 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: '0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rspec
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '10.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '10.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: :development
|
|
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: pry
|
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
type: :development
|
|
77
|
+
prerelease: false
|
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
79
|
+
requirements:
|
|
80
|
+
- - ">="
|
|
81
|
+
- !ruby/object:Gem::Version
|
|
82
|
+
version: '0'
|
|
83
|
+
description: Find out how much you know about soccer.
|
|
84
|
+
email:
|
|
85
|
+
- yarvinhhernandez@gmail.com
|
|
86
|
+
executables: []
|
|
87
|
+
extensions: []
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
files:
|
|
90
|
+
- config/environment.rb
|
|
91
|
+
- lib/quiz.rb
|
|
92
|
+
- lib/quiz/balon_d_or.rb
|
|
93
|
+
- lib/quiz/champion_league.rb
|
|
94
|
+
- lib/quiz/cli.rb
|
|
95
|
+
- lib/quiz/scraper.rb
|
|
96
|
+
- lib/quiz/version.rb
|
|
97
|
+
- lib/quiz/world_cup.rb
|
|
98
|
+
homepage: https://github.com/yarvinh/quiz_app
|
|
99
|
+
licenses:
|
|
100
|
+
- MIT
|
|
101
|
+
metadata: {}
|
|
102
|
+
post_install_message:
|
|
103
|
+
rdoc_options: []
|
|
104
|
+
require_paths:
|
|
105
|
+
- lib
|
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
107
|
+
requirements:
|
|
108
|
+
- - ">="
|
|
109
|
+
- !ruby/object:Gem::Version
|
|
110
|
+
version: 2.3.0
|
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
|
+
requirements:
|
|
113
|
+
- - ">="
|
|
114
|
+
- !ruby/object:Gem::Version
|
|
115
|
+
version: '0'
|
|
116
|
+
requirements: []
|
|
117
|
+
rubygems_version: 3.0.3
|
|
118
|
+
signing_key:
|
|
119
|
+
specification_version: 4
|
|
120
|
+
summary: 10 questions quiz about soccer.
|
|
121
|
+
test_files: []
|