league_track_abrophy 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 874f5565a63ce9948e221dd4ac7bd06560bed2b78fbbddff685251c350c643c1
4
+ data.tar.gz: ed5c32fb4b3540a4e411d2c31a06cd34573aedb0ca184302e8b8b2f8ee3ba44c
5
+ SHA512:
6
+ metadata.gz: 2c70645ec3d54e23ebed92a3ee27cb8c1f275b75ad267699e15daa277ef58fb44fef67ee51538df2aebcbae25f6990c2f60a42a1e8023d19327b869e95bfc6db
7
+ data.tar.gz: e9d3ae866239805bbbcb89e176a4df281e6d073c73cc554fac0dc3ff3bd825aa7f3b55c53141d171deeea79051ab9207cec8281941082de339175b7eb3f1fb3e
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ league_track_input
14
+
15
+ .idea
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1 @@
1
+ 2.3.1
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at artbrophy@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in league_track_abrophy.gemspec
8
+ gemspec
@@ -0,0 +1,53 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ league_track_abrophy (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ diff-lcs (1.3)
11
+ jaro_winkler (1.5.1)
12
+ parallel (1.12.1)
13
+ parser (2.5.1.2)
14
+ ast (~> 2.4.0)
15
+ powerpack (0.1.2)
16
+ rainbow (3.0.0)
17
+ rake (12.3.1)
18
+ rspec (3.8.0)
19
+ rspec-core (~> 3.8.0)
20
+ rspec-expectations (~> 3.8.0)
21
+ rspec-mocks (~> 3.8.0)
22
+ rspec-core (3.8.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-expectations (3.8.1)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-mocks (3.8.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.8.0)
30
+ rspec-support (3.8.0)
31
+ rubocop (0.59.1)
32
+ jaro_winkler (~> 1.5.1)
33
+ parallel (~> 1.10)
34
+ parser (>= 2.5, != 2.5.1.1)
35
+ powerpack (~> 0.1)
36
+ rainbow (>= 2.2.2, < 4.0)
37
+ ruby-progressbar (~> 1.7)
38
+ unicode-display_width (~> 1.0, >= 1.0.1)
39
+ ruby-progressbar (1.10.0)
40
+ unicode-display_width (1.4.0)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ bundler (~> 1.16.4)
47
+ league_track_abrophy!
48
+ rake (~> 12.3.1)
49
+ rspec (~> 3.8.0)
50
+ rubocop (~> 0.59.1)
51
+
52
+ BUNDLED WITH
53
+ 1.16.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Arthur Brophy
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,145 @@
1
+ # LeagueTrackAbrophy
2
+
3
+ This gem serves as a solution to an OOP problem where it is required to
4
+ build out a class heirarchy to calculate and format the results of a
5
+ football league.
6
+
7
+ ## Installation and Usage
8
+
9
+ There are three ways to install and use the gem:
10
+
11
+ ### clone from github
12
+
13
+ ```
14
+ git clone https://github.com/abrophy/server-side-developer-test.git
15
+ ```
16
+
17
+ after cloning the repo onto your computer, enter the directory and run:
18
+ ```
19
+ bundle install
20
+ ```
21
+ To install the dev dependencies.
22
+
23
+ A sample input file has been provided with the repo as
24
+ `league_track_input.example`.
25
+
26
+ You can then use rake to process this sample input file:
27
+
28
+ ```
29
+ rake run league_track_input.example
30
+ ```
31
+
32
+ simply replace the sample input filename with your own if desired.
33
+
34
+ ### install gem for command line usage
35
+
36
+ The gem is hosted on rubygems so it can be installed to your environment
37
+ through a simple gem install:
38
+
39
+ ```
40
+ gem install league_track_abrophy
41
+ ```
42
+
43
+ to process an input file call from command line via
44
+
45
+ ```
46
+ league_track_abrophy input_file_name
47
+ ```
48
+
49
+ ### requiring it into an existing ruby project
50
+
51
+ Add the gem to your gemfile:
52
+
53
+ ```ruby
54
+ gem 'league_track_abrophy', '1.0.0'
55
+ ```
56
+
57
+ it can then be required and used to process inputs already split into an
58
+ array:
59
+
60
+ ```ruby
61
+ require 'league_track_abrophy'
62
+
63
+ input_array = [
64
+ 'Lions 3, Snakes 3',
65
+ 'Tarantulas 1, FC Awesome 0',
66
+ 'Lions 1, FC Awesome 1',
67
+ 'Tarantulas 3, Snakes 1',
68
+ 'Lions 4, Grouches 0'
69
+ ]
70
+
71
+ # returns a formatted string ready to print of the final results
72
+ LeagueTrackAbrophy.process(input_array)
73
+ ```
74
+
75
+ ## Testing
76
+
77
+ After cloning the repo and installing dev dependencies with bundle, you can run tests against the codebase through:
78
+
79
+ ```
80
+ rake test
81
+ ```
82
+
83
+ ## Notes On Testing
84
+
85
+ I used RSpec to cover unit and integration tests, and used rubocop to test
86
+ code style across the project.
87
+
88
+ ## License
89
+
90
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
91
+
92
+
93
+
94
+ # PROBLEM
95
+ ## original problem statement and information below
96
+
97
+ ## Problem Statement & Instructions
98
+ Read the problem statement, code a working solution (valid input and output will be provided) and supporting tests using a language of your choice.
99
+
100
+ ## The Problem
101
+ We want you to create a command-line application that will calculate the ranking table for a soccer league.
102
+
103
+ ## Input/output
104
+ The input will be a text file and the output should log to your terminal.
105
+
106
+ The input contains results of games, one per line. See “Sample input” for details.
107
+ The output should be ordered from most to least points, following the format specified in “Expected output”.
108
+
109
+ You can expect that the input will be well-formed. There is no need to add special handling for malformed input files.
110
+
111
+ ## The rules
112
+ In this league, a draw (tie) is worth 1 point and a win is worth 3 points. A loss is worth 0 points.
113
+
114
+ If two or more teams have the same number of points, they should have the same rank and be printed in alphabetical order (as in the tie for 3rd place in the sample data).
115
+
116
+ ## Guidelines
117
+ This should be implemented in a language with which you are familiar. We would prefer that you use Ruby, JavaScript, Python or Elixir, if you are comfortable doing so. If none of these is comfortable, please choose a language that is both comfortable for you and suited to the task.
118
+
119
+ Please fork the repo and commit your changes early and often.
120
+
121
+ If you use other libraries installed by a common package manager (Rubygems / Bundler, NPM), it is not necessary to commit the installed packages.
122
+
123
+ We write automated tests and we would like you to do so as well.
124
+
125
+ If there are any complicated setup steps necessary to run your solution, please document them.
126
+
127
+ ## Sample input:
128
+
129
+ ```
130
+ Lions 3, Snakes 3
131
+ Tarantulas 1, FC Awesome 0
132
+ Lions 1, FC Awesome 1
133
+ Tarantulas 3, Snakes 1
134
+ Lions 4, Grouches 0
135
+ ```
136
+
137
+ ## Expected output:
138
+
139
+ ```
140
+ 1. Tarantulas, 6 pts
141
+ 2. Lions, 5 pts
142
+ 3. FC Awesome, 1 pt
143
+ 3. Snakes, 1 pt
144
+ 5. Grouches, 0 pts
145
+ ```
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:test)
7
+
8
+ task :run do
9
+ sh "ruby bin/league_track_abrophy #{ARGV[1]}"
10
+ end
11
+
12
+ task default: :test
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ #!/usr/bin/env ruby
3
+
4
+ require 'bundler/setup'
5
+ require 'league_track_abrophy'
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require 'pry'
12
+ # Pry.start
13
+
14
+ require 'irb'
15
+ IRB.start(__FILE__)
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'league_track_abrophy'
4
+
5
+ input_array = []
6
+ until ARGF.eof
7
+ input = ARGF.gets.split("\n")
8
+ input_array.push(input[0])
9
+ end
10
+
11
+ puts LeagueTrackAbrophy.process(input_array)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'league_track_abrophy/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'league_track_abrophy'
9
+ spec.version = LeagueTrackAbrophy::VERSION
10
+ spec.authors = ['Arthur Brophy']
11
+ spec.email = ['artbrophy@gmail.com']
12
+
13
+ spec.summary = 'solution to league problem'
14
+ spec.description = 'LeagueTrack is a commandline ruby gem for calculating '\
15
+ 'the final score for a league give input of final scores of matches played'
16
+ spec.homepage = 'http://github.com/abrophy/server-side-developer-test.git'
17
+ spec.license = 'MIT'
18
+
19
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
20
+ `git ls-files -z`.split("\x0").reject do |f|
21
+ f.match(%r{^(test|spec|features)/})
22
+ end
23
+ end
24
+ spec.executables = ['league_track_abrophy']
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.16.4'
28
+ spec.add_development_dependency 'rake', '~> 12.3.1'
29
+ spec.add_development_dependency 'rspec', '~> 3.8.0'
30
+ spec.add_development_dependency 'rubocop', '~> 0.59.1'
31
+ end
@@ -0,0 +1,5 @@
1
+ Lions 3, Snakes 3
2
+ Tarantulas 1, FC Awesome 0
3
+ Lions 1, FC Awesome 1
4
+ Tarantulas 3, Snakes 1
5
+ Lions 4, Grouches 0
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Game
4
+ attr_accessor :team_one, :team_two, :winning_team
5
+ def initialize(raw_string)
6
+ teams = raw_string.split(',')
7
+ team_one_data = teams[0].split(' ')
8
+ team_two_data = teams[1].split(' ')
9
+
10
+ @winning_team = nil
11
+ @team_one = team_one_data[0..-2].join(' ')
12
+ @team_two = team_two_data[0..-2].join(' ')
13
+
14
+ @team_one_score = team_one_data[-1].to_i
15
+ @team_two_score = team_two_data[-1].to_i
16
+
17
+ if draw?
18
+ return
19
+ end
20
+
21
+ if @team_one_score > @team_two_score
22
+ @winning_team = @team_one
23
+ else
24
+ @winning_team = @team_two
25
+ end
26
+ end
27
+
28
+ def draw?
29
+ @team_one_score == @team_two_score
30
+ end
31
+
32
+ def adjustment
33
+ if draw?
34
+ return { @team_one => 1,
35
+ @team_two => 1}
36
+ end
37
+
38
+ if @team_one_score > @team_two_score
39
+ return {
40
+ @team_one => 3,
41
+ @team_two => 0
42
+ }
43
+ else
44
+ return {
45
+ @team_one => 0,
46
+ @team_two => 3
47
+ }
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ class League
4
+ attr_accessor :games, :score_hash
5
+
6
+ def initialize(games_array)
7
+ @games = games_array
8
+ @score_hash = {}
9
+ end
10
+
11
+ def results
12
+ @games.each do |game|
13
+ adjust_score(game.adjustment)
14
+ end
15
+
16
+ result_array = @score_hash.sort_by { |k, v| k }
17
+ result_array = result_array.reverse
18
+ result_array = result_array.sort_by { |k, v| v }
19
+ result_array = result_array.reverse
20
+ result_array.each_with_index.map do |item, index|
21
+ "#{index + 1}. #{item[0]}, #{item[1]} #{item[1] > 1 || item[1] == 0 ? 'pts' : 'pt'}"
22
+ end
23
+ end
24
+
25
+ def adjust_score(adjustment_data)
26
+ adjustment_data.each do |key, value|
27
+ if @score_hash.key?(key)
28
+ @score_hash[key] += value
29
+ else
30
+ @score_hash[key] = value
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'league_track_abrophy/version'
4
+
5
+ require_relative('./game')
6
+ require_relative('./league')
7
+
8
+ # takes in score file input and returns the final results for a league
9
+ module LeagueTrackAbrophy
10
+ def self.process(input_array)
11
+ games = input_array.map do |item|
12
+ Game.new(item)
13
+ end
14
+ league = League.new(games)
15
+ league.results.join("\n")
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LeagueTrackAbrophy
4
+ VERSION = '1.0.0'
5
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: league_track_abrophy
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Arthur Brophy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-09-18 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.16.4
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.16.4
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 12.3.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 12.3.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.8.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.8.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.59.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.59.1
69
+ description: LeagueTrack is a commandline ruby gem for calculating the final score
70
+ for a league give input of final scores of matches played
71
+ email:
72
+ - artbrophy@gmail.com
73
+ executables:
74
+ - league_track_abrophy
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".ruby-version"
81
+ - ".travis.yml"
82
+ - CODE_OF_CONDUCT.md
83
+ - Gemfile
84
+ - Gemfile.lock
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/console
89
+ - bin/league_track_abrophy
90
+ - bin/setup
91
+ - league_track_abrophy.gemspec
92
+ - league_track_input.example
93
+ - lib/game.rb
94
+ - lib/league.rb
95
+ - lib/league_track_abrophy.rb
96
+ - lib/league_track_abrophy/version.rb
97
+ homepage: http://github.com/abrophy/server-side-developer-test.git
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.7.7
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: solution to league problem
121
+ test_files: []