cricketer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 800eb22170e5592ae475a1dff4a68889a25d74df
4
+ data.tar.gz: c58c5fe6430bec592732bb88de24d5ea11be732b
5
+ SHA512:
6
+ metadata.gz: 2ce3876cd92f6288fe9b18a62673de3226e9c2b8162898630e1f6271c8acf7d5aac75225e87c994b74f940f9218ac0726e677b6240c267d996365b35efec967d
7
+ data.tar.gz: 1f954f9582e535a9105d62c2d6ef3a1b616e93c2a6f0b8e857e98d5bd32a779ff8aaae6f7ff09268404c9cf5b73c028f5a0943269280c50b8151a277f763afae
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ..gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Derek Willis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Cricketer
2
+
3
+ Cricketer is a Ruby gem for parsing cricket match JSON from ESPNCricinfo.com. It is not intended for commercial use.
4
+
5
+ Cricketer currently creates Ruby objects for some, but not all, of the JSON data available for a given match. These include information about the score, the current (or latest) status of the match, the players, the ground and some game details. Future versions will have more objects, but the current version provides the raw JSON of all match data published.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'cricketer'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install cricketer
22
+
23
+ ## Usage
24
+
25
+ To use Cricketer, you need to know the ID number of a match from espncricinfo.com. For example, the ID for [this match](http://www.espncricinfo.com/icc-cricket-world-cup-2015/engine/match/656399.html) is 656399. Pass that ID into the `Match` constructor:
26
+
27
+ ```ruby
28
+ irb(main):001:0> require 'cricketer'
29
+ irb(main):002:0> match = Cricketer::Match.new(656399)
30
+ irb(main):003:0> match.description
31
+ => "ICC Cricket World Cup, 1st Match, Pool A: New Zealand v Sri Lanka at Christchurch, Feb 14, 2015"
32
+ irb(main):004:0> match.current_status
33
+ => "New Zealand won by 98 runs"
34
+ irb(main):005:0> match.team1
35
+ => #<OpenStruct name="New Zealand", id="5", abbrev="NZ">
36
+ ```
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it ( https://github.com/dwillis/cricketer/fork )
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/cricketer.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "cricketer"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Derek Willis"]
9
+ spec.email = ["dwillis@gmail.com"]
10
+ spec.summary = %q{A Ruby library for parsing data from ESPN's Cricinfo site.}
11
+ spec.description = %q{Parses live scores and game data.}
12
+ spec.homepage = "https://github.com/dwillis/cricketer"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ end
data/lib/cricketer.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "version"
2
+ require "match"
3
+ require 'open-uri'
4
+ require 'ostruct'
5
+ require 'json'
6
+
7
+ module Cricketer
8
+
9
+
10
+ end
data/lib/match.rb ADDED
@@ -0,0 +1,81 @@
1
+ module Cricketer
2
+ class Match
3
+
4
+ attr_reader :match_id, :json_url, :match_data, :description, :summary, :innings, :officials, :team1, :team2,
5
+ :team1_players, :team2_players, :current_status, :innings, :team1_innings, :team2_innings, :ground,
6
+ :floodlit, :batted_first, :winning_team, :cancelled, :result
7
+
8
+ def initialize(match_id)
9
+ @match_id = match_id
10
+ @json_url = "http://www.espncricinfo.com/matches/engine/match/#{match_id}.json"
11
+ @match_data = JSON.parse(open(@json_url).read)
12
+ @description = @match_data['description']
13
+ @summary = OpenStruct.new(@match_data['match'])
14
+ @team1 = OpenStruct.new(name: @summary.team1_name, id: @summary.team1_id, abbrev: @summary.team1_abbreviation)
15
+ @team2 = OpenStruct.new(name: @summary.team2_name, id: @summary.team2_id, abbrev: @summary.team2_abbreviation)
16
+ @innings = @match_data['innings'].map{|i| OpenStruct.new(i)}
17
+ @officials = @match_data['official'].map{|o| OpenStruct.new(o)}
18
+ end
19
+
20
+ def to_s
21
+ @description
22
+ end
23
+
24
+ def current_status
25
+ @match_data['live']['status']
26
+ end
27
+
28
+ def innings
29
+ @match_data['innings'].map{|i| OpenStruct.new(i)}
30
+ end
31
+
32
+ def result
33
+ @summary.result == "1" ? true : false
34
+ end
35
+
36
+ def team1_innings
37
+ innings.select{|i| i.batting_team_id == @team1.id}
38
+ end
39
+
40
+ def cancelled
41
+ @summary.cancelled_match == 'N' ? false : true
42
+ end
43
+
44
+ def ground
45
+ @summary.ground_name
46
+ end
47
+
48
+ def floodlit
49
+ @summary.floodlit == "1" ? true : false
50
+ end
51
+
52
+ def batted_first
53
+ @summary.batting_first_team_id == @team1.id ? @team1 : @team2
54
+ end
55
+
56
+ def followon
57
+ @summary.followon == "1" ? true : false
58
+ end
59
+
60
+ def winning_team
61
+ if @match_data['match']['winner_team_id'] == @team1.id
62
+ @team1
63
+ elsif @match_data['match']['winner_team_id'] == @team2.id
64
+ @team2
65
+ else
66
+ nil
67
+ end
68
+ end
69
+
70
+ def team1_players
71
+ @match_data['team'].detect{|t| t['team_name'] == @team1.name}['player'].map{|p| OpenStruct.new(p)}
72
+ end
73
+
74
+ def team2_players
75
+ @match_data['team'].detect{|t| t['team_name'] == @team2.name}['player'].map{|p| OpenStruct.new(p)}
76
+ end
77
+
78
+
79
+
80
+ end
81
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module Cricketer
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cricketer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Derek Willis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Parses live scores and game data.
42
+ email:
43
+ - dwillis@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - cricketer.gemspec
54
+ - lib/cricketer.rb
55
+ - lib/match.rb
56
+ - lib/version.rb
57
+ homepage: https://github.com/dwillis/cricketer
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.2.2
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: A Ruby library for parsing data from ESPN's Cricinfo site.
81
+ test_files: []