scoreboard 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 46b13a3848e181c9022451023003644ee1bfe922
4
+ data.tar.gz: c29ba7dc9ee0656ce0840f0b9823aef2a246b98b
5
+ SHA512:
6
+ metadata.gz: ce881be5e37276cd5f2008df36f61c831e9cf6477b1711d16e37f225de801a55e0674b03e5da7fc1d64f9aa0a811e665cdb365520c4ec2b11d186a7bd719b909
7
+ data.tar.gz: aa4695d5433a4b8b2bfb4af89cf9dbf9cb1fb924beaaaf94924ba64db4020075f34a8be09c2084659e9ee31b040d0e74f7c2ac2ef557974064d1826554eb4b86
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1 @@
1
+ 2.2.3
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+ ruby "2.2.3"
3
+
4
+ # Specify your gem's dependencies in scoreboard.gemspec
5
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Josh Bavari
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,14 @@
1
+ [![Code Climate](https://codeclimate.com/github/jbavari/scoreboard-cli/badges/gpa.svg)](https://codeclimate.com/github/jbavari/scoreboard-cli) [![Test Coverage](https://codeclimate.com/github/jbavari/scoreboard-cli/badges/coverage.svg)](https://codeclimate.com/github/jbavari/scoreboard-cli/coverage)
2
+
3
+
4
+
5
+ # Scoreboard
6
+
7
+ To get started, clone this repo.
8
+
9
+ ```
10
+ bundle install
11
+ bin/scoreboard
12
+ ```
13
+
14
+ Score your teams.
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "scoreboard"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/scoreboard/cli"
4
+
5
+ begin
6
+ cli = Scoreboard::Cli.new
7
+ cli.start(ARGV)
8
+ rescue => e
9
+ raise e if $DEBUG
10
+ STDERR.puts e.message
11
+ STDERR.puts e.backtrace.join("\n")
12
+ exit 1
13
+ end
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1 @@
1
+ require "scoreboard/version"
@@ -0,0 +1,24 @@
1
+ require "net/http"
2
+ require "uri"
3
+
4
+ module Scoreboard
5
+ class Api
6
+ def self.dashboard_url
7
+ "http://localhost:3030/scoreboard"
8
+ end
9
+
10
+ def self.send_data(data)
11
+ uri = URI.parse("http://localhost:9393/api/v1/results")
12
+
13
+ # Shortcut
14
+ response = Net::HTTP.post_form(
15
+ uri,
16
+ "home_team" => data.home_team.name,
17
+ "home_score" => data.home_team.score,
18
+ "visitor_team" => data.visitor_team.name,
19
+ "visitor_score" => data.visitor_team.score
20
+ )
21
+ response.code == 200
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,92 @@
1
+ require "thor"
2
+ require_relative "./api"
3
+ require_relative "./football_scoreboard"
4
+ require_relative "./team"
5
+
6
+ module Scoreboard
7
+ class Cli < Thor
8
+ attr_reader :football_scoreboard
9
+ no_commands do
10
+ def initialize
11
+ @football_scoreboard = Scoreboard::FootballScoreboard.new
12
+ end
13
+ end
14
+ # Doing this a second time to avoid warnings. attr_reader may mess with it.
15
+ no_commands do
16
+ def print_initial_output
17
+ puts "We're starting the game - #{football_scoreboard.home_team.name} vs #{football_scoreboard.visitor_team.name}"
18
+ puts ""
19
+ puts "Record your scores! Input in the format of <team>:<score_type>"
20
+ puts "Where <team> is h for home team, and v for visitor team"
21
+ puts ""
22
+ puts "Example: h:fg => home team, field goal (3 points)"
23
+ puts "Example: v:td => visitor team, touch down (7 points)"
24
+
25
+ puts ""
26
+ puts "End the game with CTRL+D"
27
+ end
28
+
29
+ def collect_team_input
30
+ puts "Enter Home Team"
31
+ football_scoreboard.home_team.name = $stdin.readline.sub("\n", "")
32
+
33
+ puts "Enter Team 2 Name"
34
+ football_scoreboard.visitor_team.name = $stdin.readline.sub("\n", "")
35
+ end
36
+
37
+ def begin_reading_scores
38
+ begin
39
+ STDIN.each_line do |str|
40
+ input = str.sub("\n", "").split(":")
41
+ team = input[0] == "h" ? football_scoreboard.home_team : football_scoreboard.visitor_team
42
+ adjust_team_score(team, input[1])
43
+
44
+ puts "Scoreboard: #{football_scoreboard.score}"
45
+ end
46
+ # rubocop:disable UselessAssignment
47
+ rescue Exception => ex
48
+ # Only way to continue from here is just catch an Exception.
49
+ # Ignore Rubocop warning, unfortunately catching only StandardError
50
+ # doesnt rescue from the error.
51
+ puts "You've ended the game!"
52
+ end
53
+
54
+ end_game
55
+ end
56
+
57
+ def end_game
58
+ puts "Thanks for playing! Were sending the game data."
59
+ Api.send_data(football_scoreboard)
60
+ show_dashboard_url
61
+ end
62
+
63
+ def show_dashboard_url
64
+ puts "View the scoreboard dashboard: #{Api.dashboard_url}"
65
+ puts "Weve sent your scoreboard data to our servers! Thanks for submitting!"
66
+ end
67
+
68
+ def adjust_team_score(team, score_type)
69
+ case score_type
70
+ when "fg"
71
+ puts "Field Goal, #{team.name}!"
72
+ team.field_goal
73
+ when "td"
74
+ puts "Touch down, #{team.name}!"
75
+ team.touchdown
76
+ end
77
+ end
78
+ end
79
+
80
+ desc "Entry point for CLI", "Pass visitor and home teams with a flag"
81
+ def start(_args)
82
+ collect_team_input
83
+ print_initial_output
84
+
85
+ begin
86
+ begin_reading_scores
87
+ rescue StandardError => ex
88
+ puts "The game has ended. Final scores: #{football_scoreboard.score} - #{ex}"
89
+ end
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,17 @@
1
+ module Scoreboard
2
+ class FootballScoreboard
3
+ attr_reader :home_team, :visitor_team
4
+ def initialize
5
+ @home_team = Team.new
6
+ @visitor_team = Team.new
7
+ end
8
+
9
+ def teams
10
+ {:home_team => @home_team, :visitor_team => @visitor_team}
11
+ end
12
+
13
+ def score
14
+ "#{home_team.name} - #{home_team.score}, #{visitor_team.name} - #{visitor_team.score}"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ module Scoreboard
2
+ class Team
3
+ attr_reader :name, :score
4
+ attr_writer :name, :score
5
+ def initialize
6
+ @score = 0
7
+ @name = "NA"
8
+ end
9
+
10
+ def field_goal
11
+ @score += 3
12
+ end
13
+
14
+ def touchdown
15
+ @score += 7
16
+ end
17
+
18
+ def to_s
19
+ "Team name: #{@name} - Score: #{@score}"
20
+ end
21
+
22
+ def inspect
23
+ to_s
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module Scoreboard
2
+ VERSION = "0.1.1"
3
+ end
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'scoreboard/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "scoreboard"
8
+ spec.version = Scoreboard::VERSION
9
+ spec.authors = ["Josh Bavari"]
10
+ spec.email = ["jbavari@gmail.com"]
11
+
12
+ spec.summary = %q{A commane line interface to conduct a scoreboard and report data to an API}
13
+ spec.description = %q{Start this command line tool, enter your home and visitor team, then start taking scores to see which team wins.}
14
+ spec.homepage = "http://jbavari.github.io"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "bin"
27
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_dependency 'thor', '0.19.1'
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.10"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "minitest"
35
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scoreboard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Josh Bavari
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Start this command line tool, enter your home and visitor team, then
70
+ start taking scores to see which team wins.
71
+ email:
72
+ - jbavari@gmail.com
73
+ executables:
74
+ - console
75
+ - scoreboard
76
+ - setup
77
+ extensions: []
78
+ extra_rdoc_files: []
79
+ files:
80
+ - ".gitignore"
81
+ - ".ruby-version"
82
+ - ".travis.yml"
83
+ - Gemfile
84
+ - LICENSE.txt
85
+ - README.md
86
+ - Rakefile
87
+ - bin/console
88
+ - bin/scoreboard
89
+ - bin/setup
90
+ - lib/scoreboard.rb
91
+ - lib/scoreboard/api.rb
92
+ - lib/scoreboard/cli.rb
93
+ - lib/scoreboard/football_scoreboard.rb
94
+ - lib/scoreboard/team.rb
95
+ - lib/scoreboard/version.rb
96
+ - scoreboard.gemspec
97
+ homepage: http://jbavari.github.io
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.4.8
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: A commane line interface to conduct a scoreboard and report data to an API
121
+ test_files: []