was 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 95d42be52374816fe8a10ac34087752ff5a4255d426d454e0a15bb77586a2184
4
- data.tar.gz: a64446e7c586129836c07b1b112f7b5e5db86f71cc4ed4bd711d4fcb593abc8d
3
+ metadata.gz: 35789d2f200b0436e67730bf7e2811cd61665f6bef985bc1f2cb091ed1797a5b
4
+ data.tar.gz: efd553a27afd03bb2da2443d80945239b7e22487dac6e850982d498ec32d5d01
5
5
  SHA512:
6
- metadata.gz: 30adcbb6d298b3e972067edc741fd266eaef09f7639151cdcfeded444f3b34a75d54280902cb5e7a5c88d1437324c742c9b34b7771a576d1f4591b892e7c9368
7
- data.tar.gz: 8a734c0a5ee2dd382e73060ab69b1c881a433f61e11565cbd668f7597d40cda84c4f0d19d497ffbdd80da5b6fc2e5040af8b4dd1c4c3377929e8c68bda6723dd
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module WAS
4
- VERSION = "0.5.1"
4
+ VERSION = "0.6.0"
5
5
  end
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.5.1
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 00:00:00.000000000 Z
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: