was 0.4.0 → 0.5.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: 116f56df4be0366c5cefda0647c4a59f4300ad8f84b76e39c5c3563ef97abd82
4
- data.tar.gz: e3b5304f1f46fac185b4a92ec1201c09bdfc864576332a33614a946606a31afc
3
+ metadata.gz: 8022ee48dc263f90467dd4b9eb9fe4c2125d3a5f4ca14acca80abaa149f53e14
4
+ data.tar.gz: cda95f6711c8e87b234582a6a0969427824af9c4cbb6f74146b10185bdd4bfb6
5
5
  SHA512:
6
- metadata.gz: 6ea32808ff515334b197f87ec7dfa8d3ed699b281cff0a041f88ef000884617498eb22a6ce90aec66ee793ef136b4f3939d371b5abff9b4f28b3a3dfbe880f75
7
- data.tar.gz: 124c909b89e6ce6b9bb65064bc824c70d8489e9510915a722f8d82919d3e4818f2aebade83d2381f12c121591797eb5937ebaf7b61e05425b6ef93b9e6b12993
6
+ metadata.gz: 1693a283d769e0d4b2c96f42c154b39c5c9c8c3bf426befc73e81c938d163ae45ae74385719792966990dfe8f4a5f908915ec06876d003664feafd85e6c9bd89
7
+ data.tar.gz: 12cfc53b40541711c802191e428fabe75cb93b3f648255f181f6b378f05750441843829cab4264ad5dfae765d82f7a7f211b8c5b0189abc8fcce40978e2603d7
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
- klasses.merge!(klass => weight)
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.klasses
18
- @klasses ||= {}
17
+ def self.scorers
18
+ @scorers ||= {}
19
19
  end
20
20
 
21
21
  def self.weights
22
22
  {}.tap do |hash|
23
- klasses.each do |klass, weight|
24
- hash[klass_name_symbol(klass)] = { weight: weight }
25
- if Object.const_get(klass).klasses.length > 0
26
- hash[klass_name_symbol(klass)].merge!(
27
- with: Object.const_get(klass).weights
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,9 +40,9 @@ module WAS
40
40
  end
41
41
 
42
42
  def calculation
43
- self.class.klasses.sum do |klass, weight|
44
- score = Object.const_get(klass).new(input[self.class.klass_name_symbol(klass)]).calculate
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
48
 
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.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: was
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Connell