soccer-quiz 0.1.1 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9fe7fc9e40452c5b0e0a959f383bd831298be2226c0222b3beb72f630dc3954
4
- data.tar.gz: 8450bd8d832870434480a152b8671f3af17d05108c50656c2eb5080386a3f8d2
3
+ metadata.gz: 83d1b7f0a4503c846912b2cee8e99ab83e7c5f63598515f51fda558e7c26bb56
4
+ data.tar.gz: a2948b710b67d54274803adcaab90db96f1b0efc96511c282dabd8221c1772ad
5
5
  SHA512:
6
- metadata.gz: 0d7d16e0712c15a0e182281c055c32e33c3e8fc996327c2b717ba1f1a8edc2b4d17e46467aa5e4fabc06517c3c995ffaa89cf783cb36975aee232d10a467da4a
7
- data.tar.gz: f61d8b1b59623bf726ee6ad87e9cc2742cb35656ee0efc52f259889df4e39c2ad1f38d7e26b6425519dcefe7a84b64f5722c9a678cb8a99f7a1ed2b295a4a216
6
+ metadata.gz: 1e4c00a7bd40185b53d25d08f7b1d6e16cd3b10dbcd2930295b3483a8e0d830ffed001cb2515da648c654e7d01e37e0899e49ce21023d8a2f361ff731bf8f7f2
7
+ data.tar.gz: 1722039f50710738648b6c7f81d7e979266b40849ad3a2f59ae6369ebae678aeb4cc805583a0ad447b60ebf483c9c34af8104ce5dbbc24654ae30f19717a71f5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- soccer-quiz (0.1.0)
4
+ soccer-quiz (0.1.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -10,7 +10,7 @@ GEM
10
10
  mini_portile2 (2.4.0)
11
11
  nokogiri (1.10.9)
12
12
  mini_portile2 (~> 2.4.0)
13
- rake (10.5.0)
13
+ rake (13.0.1)
14
14
  rspec (3.9.0)
15
15
  rspec-core (~> 3.9.0)
16
16
  rspec-expectations (~> 3.9.0)
@@ -31,7 +31,7 @@ PLATFORMS
31
31
  DEPENDENCIES
32
32
  bundler
33
33
  nokogiri
34
- rake (~> 10.0)
34
+ rake (>= 12.3.3)
35
35
  rspec
36
36
  soccer-quiz!
37
37
 
data/README.md CHANGED
@@ -7,20 +7,9 @@ Take this quiz of 10 questions.
7
7
 
8
8
 
9
9
  ## Installation
10
+ Install it yourself as:
10
11
 
11
- Add this line to your application's Gemfile:
12
-
13
- ```ruby
14
- gem 'quiz'
15
- ```
16
-
17
- And then execute:
18
-
19
- $ bundle install
20
-
21
- Or install it yourself as:
22
-
23
- $ gem install quiz
12
+ $ gem install soccer-quiz
24
13
 
25
14
  ## Usage
26
15
 
@@ -36,7 +25,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
36
25
 
37
26
  ## Contributing
38
27
 
39
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/quiz. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/quiz/blob/master/CODE_OF_CONDUCT.md).
28
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yarvinh/quiz_app. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/yarvinh/quiz_app/blob/master/CODE_OF_CONDUCT.md).
40
29
 
41
30
 
42
31
  ## License
data/bin/console CHANGED
@@ -5,7 +5,7 @@ require "quiz"
5
5
 
6
6
  # (If you use this, don't forget to add pry to your Gemfile!)
7
7
  # require "pry"
8
- # Pry.start
8
+ # Pry.start
9
9
 
10
10
  require "irb"
11
11
  IRB.start(__FILE__)
data/bin/quiz CHANGED
@@ -1,3 +1,29 @@
1
1
  #!/usr/bin/env ruby
2
- require_relative '../lib/quiz'
3
- Quiz::CLI.new.call
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'quiz' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ bundle_binstub = File.expand_path("../bundle", __FILE__)
16
+
17
+ if File.file?(bundle_binstub)
18
+ if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
19
+ load(bundle_binstub)
20
+ else
21
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
22
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
23
+ end
24
+ end
25
+
26
+ require "rubygems"
27
+ require "bundler/setup"
28
+
29
+ load Gem.bin_path("soccer-quiz", "quiz")
@@ -5,7 +5,7 @@ class Quiz::CHAMPIONLEAGUE
5
5
  @@all << self
