was 0.5.1 → 0.6.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 +4 -4
- data/README.md +4 -4
- data/lib/was/score.rb +27 -0
- data/lib/was/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 35789d2f200b0436e67730bf7e2811cd61665f6bef985bc1f2cb091ed1797a5b
|
4
|
+
data.tar.gz: efd553a27afd03bb2da2443d80945239b7e22487dac6e850982d498ec32d5d01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 630fc202315d1b3d90c28214f97d23ba66f7f5daba3a43651cf720d21a7ece94c6d2533715267933edc2f6b18f662301d71d6590c7d9db655aa30dbcc90703d6
|
7
|
+
data.tar.gz: 9e95ffaddcbae72fba82c4957b7ac20bb6db44bc219c6e13b445281799aafead6a9c722b0a7235975d737f877828da63dfc70e0284b65288e284e0245b54614a
|
data/README.md
CHANGED
@@ -25,8 +25,8 @@ require "was"
|
|
25
25
|
class ReportScore < WAS::Score
|
26
26
|
maximum_score 1000
|
27
27
|
|
28
|
-
with :exam, "ExamScore", weight: 0.75
|
29
|
-
with :practical "PracticalScore", weight: 0.25
|
28
|
+
with :exam, class_name: "ExamScore", weight: 0.75
|
29
|
+
with :practical class_name: "PracticalScore", weight: 0.25
|
30
30
|
end
|
31
31
|
|
32
32
|
class ExamScore < WAS::Score
|
@@ -68,8 +68,8 @@ Omitting the `maximum_score` will return a composed percentage represented as a
|
|
68
68
|
```ruby
|
69
69
|
# report_score.rb
|
70
70
|
class ReportScore < WAS::Score
|
71
|
-
with :exam, "ExamScore", weight: 0.75
|
72
|
-
with :practical "PracticalScore", weight: 0.25
|
71
|
+
with :exam, class_name: "ExamScore", weight: 0.75
|
72
|
+
with :practical class_name: "PracticalScore", weight: 0.25
|
73
73
|
end
|
74
74
|
```
|
75
75
|
|
data/lib/was/score.rb
CHANGED
@@ -31,6 +31,11 @@ module WAS
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
+
def self.context(name, score: nil, &block)
|
35
|
+
@contexts ||= []
|
36
|
+
@contexts.push({ name: name, score: score, code: block })
|
37
|
+
end
|
38
|
+
|
34
39
|
def initialize(input)
|
35
40
|
@input = input
|
36
41
|
end
|
@@ -40,6 +45,28 @@ module WAS
|
|
40
45
|
end
|
41
46
|
|
42
47
|
def calculation
|
48
|
+
if contexts?
|
49
|
+
context_score_calculation
|
50
|
+
else
|
51
|
+
nested_score_calcuation
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def contexts?
|
58
|
+
!!self.class.instance_variable_get("@contexts")
|
59
|
+
end
|
60
|
+
|
61
|
+
def context_score_calculation
|
62
|
+
self.class.instance_variable_get("@contexts").each do |context|
|
63
|
+
output = context[:code].call(input)
|
64
|
+
next unless output
|
65
|
+
return context[:score] || output
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def nested_score_calcuation
|
43
70
|
self.class.scorers.sum do |name, scorer|
|
44
71
|
score = Object.const_get(scorer[:class_name]).new(input[name.to_sym]).calculate
|
45
72
|
score * scorer[:weight]
|
data/lib/was/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: was
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Connell
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-02-
|
11
|
+
date: 2025-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A simple gem/dsl for generating Weighted Average Score calculations.
|
14
14
|
email:
|