nba_today_gem 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fbd6cab7302ef20c4a2d72c2de14d831f2984ee7
4
- data.tar.gz: a6b546b2ef6c291f339310d5b45b468a0e376a86
3
+ metadata.gz: 92738c0f70df56ff85d89d22ce146236936db595
4
+ data.tar.gz: 6d6ec54cd022d8b468bfe25bb818383f6178a3dd
5
5
  SHA512:
6
- metadata.gz: 5abe31aa45f83239f71ede711c01ab359a36db355e27a7d4c4253932a4f484794763b5d0bee6e36355641bacd819bacddd323b6ab4ee9da0eeb0e2cd46835bc3
7
- data.tar.gz: 943c367c3ef6c66732bfd016cee1f1bc25f414376a38603efb7faae5cae2d3bcd6789c21845d08fd8bc03288539bfb525ecad7f15ebce3b7dbabf6ae9b38d0be
6
+ metadata.gz: 72f9f028e0d8b84fa61aefdd2e90f8409950e10f707230dac7916d5d1858f8b08bb78f4c8ad8de1755acdea1a58de25aa85e12d28e66fae52842aae2a1123e4f
7
+ data.tar.gz: 5f05587b4edad5142b1eb6cdd13ac7aac85c592b9b46e93b719bae01dbdf77a26ef2d68a3a19aa85077aff1da1a3e65ec4a045f2c176eda4e3a45e796053925b
@@ -1,7 +1,7 @@
1
1
  class NbaTodayGem::CommandLine
2
2
  include CommandLineReporter
3
3
 
4
- attr_reader :games
4
+ #attr_reader :games
5
5
 
6
6
  def call
7
7
  puts "Hello, Welcome to the NBA Today Gem!"
@@ -28,12 +28,12 @@ class NbaTodayGem::CommandLine
28
28
  end
29
29
 
30
30
  def list_games
31
- if !self.games
32
- @games = NbaTodayGem::Scraper.new.scrape_nba_scores
31
+ if NbaTodayGem::Game.all.size == 0
32
+ NbaTodayGem::Scraper.new.scrape_nba_scores
33
33
 
34
34
  header :title => 'NBA SCORES', :width => 75, :align => 'center', :rule => true, :color => 'green', :bold => true, :timestamp => true
35
35
 
36
- self.games.each.with_index(1) do |game, index|
36
+ NbaTodayGem::Game.all.each.with_index(1) do |game, index|
37
37
  table(:border => true) do
38
38
  row do
39
39
  column('GAME NUM.', :width => 10, :align => 'center')
@@ -55,7 +55,7 @@ class NbaTodayGem::CommandLine
55
55
  else
56
56
  header :title => 'NBA SCORES', :width => 50, :align => 'center', :rule => true, :color => 'green', :bold => true, :timestamp => true
57
57
 
58
- self.games.each.with_index(1) do |game, index|
58
+ NbaTodayGem::Game.all.each.with_index(1) do |game, index|
59
59
  table(:border => true) do
60
60
  row do
61
61
  column('GAME NUM.', :width => 5)
@@ -92,8 +92,10 @@ class NbaTodayGem::CommandLine
92
92
  if game_no == "list games"
93
93
  list_games
94
94
  pick_game_menu
95
- elsif game_no.to_i > 0 && game_no.to_i <= self.games.length
95
+ elsif game_no.to_i > 0 && game_no.to_i <= NbaTodayGem::Game.all.length
96
96
  index = game_no.to_i - 1
97
+ game = NbaTodayGem::Game.find(index)
98
+ NbaTodayGem::Scraper.scrape_nba_game_info(game)
97
99
  show_game(index)
98
100
  end
99
101
  end
@@ -102,17 +104,17 @@ class NbaTodayGem::CommandLine
102
104
  def show_game(index)
103
105
  table(:border => true) do
104
106
  row do
105
- column(self.games[index].date, :width => 30, :align => 'center')
106
- column(self.games[index].venue, :width => 55, :align => 'center')
107
+ column(NbaTodayGem::Game.all[index].date, :width => 30, :align => 'center')
108
+ column(NbaTodayGem::Game.all[index].venue, :width => 55, :align => 'center')
107
109
  end
108
110
  end
109
111
 
110
112
  puts
111
113
 
