gpa_calculator 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +17 -0
- data/Rakefile +2 -0
- data/bin/gpa_calculator +6 -0
- data/gpa_calculator.gemspec +24 -0
- data/lib/gpa_calculator.rb +169 -0
- data/lib/gpa_calculator/version.rb +3 -0
- data/spec/gpa_calculator_spec.rb +70 -0
- data/spec/spec_helper.rb +3 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: afc9dd5c984056cd2c2a42ad8c8017f49a6f3849
|
4
|
+
data.tar.gz: 1d85176927b0eab664c106aed804230648a70b5d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 92921a0e8284c39290fb00a56f0353cd256fa2a78df929ce7b1928e32f75c080ce383dd4e7a4e998d36daa418537958b32f8e36d7932387e3b4526f9df0e2946
|
7
|
+
data.tar.gz: 3e80db69587c6d92d6578d66fb8ef5378140b72f50945e80edd8c6ebc44a7a18eb10378f54a7396d66d48d098d9f196c0b3cd7a93894b80d1a34ae941ef7212e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Sarah Wheeler
|
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,17 @@
|
|
1
|
+
# Summary
|
2
|
+
|
3
|
+
`gpa_calculator` is a command line tool that allows you to input course information and receive a GPA total, as well as a detailed grade report. You can provide grades as either letters or percentage scores.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
To install as a gem:
|
8
|
+
|
9
|
+
$ gem install gpa_calculator
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
After installation, simply type:
|
14
|
+
|
15
|
+
$ gpa_calculator
|
16
|
+
|
17
|
+
and you will be prompted to enter your course information.
|
data/Rakefile
ADDED
data/bin/gpa_calculator
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gpa_calculator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gpa_calculator"
|
8
|
+
spec.version = GpaCalculator::VERSION
|
9
|
+
spec.authors = ["Sarah W."]
|
10
|
+
spec.email = ["sarahcwheeler@gmail.com"]
|
11
|
+
spec.summary = "GPA calculator and grade report generator."
|
12
|
+
spec.description = "Provide course names and scores, and your GPA will be automatically generated."
|
13
|
+
spec.homepage = "http://rubygems.org/gems/gpa_calculator"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "2.14.1"
|
24
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
require "gpa_calculator/version"
|
2
|
+
|
3
|
+
module GpaCalculator
|
4
|
+
class Calculator
|
5
|
+
|
6
|
+
def start_program
|
7
|
+
@courses = {}
|
8
|
+
add_course
|
9
|
+
more_courses?
|
10
|
+
end
|
11
|
+
|
12
|
+
def add_course
|
13
|
+
name = add_course_name
|
14
|
+
score = add_course_score
|
15
|
+
save_course(name, score)
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_course_name
|
19
|
+
print "Enter course name: "
|
20
|
+
name = gets.chomp
|
21
|
+
course_name_validation(name)
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_course_score
|
25
|
+
print "Enter course grade: "
|
26
|
+
score = gets.chomp
|
27
|
+
course_grade_validation(score)
|
28
|
+
end
|
29
|
+
|
30
|
+
def more_courses?
|
31
|
+
print "Do you want to add another course? (y/N) "
|
32
|
+
add_more = gets.chomp.downcase
|
33
|
+
if add_more == "y" || add_more == "yes"
|
34
|
+
add_course
|
35
|
+
more_courses?
|
36
|
+
elsif add_more == "n" || add_more == "no"
|
37
|
+
print_table
|
38
|
+
calculate_avg
|
39
|
+
calculate_gpa
|
40
|
+
else
|
41
|
+
puts "Sorry, I didn't understand that. Please select y/n or yes/no."
|
42
|
+
more_courses?
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def course_name_validation(name)
|
47
|
+
if name == "" || name == " " || name.match(/[a-zA-Z0-9\-]+/) == nil
|
48
|
+
print "Enter course name (required): "
|
49
|
+
name = gets.chomp
|
50
|
+
course_name_validation(name)
|
51
|
+
else
|
52
|
+
name
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def course_grade_validation(grade)
|
57
|
+
grade.tr!('%', '')
|
58
|
+
if grade == "" || grade == " " || grade.match(/[e-zE-Z]+/)
|
59
|
+
print "Enter course grade (required): "
|
60
|
+
grade = gets.chomp
|
61
|
+
course_grade_validation(grade)
|
62
|
+
elsif grade.match(/[a-fA-F]\-?\+?/)
|
63
|
+
grade_to_percent(grade)
|
64
|
+
else
|
65
|
+
grade
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def save_course(name, score)
|
70
|
+
@courses.store(name, score.to_f)
|
71
|
+
end
|
72
|
+
|
73
|
+
def print_table
|
74
|
+
puts "\nCOURSE \t| GRADE \t| POINTS"
|
75
|
+
puts "----------- \t|----------- \t|-----------"
|
76
|
+
@courses.each do |name, score|
|
77
|
+
puts "#{fit_course_name(name)} \t| #{score.to_f}\t\t| #{percent_to_points(score)}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def calculate_avg
|
82
|
+
total = @courses.values.inject { |sum, x| sum + x }
|
83
|
+
average = total/@courses.length
|
84
|
+
puts "\nCumulative Average:\t #{average.round(3)}"
|
85
|
+
end
|
86
|
+
|
87
|
+
def calculate_gpa
|
88
|
+
total = @courses.values.inject(percent_to_points(0)) { |sum, x| sum + percent_to_points(x) }
|
89
|
+
average = total/@courses.length
|
90
|
+
puts "Cumulative GPA:\t\t #{average.round(3)}"
|
91
|
+
end
|
92
|
+
|
93
|
+
def fit_course_name(name)
|
94
|
+
if name.length >= 14
|
95
|
+
name.capitalize.slice(0,10) + ("...")
|
96
|
+
elsif name.length <= 6
|
97
|
+
name.capitalize + ("\t")
|
98
|
+
else
|
99
|
+
name.capitalize
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def percent_to_points(grade)
|
104
|
+
case grade.to_f
|
105
|
+
when 97.0..1000.0
|
106
|
+
points = 4.0
|
107
|
+
when 93.0..96.99
|
108
|
+
points = 4.0
|
109
|
+
when 90.0..92.99
|
110
|
+
points = 3.7
|
111
|
+
when 87.0..89.99
|
112
|
+
points = 3.3
|
113
|
+
when 83.0..86.99
|
114
|
+
points = 3.0
|
115
|
+
when 80.0..82.99
|
116
|
+
points = 2.7
|
117
|
+
when 77.0..79.99
|
118
|
+
points = 2.3
|
119
|
+
when 73.0..76.99
|
120
|
+
points = 2.0
|
121
|
+
when 70.0..72.99
|
122
|
+
points = 1.7
|
123
|
+
when 67.0..69.99
|
124
|
+
points = 1.3
|
125
|
+
when 65.0..66.99
|
126
|
+
points = 1.0
|
127
|
+
when -1000.0..64.99
|
128
|
+
points = 0
|
129
|
+
else
|
130
|
+
puts "An error has occurred"
|
131
|
+
end
|
132
|
+
points
|
133
|
+
end
|
134
|
+
|
135
|
+
def grade_to_percent(grade)
|
136
|
+
case grade.capitalize
|
137
|
+
when "A+"
|
138
|
+
percent = 97
|
139
|
+
when "A"
|
140
|
+
percent = 93
|
141
|
+
when "A-"
|
142
|
+
percent = 90
|
143
|
+
when "B+"
|
144
|
+
percent = 87
|
145
|
+
when "B"
|
146
|
+
percent = 83
|
147
|
+
when "B-"
|
148
|
+
percent = 80
|
149
|
+
when "C+"
|
150
|
+
percent = 77
|
151
|
+
when "C"
|
152
|
+
percent = 73
|
153
|
+
when "C-"
|
154
|
+
percent = 70
|
155
|
+
when "D+"
|
156
|
+
percent = 67
|
157
|
+
when "D"
|
158
|
+
percent = 65
|
159
|
+
when "F"
|
160
|
+
percent = 64
|
161
|
+
else
|
162
|
+
print "Enter course grade (required): "
|
163
|
+
grade = gets.chomp
|
164
|
+
course_grade_validation(grade)
|
165
|
+
end
|
166
|
+
percent
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gpa_calculator'
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.mock_framework = :rspec
|
6
|
+
config.mock_with :rspec do |c|
|
7
|
+
c.syntax = [:should, :expect]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "GpaCalculator" do
|
12
|
+
before do
|
13
|
+
@calculator = GpaCalculator::Calculator.new
|
14
|
+
@courses = {"English" => 72, "Math" => 99, "Science" => 100 }
|
15
|
+
end
|
16
|
+
describe "#start_program" do
|
17
|
+
it "should start by requesting a course name" do
|
18
|
+
@calculator.stub(:start_program) {"English"}.and_return("English")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
describe "#more_courses?" do
|
22
|
+
it "should return the course name prompt for y/yes answers" do
|
23
|
+
@calculator.stub(:more_courses?) {"y"}.and_return("Enter course name: ")
|
24
|
+
@calculator.stub(:more_courses?) {"Yes"}.and_return("Enter course name: ")
|
25
|
+
end
|
26
|
+
it "should print the course report table for n/no answers" do
|
27
|
+
@calculator.stub(:more_courses?) {"n"}.and_return("\nCOURSE \t| GRADE \t| POINTS")
|
28
|
+
@calculator.stub(:more_courses?) {"No"}.and_return("\nCOURSE \t| GRADE \t| POINTS")
|
29
|
+
end
|
30
|
+
it "should" do
|
31
|
+
@calculator.stub(:more_courses?) {"whatever"}.and_return("Sorry, I didn't understand that. Please select y/n or yes/no.")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
describe "course name validations" do
|
35
|
+
it "should not allow blank or empty course names" do
|
36
|
+
@calculator.stub(:course_name_validation) {" "}.and_return("Enter course name (required): ")
|
37
|
+
@calculator.stub(:course_name_validation) {""}.and_return("Enter course name (required): ")
|
38
|
+
end
|
39
|
+
it "should allow course names with numbers and dashes" do
|
40
|
+
@calculator.stub(:course_name_validation) {"CS-101"}.and_return("Enter course grade: ")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
describe "course grade validations" do
|
44
|
+
it "should not allow blank or empty course grades" do
|
45
|
+
@calculator.stub(:course_grade_validation) {""}.and_return("Enter course grade (required): ")
|
46
|
+
@calculator.stub(:course_grade_validation) {" "}.and_return("Enter course grade (required): ")
|
47
|
+
end
|
48
|
+
it "should not allow course letter grades that aren't A-F" do
|
49
|
+
@calculator.stub(:course_grade_validation) {"pass"}.and_return("Enter course grade (required): ")
|
50
|
+
end
|
51
|
+
it "should accept floats and integers" do
|
52
|
+
@calculator.stub(:course_grade_validation) {88.0}.and_return(88.0)
|
53
|
+
@calculator.stub(:course_grade_validation) {88}.and_return(88)
|
54
|
+
end
|
55
|
+
it "should accept letter grades and pluses/minuses" do
|
56
|
+
@calculator.stub(:course_grade_validation) {"A+"}.and_return("A+")
|
57
|
+
@calculator.stub(:course_grade_validation) {"C"}.and_return("C")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
describe "#calculate_avg" do
|
61
|
+
it "should find the correct average for the course scores" do
|
62
|
+
@calculator.stub(:calculate_avg).and_return("\nCumulative Average:\t 90.334")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
describe "#calculate_gpa" do
|
66
|
+
it "should find the correct GPA for the course scores" do
|
67
|
+
@calculator.stub(:calculate_gpa).and_return("Cumulative GPA:\t\t 3.234")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gpa_calculator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sarah W.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-03 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
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
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.14.1
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.14.1
|
55
|
+
description: Provide course names and scores, and your GPA will be automatically generated.
|
56
|
+
email:
|
57
|
+
- sarahcwheeler@gmail.com
|
58
|
+
executables:
|
59
|
+
- gpa_calculator
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE.txt
|
66
|
+
- README.md
|
67
|
+
- Rakefile
|
68
|
+
- bin/gpa_calculator
|
69
|
+
- gpa_calculator.gemspec
|
70
|
+
- lib/gpa_calculator.rb
|
71
|
+
- lib/gpa_calculator/version.rb
|
72
|
+
- spec/gpa_calculator_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
homepage: http://rubygems.org/gems/gpa_calculator
|
75
|
+
licenses:
|
76
|
+
- MIT
|
77
|
+
metadata: {}
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 2.2.2
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: GPA calculator and grade report generator.
|
98
|
+
test_files:
|
99
|
+
- spec/gpa_calculator_spec.rb
|
100
|
+
- spec/spec_helper.rb
|