Class: EplCliGem::Team
- Inherits:
-
Object
- Object
- EplCliGem::Team
- Defined in:
- lib/epl_cli_gem/team.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#drawn ⇒ Object
Returns the value of attribute drawn.
-
#games_played ⇒ Object
Returns the value of attribute games_played.
-
#goal_diff ⇒ Object
Returns the value of attribute goal_diff.
-
#lost ⇒ Object
Returns the value of attribute lost.
-
#name ⇒ Object
Returns the value of attribute name.
-
#points ⇒ Object
Returns the value of attribute points.
-
#rank ⇒ Object
Returns the value of attribute rank.
-
#url ⇒ Object
Returns the value of attribute url.
-
#website ⇒ Object
Returns the value of attribute website.
-
#won ⇒ Object
Returns the value of attribute won.
Class Method Summary collapse
Instance Method Summary collapse
- #club_news ⇒ Object
- #doc ⇒ Object
-
#initialize(row, name = nil, rank = nil, url = nil, games_played = nil, won = nil, drawn = nil, lost = nil, goal_diff = nil, points = nil) ⇒ Team
constructor
A new instance of Team.
- #match_date ⇒ Object
- #match_time ⇒ Object
- #team_1 ⇒ Object
- #team_2 ⇒ Object
Constructor Details
#initialize(row, name = nil, rank = nil, url = nil, games_played = nil, won = nil, drawn = nil, lost = nil, goal_diff = nil, points = nil) ⇒ Team
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/epl_cli_gem/team.rb', line 29 def initialize(row, name=nil, rank=nil, url=nil, games_played=nil, won=nil, drawn=nil, lost=nil, goal_diff=nil, points=nil) @nodeset = row @name = name @rank = rank @url = url @games_played = games_played @won = won @drawn = drawn @lost = lost @goal_diff = goal_diff @points = points @@all << self unless @@all.include?(self.name) end |
Instance Attribute Details
#drawn ⇒ Object
Returns the value of attribute drawn.
3 4 5 |
# File 'lib/epl_cli_gem/team.rb', line 3 def drawn @drawn end |
#games_played ⇒ Object
Returns the value of attribute games_played.
3 4 5 |
# File 'lib/epl_cli_gem/team.rb', line 3 def games_played @games_played end |
#goal_diff ⇒ Object
Returns the value of attribute goal_diff.
3 4 5 |
# File 'lib/epl_cli_gem/team.rb', line 3 def goal_diff @goal_diff end |
#lost ⇒ Object
Returns the value of attribute lost.
3 4 5 |
# File 'lib/epl_cli_gem/team.rb', line 3 def lost @lost end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/epl_cli_gem/team.rb', line 3 def name @name end |
#points ⇒ Object
Returns the value of attribute points.
3 4 5 |
# File 'lib/epl_cli_gem/team.rb', line 3 def points @points end |
#rank ⇒ Object
Returns the value of attribute rank.
3 4 5 |
# File 'lib/epl_cli_gem/team.rb', line 3 def rank @rank end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/epl_cli_gem/team.rb', line 3 def url @url end |
#website ⇒ Object
Returns the value of attribute website.
3 4 5 |
# File 'lib/epl_cli_gem/team.rb', line 3 def website @website end |
#won ⇒ Object
Returns the value of attribute won.
3 4 5 |
# File 'lib/epl_cli_gem/team.rb', line 3 def won @won end |
Class Method Details
.all ⇒ Object
43 44 45 |
# File 'lib/epl_cli_gem/team.rb', line 43 def self.all @@all end |
.make_teams ⇒ Object
7 8 9 10 |
# File 'lib/epl_cli_gem/team.rb', line 7 def self.make_teams @@table ||= EplCliGem::Scraper.new.scrape_table @@table.each{|row| self.new_from_table(row)} end |
.new_from_table(row) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/epl_cli_gem/team.rb', line 12 def self.new_from_table(row) self.new( row, #=> self.nodeset: data from scrape, needed for various methods requiring scraped data row.css("span.long").text, #=> self.name row.css("span.value").text, #=> self.rank "https://www.premierleague.com#{row.css("a").attribute("href").text}", #=> self.url row.css("td[4]").text, #=> self.games_played row.css("td[5]").text, #=> self.won row.css("td[6]").text, #=> self.drawn row.css("td[7]").text, #=> self.lost row.css("td[10]").text.strip, #=> self.goal_diff row.css("td.points").text #=> self.points ) end |
.sorted ⇒ Object
47 48 49 |
# File 'lib/epl_cli_gem/team.rb', line 47 def self.sorted @@all.sort_by!{|team| team.rank.to_i} end |
Instance Method Details
#club_news ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/epl_cli_gem/team.rb', line 98 def club_news rows = [] @news ||= doc.css("div.sidebarPush section")[1].css("li") @news.each do |li| rows << [li.css('span.title').text] rows << :separator end table = Terminal::Table.new :title => "Latest Club News\nRead more at #{self.website}", :rows => rows table.align_column 0, :center puts table end |
#doc ⇒ Object
90 91 92 |
# File 'lib/epl_cli_gem/team.rb', line 90 def doc @doc ||= Nokogiri::HTML(open(self.url)) end |
#match_date ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/epl_cli_gem/team.rb', line 51 def match_date # matches are sometimes pending due to scheduling, if statement in place # to stop NoMethodError from .text when there is no text to return if @nodeset.css("td.nextMatchCol span.matchInfo").text != "" @match_date = @nodeset.css("td.nextMatchCol span.matchInfo").text else "To Be Determined" end end |
#match_time ⇒ Object
81 82 83 84 85 86 87 88 |
# File 'lib/epl_cli_gem/team.rb', line 81 def match_time # matches are sometimes pending due to scheduling, if statement in place # to stop NoMethodError from .text when there is no text to return if @nodeset.css("td.nextMatchCol time").text != "" @match_time = @nodeset.css("td.nextMatchCol time").text end end |
#team_1 ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/epl_cli_gem/team.rb', line 63 def team_1 # matches are sometimes pending due to scheduling, if statement in place # to stop NoMethodError from .text when there is no text to return if @nodeset.css("td.nextMatchCol span.teamName")[0] != nil @team_1 = @nodeset.css("td.nextMatchCol span.teamName")[0].text end end |
#team_2 ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/epl_cli_gem/team.rb', line 72 def team_2 # matches are sometimes pending due to scheduling, if statement in place # to stop NoMethodError from .text when there is no text to return if @nodeset.css("td.nextMatchCol span.teamName")[1] != nil @team_2 = @nodeset.css("td.nextMatchCol span.teamName")[1].text end end |