112
- if self.games[index].recap != ""
114
+ if NbaTodayGem::Game.all[index].recap != ""
113
115
  table(:border => true) do
114
116
  row do
115
- column(self.games[index].recap, :width => 80, :align => 'center')
117
+ column(NbaTodayGem::Game.all[index].recap, :width => 80, :align => 'center')
116
118
  end
117
119
  end
118
120
 
@@ -128,23 +130,23 @@ class NbaTodayGem::CommandLine
128
130
  column('QTR 2', :width => 9, :align => 'center')
129
131
  column('QTR 3', :width => 9, :align => 'center')
130
132
  column('QTR 4', :width => 9, :align => 'center')
131
- column(self.games[index].status, :align => 'center')
133
+ column(NbaTodayGem::Game.all[index].status, :align => 'center')
132
134
  end
133
135
  row do
134
- column(self.games[index].away_team.name)
135
- column(self.games[index].away_team.score[1])
136
- column(self.games[index].away_team.score[2])
137
- column(self.games[index].away_team.score[3])
138
- column(self.games[index].away_team.score[4])
139
- column(self.games[index].away_team.score[0])
136
+ column(NbaTodayGem::Game.all[index].away_team.name)
137
+ column(NbaTodayGem::Game.all[index].away_team.score[1])
138
+ column(NbaTodayGem::Game.all[index].away_team.score[2])
139
+ column(NbaTodayGem::Game.all[index].away_team.score[3])
140
+ column(NbaTodayGem::Game.all[index].away_team.score[4])
141
+ column(NbaTodayGem::Game.all[index].away_team.score[0])
140
142
  end
141
143
  row do
142
- column(self.games[index].home_team.name)
143
- column(self.games[index].home_team.score[1])
144
- column(self.games[index].home_team.score[2])
145
- column(self.games[index].home_team.score[3])
146
- column(self.games[index].home_team.score[4])
147
- column(self.games[index].home_team.score[0])
144
+ column(NbaTodayGem::Game.all[index].home_team.name)
145
+ column(NbaTodayGem::Game.all[index].home_team.score[1])
146
+ column(NbaTodayGem::Game.all[index].home_team.score[2])
147
+ column(NbaTodayGem::Game.all[index].home_team.score[3])
148
+ column(NbaTodayGem::Game.all[index].home_team.score[4])
149
+ column(NbaTodayGem::Game.all[index].home_team.score[0])
148
150
  end
149
151
  end
150
152
 
@@ -153,24 +155,24 @@ class NbaTodayGem::CommandLine
153
155
 
154
156
  table(:border => true) do
155
157
  row do
156
- column("#{self.games[index].away_team.name}", :width => 35, :align => 'center')
158
+ column("#{NbaTodayGem::Game.all[index].away_team.name}", :width => 35, :align => 'center')
157
159
  column('', :align => 'center')
158
- column("#{self.games[index].home_team.name}", :width => 35, :align => 'center')
160
+ column("#{NbaTodayGem::Game.all[index].home_team.name}", :width => 35, :align => 'center')
159
161
  end
160
162
  row do
161
- column("#{self.games[index].top_peformers[:points][0].name}: #{self.games[index].top_peformers[:points][0].points}", :width => 35, :align => 'center')
163
+ column("#{NbaTodayGem::Game.all[index].top_peformers[:points][0].name}: #{NbaTodayGem::Game.all[index].top_peformers[:points][0].points}", :width => 35, :align => 'center')
162
164
  column('POINTS', :align => 'center')
163
- column("#{self.games[index].top_peformers[:points][1].name}: #{self.games[index].top_peformers[:points][1].points}", :width => 35, :align => 'center')
165
+ column("#{NbaTodayGem::Game.all[index].top_peformers[:points][1].name}: #{NbaTodayGem::Game.all[index].top_peformers[:points][1].points}", :width => 35, :align => 'center')
164
166
  end
165
167
  row do
166
- column("#{self.games[index].top_peformers[:rebounds][0].name}: #{self.games[index].top_peformers[:rebounds][0].rebounds}", :width => 35, :align => 'center')
168
+ column("#{NbaTodayGem::Game.all[index].top_peformers[:rebounds][0].name}: #{NbaTodayGem::Game.all[index].top_peformers[:rebounds][0].rebounds}", :width => 35, :align => 'center')
167
169
  column('REBOUNDS', :align => 'center')
