soccer-quiz 0.1.2 → 0.1.3
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 +4 -4
- data/lib/quiz/cli.rb +71 -84
- data/lib/quiz/scraper.rb +17 -10
- data/lib/quiz/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02aea3869baa3870430cce2767790a980664079402e3d24d79ff0548c9b34d4f
|
4
|
+
data.tar.gz: c546abcab96cfb08bcde91da97f41afa95115748b37461e5ff97a7abd94ab89a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 821d9505685d56f4109b9841140517587b8734745b885ebc4acb410540ecfa158d674ac20faf1266b359c69c1d1245c814b5e07c6db7112e8bedd3f4b0c6b628
|
7
|
+
data.tar.gz: 2e8ff93c464c5441451bc13a9aff5d76bbde2e41c2e77b4afaceed97733260fd844a7d80d04ba9155fcee65374e59dbb456cae2ce774e6a73218168efb2f9185
|
data/lib/quiz/cli.rb
CHANGED
@@ -3,26 +3,10 @@ class Quiz::CLI
|
|
3
3
|
@@points = []
|
4
4
|
def call
|
5
5
|
puts "Welcome to football soccer quiz."
|
6
|
-
|
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)
|
6
|
+
start_quiz
|
23
7
|
end
|
24
8
|
|
25
|
-
def start_quiz
|
9
|
+
def start_quiz
|
26
10
|
puts "*************************************************************************"
|
27
11
|
puts "Take this 10 question quiz to find out how much you know about soccer."
|
28
12
|
puts "*************************************************************************"
|
@@ -30,8 +14,10 @@ class Quiz::CLI
|
|
30
14
|
puts "*************************************************************************"
|
31
15
|
puts "To take the quiz press enter, to exit press 1 and enter."
|
32
16
|
input = gets
|
17
|
+
|
18
|
+
|
33
19
|
while input.to_i != 1
|
34
|
-
question_processor
|
20
|
+
question_processor
|
35
21
|
puts "To take the quiz one more time press enter. to exit press 1 and enter."
|
36
22
|
input = gets
|
37
23
|
end
|
@@ -41,7 +27,7 @@ class Quiz::CLI
|
|
41
27
|
def multiple_choice(answer,winners)
|
42
28
|
multiple_choice = []
|
43
29
|
multiple_choice << answer
|
44
|
-
until multiple_choice.size == 4
|
30
|
+
until multiple_choice.size == 4
|
45
31
|
multiple_choice << winners.sample
|
46
32
|
multiple_choice = multiple_choice.uniq
|
47
33
|
end
|
@@ -65,40 +51,43 @@ class Quiz::CLI
|
|
65
51
|
gets
|
66
52
|
end
|
67
53
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
54
|
+
def question_selector(objects,question)
|
55
|
+
years = objects.map{|item| item.year}
|
56
|
+
winners = objects.map{|item|item.winner}
|
57
|
+
hosts = objects.map{|item|item.host}
|
58
|
+
runner_ups = objects.map{|item|item.runner_up}
|
59
|
+
random_year = years.sample
|
60
|
+
random_winner = winners.sample
|
61
|
+
|
62
|
+
instace_for_answers = objects.select{|item|item.year == random_year}
|
63
|
+
|
64
|
+
answer_for_how_many = objects.select{|item|item.winner == random_winner}.size
|
65
|
+
|
66
|
+
winner = instace_for_answers[0].winner
|
67
|
+
|
68
|
+
host = instace_for_answers[0].host
|
69
|
+
runner_up = instace_for_answers[0].runner_up
|
70
|
+
if all_question("none",random_year)[question].include?("host")
|
71
|
+
puts all_question(host,random_year)[question]
|
72
|
+
multiple_choice(host,hosts)
|
73
|
+
elsif all_question("none",random_year)[question].include?("runner-up")
|
74
|
+
runner_ups = runner_ups.reject{|item| item == winner}
|
75
|
+
puts all_question(winner,random_year)[question]
|
76
|
+
multiple_choice(runner_up,runner_ups)
|
88
77
|
elsif all_question("none",random_year)[question].include?("How many")
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
78
|
+
puts all_question(random_winner,'none')[question]
|
79
|
+
obtions = []
|
80
|
+
counter = 1
|
81
|
+
while obtions.size < 13
|
82
|
+
obtions << counter
|
83
|
+
counter += 1
|
95
84
|
end
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
85
|
+
multiple_choice(answer_for_how_many,obtions)
|
86
|
+
else
|
87
|
+
puts all_question(winner,random_year)[question]
|
88
|
+
multiple_choice(winner,winners)
|
89
|
+
end
|
90
|
+
end
|
102
91
|
|
103
92
|
def all_question(team, year)
|
104
93
|
["Who won the world cup in #{year}?",
|
@@ -113,48 +102,45 @@ class Quiz::CLI
|
|
113
102
|
"How many Champion league #{team} has won?"
|
114
103
|
]
|
115
104
|
end
|
105
|
+
|
116
106
|
|
107
|
+
def question_processor
|
108
|
+
Quiz::CHAMPIONLEAGUE.champion_league_files(Quiz::Scraper.champion_league)
|
109
|
+
Quiz::Worldcup.world_cup_file(Quiz::Scraper.world_cup)
|
110
|
+
Quiz::BALONDOR.balon_d_or(Quiz::Scraper.balon_d_or_players)
|
111
|
+
champion_league = Quiz::CHAMPIONLEAGUE.all
|
112
|
+
world_cup = Quiz::Worldcup.all
|
113
|
+
balon_d_or = Quiz::BALONDOR.all
|
117
114
|
|
118
|
-
def question_processor(balon_d_or,champion_leage,world_cup)
|
119
115
|
last_20_champions = []
|
120
116
|
counter = 44
|
121
|
-
while counter <
|
122
|
-
last_20_champions <<
|
117
|
+
while counter < champion_league.size
|
118
|
+
last_20_champions << champion_league[counter]
|
123
119
|
counter += 1
|
124
|
-
end
|
125
|
-
# question_counter = 0
|
126
|
-
# until question_counter == 9
|
127
|
-
# if question_counter < 4
|
128
|
-
# question_selector(world_cup,question_counter)
|
129
|
-
# elsif question_counter > 4 && question_counter < 7
|
130
|
-
# question_selector(last_20_champions,question_counter)
|
131
|
-
# elsif question_counter > 6 && question_counter < 9
|
132
|
-
# question_selector(balon_d_or,question_counter)
|
133
|
-
# else question_selector(champion_leage,question_counter)
|
134
|
-
# question_counter += 1
|
135
|
-
# end
|
136
|
-
question_selector(world_cup,0)
|
137
|
-
question_selector(world_cup,1)
|
138
|
-
question_selector(world_cup,2)
|
139
|
-
question_selector(world_cup,3)
|
140
|
-
question_selector(last_20_champions,4)
|
141
|
-
question_selector(last_20_champions,5)
|
142
|
-
question_selector(last_20_champions,6)
|
143
|
-
question_selector(balon_d_or,7)
|
144
|
-
question_selector(balon_d_or,8)
|
145
|
-
question_selector(champion_leage,9)
|
146
|
-
points = 0
|
147
|
-
@@points.each{|i|points += i }
|
148
|
-
if points > 5
|
149
|
-
puts "Congratulation you score #{points} of 10 points."
|
150
|
-
else puts "Sorry you failed. you score #{points} of 10 points."
|
151
|
-
end
|
152
|
-
Quiz::CLI.clear
|
153
120
|
end
|
121
|
+
question_selector(world_cup,0)
|
122
|
+
question_selector(world_cup,1)
|
123
|
+
question_selector(world_cup,2)
|
124
|
+
question_selector(world_cup,3)
|
125
|
+
question_selector(last_20_champions,4)
|
126
|
+
question_selector(last_20_champions,5)
|
127
|
+
question_selector(last_20_champions,6)
|
128
|
+
question_selector(balon_d_or,7)
|
129
|
+
question_selector(balon_d_or,8)
|
130
|
+
question_selector(champion_league,9)
|
131
|
+
points = 0
|
132
|
+
@@points.each{|i|points += i }
|
133
|
+
if points > 5
|
134
|
+
puts "Congratulation you score #{points} of 10 points."
|
135
|
+
else puts "Sorry you failed. you score #{points} of 10 points."
|
136
|
+
end
|
137
|
+
Quiz::CLI.clear
|
138
|
+
end
|
154
139
|
|
155
140
|
def self.points
|
156
141
|
@@points
|
157
142
|
end
|
143
|
+
|
158
144
|
def self.clear
|
159
145
|
@@points.clear
|
160
146
|
end
|
@@ -165,3 +151,4 @@ end
|
|
165
151
|
|
166
152
|
|
167
153
|
|
154
|
+
|
data/lib/quiz/scraper.rb
CHANGED
@@ -1,12 +1,16 @@
|
|
1
1
|
#scraper Class
|
2
2
|
class Quiz::Scraper
|
3
|
+
|
4
|
+
|
3
5
|
def self.scraper(url,clas)
|
4
6
|
doc = Nokogiri::HTML(open(url))
|
5
7
|
doc.css(clas)
|
6
8
|
end
|
7
9
|
|
8
|
-
def self.balon_d_or_players
|
9
|
-
|
10
|
+
def self.balon_d_or_players
|
11
|
+
balon_d_or_url = "https://www.goal.com/es/noticias/todos-los-ganadores-del-balon-de-oro/wn19xivn1eh91t0jrslbzz5kq"
|
12
|
+
balon_de_or_files = ".tableizer-table"
|
13
|
+
players = self.scraper(balon_d_or_url,balon_de_or_files).map{|l|l.text.split(/\t|\*/).reject{|e|e.empty? || e.include?("(FIFA Balón de Oro)")}}
|
10
14
|
2.times{players[0].shift}
|
11
15
|
players[0][16] = "Lionel Messi"
|
12
16
|
counter = 0
|
@@ -19,23 +23,27 @@ class Quiz::Scraper
|
|
19
23
|
end
|
20
24
|
|
21
25
|
|
22
|
-
def self.world_cup
|
23
|
-
|
26
|
+
def self.world_cup
|
27
|
+
world_cup_url = "https://www.foxsports.com/soccer/fifa-world-cup/history"
|
28
|
+
world_cup = "tbody"
|
29
|
+
world_cup = self.scraper(world_cup_url,world_cup).map{|l|l.text.split(/\r\n|\s{2,}/).reject{|e|e.empty?}}
|
24
30
|
counter = 0
|
25
31
|
all_countries = []
|
26
32
|
while counter < world_cup[0].size
|
27
33
|
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]}
|
28
34
|
counter += 9
|
29
35
|
end
|
30
|
-
|
36
|
+
all_countries
|
31
37
|
end
|
32
38
|
|
33
|
-
def self.champion_league
|
34
|
-
|
39
|
+
def self.champion_league
|
40
|
+
champion_league_url = "https://en.wikipedia.org/wiki/List_of_European_Cup_and_UEFA_Champions_League_finals"
|
41
|
+
champion_league_file = "tbody"
|
42
|
+
champions = self.scraper(champion_league_url,champion_league_file).map{|l|l.text.split("\n").reject{|e|e.empty?}}
|
35
43
|
2.times{champions.shift}
|
36
44
|
10.times{champions[0].shift}
|
37
|
-
|
38
|
-
champions[0].map{|item|item.strip}
|
45
|
+
25.times{champions[0].pop}#22
|
46
|
+
champions[0].map{|item|item.strip}
|
39
47
|
counter = 0
|
40
48
|
all_teams = []
|
41
49
|
while counter < champions[0].size
|
@@ -46,4 +54,3 @@ class Quiz::Scraper
|
|
46
54
|
end
|
47
55
|
end
|
48
56
|
|
49
|
-
|
data/lib/quiz/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soccer-quiz
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yarvin Hernandez
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,7 +97,7 @@ homepage: https://rubygems.org/gems/soccer_quiz
|
|
97
97
|
licenses:
|
98
98
|
- MIT
|
99
99
|
metadata: {}
|
100
|
-
post_install_message:
|
100
|
+
post_install_message:
|
101
101
|
rdoc_options: []
|
102
102
|
require_paths:
|
103
103
|
- lib
|
@@ -112,8 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
- !ruby/object:Gem::Version
|
113
113
|
version: '0'
|
114
114
|
requirements: []
|
115
|
-
rubygems_version: 3.0.
|
116
|
-
signing_key:
|
115
|
+
rubygems_version: 3.0.8
|
116
|
+
signing_key:
|
117
117
|
specification_version: 4
|
118
118
|
summary: 10 questions quiz about soccer.
|
119
119
|
test_files: []
|