6
6
  file.each{|key,value|
7
7
  self.send("#{key}=", value)}
8
-
8
+
9
9
  end
10
10
  def self.champion_league_files(file)
11
11
  file.each{|e|Quiz::CHAMPIONLEAGUE.new(e)}
data/lib/quiz/cli.rb CHANGED
@@ -1,43 +1,35 @@
1
1
 
2
2
  class Quiz::CLI
3
3
  @@points = []
4
+ def initialize
5
+ end
4
6
  def call
5
7
  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)
8
+ start_quiz
23
9
  end
24
10
 
25
- def start_quiz(balon_d_or,champion_league,world_cup)
11
+ def start_quiz
12
+ puts "*************************************************************************"
26
13
  puts "Take this 10 question quiz to find out how much you know about soccer."
14
+ puts "*************************************************************************"
27
15
  puts "You pass the test if you score 6 or more points."
16
+ puts "*************************************************************************"
28
17
  puts "To take the quiz press enter, to exit press 1 and enter."
29
18
  input = gets
19
+
20
+
30
21
  while input.to_i != 1
31
- question_processor(balon_d_or,champion_league,world_cup)
22
+ question_processor
32
23
  puts "To take the quiz one more time press enter. to exit press 1 and enter."
33
24
  input = gets
34
25
  end
26
+ puts "Thanks for playing Soccer quiz."
35
27
  end
36
28
 
37
29
  def multiple_choice(answer,winners)
38
30
  multiple_choice = []
39
31
  multiple_choice << answer
40
- until multiple_choice.size == 4
32
+ until multiple_choice.size == 4
41
33
  multiple_choice << winners.sample
42
34
  multiple_choice = multiple_choice.uniq
43
35
  end
@@ -57,48 +49,52 @@ class Quiz::CLI
57
49
  else
58
50
  puts "Wrong. Right answer is #{multiple_choice.index(answer) + 1}: #{answer}."
59
51
  end
60
- puts "Press enter for next question"
52
+ puts "Press enter to continue"
61
53
  gets
62
54
  end
63
55
 
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)
56
+ def question_selector(objects,question)
57
+ years = objects.map{|item| item.year}
58
+ winners = objects.map{|item|item.winner}
59
+ hosts = objects.map{|item|item.host}
60
+ runner_ups = objects.map{|item|item.runner_up}
61
+ random_year = years.sample
62
+ random_winner = winners.sample
63
+
64
+ instace_for_answers = objects.select{|item|item.year == random_year}
65
+
66
+ answer_for_how_many = objects.select{|item|item.winner == random_winner}.size
67
+
68
+ winner = instace_for_answers[0].winner
69
+
70
+ host = instace_for_answers[0].host
71
+ runner_up = instace_for_answers[0].runner_up
72
+
73
+ if all_question("none",random_year)[question].include?("host")
74
+ puts all_question(host,random_year)[question]
75
+ multiple_choice(host,hosts)
76
+ elsif all_question("none",random_year)[question].include?("runner-up")
77
+ runner_ups = runner_ups.reject{|item| item == winner}
78
+ puts all_question(winner,random_year)[question]
79
+ multiple_choice(runner_up,runner_ups)
84
80
  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
81
+ puts all_question(random_winner,'none')[question]
82
+ obtions = []
83
+ counter = 1
84
+ while obtions.size < 13
85
+ obtions << counter
86
+ counter += 1
91
87
  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
88
+ multiple_choice(answer_for_how_many,obtions)
89
+ else
90
+ puts all_question(winner,random_year)[question]
91
+ multiple_choice(winner,winners)
92
+ end
93
+ end
98
94
 
99
95
  def all_question(team, year)
100
96
  ["Who won the world cup in #{year}?",
101
- "Who was the host in #{year} world cup",
97
+ "Who was the host in #{year} world cup?",
102
98
  "#{team} won the World cup final in #{year}. Who was the runner-up?",
103
99
  "How many world cup #{team} has won?",
104
100
  "Who won the champion leage in #{year}?",
@@ -109,51 +105,51 @@ class Quiz::CLI
109
105
  "How many Champion league #{team} has won?"
110
106
  ]
