was 0.1.0
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/.rspec +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +60 -0
- data/Rakefile +8 -0
- data/lib/was/score.rb +42 -0
- data/lib/was/version.rb +5 -0
- data/lib/was.rb +9 -0
- data/sig/was.rbs +4 -0
- data/was.gemspec +30 -0
- metadata +53 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 99421529aa08811e583cff20a0e7d41e110aaad70976b8ef6e52a7bda38feab6
|
4
|
+
data.tar.gz: 70b2035d1d5b2ee5937810efd7f337b9133e0b87b5f68434ece9bc796ffb16dd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d5cff77d12a2a61eff5c1a0c131bfbc831e43c0b67d9761b9f44146a1307d6d2c08165f28e1a4d644b19c29b582e0479390135818dade2f344a24c323b8fb3eb
|
7
|
+
data.tar.gz: cbfe391a566ffe9b0ce431d3975e4abfdace7dc3194f3fa9b35430a50d571a81e7c0b9baadd1dfe2f29f2e1c8ad59001e6165d41cf9a3943f25e2615c9f42769
|
data/.rspec
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Mark Connell
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# WAS: Weighted Average Score
|
2
|
+
|
3
|
+
A simple gem/dsl for generating Weighted Average Score calculations.
|
4
|
+
|
5
|
+
## Example Usage
|
6
|
+
|
7
|
+
Scenario:
|
8
|
+
* A person has a final report that is scored based on two parts:
|
9
|
+
* A practical test score, worth 25% of the total
|
10
|
+
* An Exam score, worth 75%
|
11
|
+
* The exam is given a grade: A, B, C, F
|
12
|
+
* 'A' is worth 100%
|
13
|
+
* 'B' is 75%
|
14
|
+
* 'C' is 50%
|
15
|
+
* 'D' is 0%
|
16
|
+
* The practical is a simple mark out of 10.
|
17
|
+
* 4 out of 10 is 40%
|
18
|
+
* The person is given a final score out of 1000.
|
19
|
+
|
20
|
+
### Define score classes
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
class ReportScore < WAS::Score
|
24
|
+
maximum_score 1000
|
25
|
+
|
26
|
+
with "ExamScore", weight: 0.75
|
27
|
+
with "PracticalScore", weight: 0.25
|
28
|
+
end
|
29
|
+
|
30
|
+
class ExamScore < WAS::Score
|
31
|
+
def calculation
|
32
|
+
return 1 if input == "A"
|
33
|
+
return 0.75 if input == "B"
|
34
|
+
return 0.5 if input == "C"
|
35
|
+
0
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class PracticalScore < WAS::Score
|
40
|
+
def calculation
|
41
|
+
input / 10.0
|
42
|
+
end
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
### Generate a total score
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
ReportScore.new(
|
50
|
+
exam: "A"
|
51
|
+
practical: 10
|
52
|
+
).calculate
|
53
|
+
#> 1000
|
54
|
+
|
55
|
+
ReportScore.new(
|
56
|
+
exam: "F",
|
57
|
+
practical: 10
|
58
|
+
).calculate
|
59
|
+
#> 250
|
60
|
+
````
|
data/Rakefile
ADDED
data/lib/was/score.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module WAS
|
2
|
+
class Score
|
3
|
+
attr_reader :input
|
4
|
+
|
5
|
+
def self.maximum_score(value)
|
6
|
+
@maximum_score = value
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.max_score
|
10
|
+
@maximum_score
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.with(klass, weight: 0)
|
14
|
+
klasses.merge!(klass => weight)
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.klasses
|
18
|
+
@klasses ||= {}
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(input)
|
22
|
+
@input = input
|
23
|
+
end
|
24
|
+
|
25
|
+
def calculate
|
26
|
+
calculation
|
27
|
+
end
|
28
|
+
|
29
|
+
def calculation
|
30
|
+
self.class.klasses.sum do |klass, weight|
|
31
|
+
score = Object.const_get(klass).new(input[klass_name_symbol(klass)]).calculate
|
32
|
+
score * weight
|
33
|
+
end * self.class.max_score
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def klass_name_symbol(klass)
|
39
|
+
klass[/(\w+)Score$/, 1].downcase.to_sym
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/was/version.rb
ADDED
data/lib/was.rb
ADDED
data/sig/was.rbs
ADDED
data/was.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/was/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "was"
|
7
|
+
spec.version = WAS::VERSION
|
8
|
+
spec.authors = ["Mark Connell"]
|
9
|
+
spec.email = ["github@markconnell.co.uk"]
|
10
|
+
|
11
|
+
spec.summary = "WAS: Weighted Average Score calculator"
|
12
|
+
spec.description = "A simple gem/dsl for generating Weighted Average Score calculations."
|
13
|
+
spec.homepage = "https://github.com/mconnell/was"
|
14
|
+
spec.required_ruby_version = ">= 2.6.0"
|
15
|
+
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
17
|
+
spec.metadata["source_code_uri"] = "https://github.com/mconnell/was"
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files = Dir.chdir(__dir__) do
|
22
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
(File.expand_path(f) == __FILE__) ||
|
24
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
25
|
+
end
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: was
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Connell
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-02-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple gem/dsl for generating Weighted Average Score calculations.
|
14
|
+
email:
|
15
|
+
- github@markconnell.co.uk
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".rspec"
|
21
|
+
- LICENSE.txt
|
22
|
+
- README.md
|
23
|
+
- Rakefile
|
24
|
+
- lib/was.rb
|
25
|
+
- lib/was/score.rb
|
26
|
+
- lib/was/version.rb
|
27
|
+
- sig/was.rbs
|
28
|
+
- was.gemspec
|
29
|
+
homepage: https://github.com/mconnell/was
|
30
|
+
licenses: []
|
31
|
+
metadata:
|
32
|
+
homepage_uri: https://github.com/mconnell/was
|
33
|
+
source_code_uri: https://github.com/mconnell/was
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 2.6.0
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubygems_version: 3.0.1
|
50
|
+
signing_key:
|
51
|
+
specification_version: 4
|
52
|
+
summary: 'WAS: Weighted Average Score calculator'
|
53
|
+
test_files: []
|