168
- column("#{self.games[index].top_peformers[:rebounds][1].name}: #{self.games[index].top_peformers[:rebounds][1].rebounds}", :width => 35, :align => 'center')
170
+ column("#{NbaTodayGem::Game.all[index].top_peformers[:rebounds][1].name}: #{NbaTodayGem::Game.all[index].top_peformers[:rebounds][1].rebounds}", :width => 35, :align => 'center')
169
171
  end
170
172
  row do
171
- column("#{self.games[index].top_peformers[:assists][0].name}: #{self.games[index].top_peformers[:assists][0].assists}", :width => 35, :align => 'center')
173
+ column("#{NbaTodayGem::Game.all[index].top_peformers[:assists][0].name}: #{NbaTodayGem::Game.all[index].top_peformers[:assists][0].assists}", :width => 35, :align => 'center')
172
174
  column('ASSISTS', :align => 'center')
173
- column("#{self.games[index].top_peformers[:assists][1].name}: #{self.games[index].top_peformers[:assists][1].assists}", :width => 35, :align => 'center')
175
+ column("#{NbaTodayGem::Game.all[index].top_peformers[:assists][1].name}: #{NbaTodayGem::Game.all[index].top_peformers[:assists][1].assists}", :width => 35, :align => 'center')
174
176
  end
175
177
  end
176
178
  end
@@ -24,8 +24,21 @@ class NbaTodayGem::Game
24
24
  end
25
25
  end
26
26
 
27
+ def self.find(index)
28
+ @@all[index]
29
+ end
30
+
27
31
  def self.all
28
32
  @@all
29
33
  end
30
34
 
35
+ def totalscore
36
+ self.home_team.score[0].to_i + self.away_team.score[0].to_i
37
+ end
38
+
39
+ def self.sort_by_total_score
40
+ # binding.pry
41
+ NbaTodayGem::Game.all.sort! {|game1, game2| game2.totalscore <=> game1.totalscore}
42
+ end
43
+
31
44
  end
@@ -7,7 +7,7 @@ class NbaTodayGem::Scraper
7
7
  # CommandLineReporter progress
8
8
  self.formatter = 'progress'
9
9
 
10
- @doc = Nokogiri::HTML(open("https://www.msn.com/en-us/sports/nba/scores")).css("div.sectionsgroup div.section")[0..2]
10
+ @doc = Nokogiri::HTML(open("https://www.msn.com/en-us/sports/nba/scores")).css("div.sectionsgroup div.section")[0..3]
11
11
  @games = []
12
12
  end
13
13
 
@@ -39,17 +39,17 @@ class NbaTodayGem::Scraper
39
39
  new_nba_game.home_team.score[3] = game.css("tr:nth-child(2) td:nth-child(7)").text.gsub(/[\n _]/, "") # Quarter 3 score
40
40
  new_nba_game.home_team.score[4] = game.css("tr:nth-child(2) td:nth-child(8)").text.gsub(/[\n _]/, "") # Quarter 4 score
41
41
 
42
- scrape_nba_game_info(new_nba_game)
42
+ # scrape_nba_game_info(new_nba_game)
43
43
 
44
- games << new_nba_game
44
+ #games << new_nba_game
45
45
  # CommandLineReporter progress
46
46
  progress
47
47
  end
48
48
  end
49
- games
49
+ #games
50
50
  end
51
51
 
52
- def scrape_nba_game_info(game)
52
+ def self.scrape_nba_game_info(game)
53
53
  get_game_info = Nokogiri::HTML(open(game.url))
54
54
 
55
55
  game.date = get_game_info.css("#gamematchupsummary div.basicinfo div.datetime.hide1").text
@@ -1,3 +1,3 @@
1
1
  module NbaTodayGem
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nba_today_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio Mendoza
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-11 00:00:00.000000000 Z
11
+ date: 2017-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -107,6 +107,7 @@ files:
107
107
  - lib/nba_today_gem/version.rb
108
108
  - nba_today_gem-0.1.0.gem
109
109
  - nba_today_gem-0.1.1.gem
110
+ - nba_today_gem-0.1.2.gem
110
111
  - nba_today_gem.gemspec
111
112
  - spec.md
112
113
  homepage: https://github.com/smendoza787/nba-today-gem