was 0.4.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/was/score.rb +12 -18
- data/lib/was/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95d42be52374816fe8a10ac34087752ff5a4255d426d454e0a15bb77586a2184
|
4
|
+
data.tar.gz: a64446e7c586129836c07b1b112f7b5e5db86f71cc4ed4bd711d4fcb593abc8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30adcbb6d298b3e972067edc741fd266eaef09f7639151cdcfeded444f3b34a75d54280902cb5e7a5c88d1437324c742c9b34b7771a576d1f4591b892e7c9368
|
7
|
+
data.tar.gz: 8a734c0a5ee2dd382e73060ab69b1c881a433f61e11565cbd668f7597d40cda84c4f0d19d497ffbdd80da5b6fc2e5040af8b4dd1c4c3377929e8c68bda6723dd
|
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 "ExamScore", weight: 0.75
|
29
|
-
with "PracticalScore", weight: 0.25
|
28
|
+
with :exam, "ExamScore", weight: 0.75
|
29
|
+
with :practical "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 "ExamScore", weight: 0.75
|
72
|
-
with "PracticalScore", weight: 0.25
|
71
|
+
with :exam, "ExamScore", weight: 0.75
|
72
|
+
with :practical "PracticalScore", weight: 0.25
|
73
73
|
end
|
74
74
|
```
|
75
75
|
|
data/lib/was/score.rb
CHANGED
@@ -10,21 +10,21 @@ module WAS
|
|
10
10
|
@maximum_score || 1
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.with(klass, weight: 0)
|
14
|
-
|
13
|
+
def self.with(name, class_name: klass, weight: 0)
|
14
|
+
scorers.merge!(name => { class_name: class_name, weight: weight })
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.
|
18
|
-
@
|
17
|
+
def self.scorers
|
18
|
+
@scorers ||= {}
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.weights
|
22
22
|
{}.tap do |hash|
|
23
|
-
|
24
|
-
hash[
|
25
|
-
if Object.const_get(
|
26
|
-
hash[
|
27
|
-
with: Object.const_get(
|
23
|
+
scorers.each do |name, scorer|
|
24
|
+
hash[name] = { weight: scorer[:weight] }
|
25
|
+
if Object.const_get(scorer[:class_name]).scorers.length > 0
|
26
|
+
hash[name].merge!(
|
27
|
+
with: Object.const_get(scorer[:class_name]).weights
|
28
28
|
)
|
29
29
|
end
|
30
30
|
end
|
@@ -40,16 +40,10 @@ module WAS
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def calculation
|
43
|
-
self.class.
|
44
|
-
score = Object.const_get(
|
45
|
-
score * weight
|
43
|
+
self.class.scorers.sum do |name, scorer|
|
44
|
+
score = Object.const_get(scorer[:class_name]).new(input[name.to_sym]).calculate
|
45
|
+
score * scorer[:weight]
|
46
46
|
end * self.class.max_score
|
47
47
|
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def self.klass_name_symbol(klass)
|
52
|
-
klass[/(\w+)Score$/, 1].downcase.to_sym
|
53
|
-
end
|
54
48
|
end
|
55
49
|
end
|
data/lib/was/version.rb
CHANGED