standings 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Y2QzYTA3YzM1ZjdkMTkyZWZiNDc0ZGRhZWMzYjEzNzU2NDlmZDdiNw==
5
+ data.tar.gz: !binary |-
6
+ MjhiNmQ2MGUyYjZlZmFjZTA4MWRkN2FmNDcwNGI3MmZhMTAzOGI2OQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ MTc3MWZjZDZkZDIzOWQ4YWUzMjhmZjhjNWNjNjIwZGJiMWJlZDc4YTFiNzBh
10
+ MzM1YWY0NWYyZmE4MDY1MmJlM2I5MzdiYTljYzg3NmJkM2ZkOGNmM2JlMTE5
11
+ NGIyZDU3Zjg1NmIyZGNhNjk5MDg0Y2JmNmNkMmMzMGFjMzJkMWY=
12
+ data.tar.gz: !binary |-
13
+ OGUyZDg1ZTMzY2U1OTA5ZWE0ZGJkNWM4OGVhOGI3MDAwMTJiYWI3NmNmNWRl
14
+ ZmMzYzE5ZjlkZjhiZTEwOWI5NDVhZWYzM2VkZWQwMmRhNjI1ZmY3YzliNzkz
15
+ MWI5OWRhM2I2YjE3NTA0YjM0ZmI2ZGY1N2UxNTQ3ODM4OWRkNTg=
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'standings'
@@ -0,0 +1,11 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+ require 'colorize'
4
+ require 'pry'
5
+
6
+ Dir.foreach("./lib/") do |file|
7
+ next if file.start_with?('.')
8
+ require_relative "../lib/#{file}" if file.end_with?(".rb")
9
+ end
10
+
11
+ Displayer.new.call
@@ -0,0 +1,27 @@
1
+ class Displayer
2
+
3
+ def call
4
+ TableScraper.new.call
5
+ display_table
6
+ end
7
+
8
+ def template(team)
9
+ string = "#{(team.position).ljust(3," ")} #{team.played.ljust(3, " ")} #{team.points.ljust(5, " ")}"
10
+ if team.position.to_i <= 4
11
+ string += team.name.green
12
+ elsif team.position.to_i >= 18
13
+ string += team.name.red
14
+ else
15
+ string += team.name
16
+ end
17
+ puts string
18
+ end
19
+
20
+ def display_table
21
+ puts "-" * 28
22
+ puts "# P Pts Team"
23
+ puts "-" * 28
24
+ Team.all.each { |team| template(team) }
25
+ end
26
+
27
+ end
@@ -0,0 +1,2 @@
1
+ require_relative '../config/environment'
2
+ Displayer.new
@@ -0,0 +1,26 @@
1
+ class TableScraper
2
+
3
+ attr_accessor :url, :teams
4
+
5
+ def initialize
6
+ @url = "http://www.theguardian.com/football/premierleague/table"
7
+ end
8
+
9
+ def call
10
+ site = Nokogiri::HTML(open(self.url))
11
+ self.teams = site.css('.table-football-body tr')[3..-1]
12
+ build_teams
13
+ end
14
+
15
+ def build_teams
16
+ teams.length.times do |i|
17
+ source = teams[i].children
18
+ Team.new({
19
+ :name => source[2].children[-1].children.text,
20
+ :played => source[4].children.text,
21
+ :points => source[-2].text,
22
+ :position => source[0].children.text
23
+ })
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ class Team
2
+ attr_accessor :name, :position, :played, :points
3
+
4
+ @@teams = []
5
+
6
+ def initialize(info)
7
+ @name = info[:name]
8
+ @played = info[:played]
9
+ @points = info[:points]
10
+ @position = info[:position]
11
+ @@teams << self
12
+ end
13
+
14
+ def self.all
15
+ @@teams
16
+ end
17
+
18
+ end
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: standings
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Scott Luptowski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2010-10-21 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: View the current table of the Barclays Premier League from your terminal
14
+ email: scottluptowski@gmail.com
15
+ executables:
16
+ - standings
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - config/environment.rb
21
+ - lib/displayer.rb
22
+ - lib/standings.rb
23
+ - lib/table_scraper.rb
24
+ - lib/team.rb
25
+ - bin/standings
26
+ homepage: http://www.scottluptowski.com
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.1.4
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: BPL table
50
+ test_files: []