111
107
  end
108
+
112
109
 
113
-
114
- def question_processor(balon_d_or,champion_leage,world_cup)
110
+ def question_processor
111
+ Quiz::CHAMPIONLEAGUE.champion_league_files(Quiz::Scraper.champion_league)
112
+ Quiz::Worldcup.world_cup_file(Quiz::Scraper.world_cup)
113
+ Quiz::BALONDOR.balon_d_or(Quiz::Scraper.balon_d_or_players)
114
+ champion_league = Quiz::CHAMPIONLEAGUE.all
115
+ world_cup = Quiz::Worldcup.all
116
+ balon_d_or = Quiz::BALONDOR.all
115
117
  last_20_champions = []
116
118
  counter = 44
117
- while counter < champion_leage.size
118
- last_20_champions << champion_leage[counter]
119
+ while counter < champion_league.size
120
+ last_20_champions << champion_league[counter]
119
121
  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
122
  end
123
+ question_selector(world_cup,0)
124
+ question_selector(world_cup,1)
125
+ question_selector(world_cup,2)
126
+ question_selector(world_cup,3)
127
+ question_selector(last_20_champions,4)
128
+ question_selector(last_20_champions,5)
129
+ question_selector(last_20_champions,6)
130
+ question_selector(balon_d_or,7)
131
+ question_selector(balon_d_or,8)
132
+ question_selector(champion_league,9)
133
+ points = 0
134
+ @@points.each{|i|points += i }
135
+ if points > 5
136
+ puts "Congratulation you score #{points} of 10 points."
137
+ else puts "Sorry you failed. you score #{points} of 10 points."
138
+ end
139
+ Quiz::CLI.clear
140
+ end
141
+
142
+
143
+
150
144
 
151
145
  def self.points
152
146
  @@points
153
147
  end
148
+
154
149
  def self.clear
155
150
  @@points.clear
156
- end
151
+ end
152
+
157
153
  end
158
154
 
159
155
 
@@ -161,3 +157,5 @@ end
161
157
 
162
158
 
163
159
 
160
+
161
+
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(url,clas)
9
- players = self.scraper(url,clas).map{|l|l.text.split(/\t|\*/).reject{|e|e.empty? || e.include?("(FIFA Balón de Oro)")}}
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,8 +23,10 @@ class Quiz::Scraper
19
23
  end
20
24
 
21
25
 
22
- def self.world_cup(url,clas)
23
- world_cup = self.scraper(url,clas).map{|l|l.text.split(/\r\n|\s{2,}/).reject{|e|e.empty?}}
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
@@ -30,12 +36,17 @@ class Quiz::Scraper
30
36
  all_countries
31
37
  end
32
38
 
33
- def self.champion_league(url,clas)
34
- champions = self.scraper(url,clas).map{|l|l.text.split("\n").reject{|e|e.empty?}}
35
- 2.times{champions.shift}
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
+
43
+ champions = self.scraper(champion_league_url,champion_league_file).map{|l|l.text.split("\n").reject{|e|e.empty?}}
44
+ champions[0].shift
45
+ champions.shift
46
+ champions.shift
36
47
  10.times{champions[0].shift}
37
- 22.times{champions[0].pop}
38
- champions[0].map{|item|item.strip}
48
+ 23.times{champions[0].pop}
49
+ 7.times{champions[0].delete_at(145)}
39
50
  counter = 0
40
51
  all_teams = []
41
52
  while counter < champions[0].size
@@ -46,4 +57,3 @@ class Quiz::Scraper
46
57
  end
47
58
  end
48
59
 
49
-
data/lib/quiz/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Quiz
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.5"
3
3
  end
data/quiz.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.executables << "quiz"
19
19
  spec.add_development_dependency "bundler"
20
20
  spec.add_development_dependency "rspec"
21
- spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "rake", ">= 12.3.3"
22
22
  spec.add_development_dependency "nokogiri"
23
23
  # spec.add_development_dependency "pry"
24
24
  end
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.1
4
+ version: 0.1.5
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-05-31 00:00:00.000000000 Z
11
+ date: 2021-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: 12.3.3
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: 12.3.3
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: nokogiri
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -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.3
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: []