Class: Qualspec::Rubric
- Inherits:
-
Object
- Object
- Qualspec::Rubric
- Defined in:
- lib/qualspec/rubric.rb
Instance Attribute Summary collapse
-
#criteria ⇒ Object
readonly
Returns the value of attribute criteria.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
- .clear! ⇒ Object
- .define(name, &block) ⇒ Object
- .defined?(name) ⇒ Boolean
- .find(name) ⇒ Object
- .registry ⇒ Object
Instance Method Summary collapse
- #criterion(description) ⇒ Object
-
#initialize(name, &block) ⇒ Rubric
constructor
A new instance of Rubric.
- #to_s ⇒ Object
Constructor Details
#initialize(name, &block) ⇒ Rubric
Returns a new instance of Rubric.
7 8 9 10 11 |
# File 'lib/qualspec/rubric.rb', line 7 def initialize(name, &block) @name = name @criteria = [] instance_eval(&block) if block_given? # rubocop:disable Style/EvalWithLocation -- DSL pattern requires eval end |
Instance Attribute Details
#criteria ⇒ Object (readonly)
Returns the value of attribute criteria.
5 6 7 |
# File 'lib/qualspec/rubric.rb', line 5 def criteria @criteria end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/qualspec/rubric.rb', line 5 def name @name end |
Class Method Details
.clear! ⇒ Object
38 39 40 |
# File 'lib/qualspec/rubric.rb', line 38 def clear! @registry = {} end |
.define(name, &block) ⇒ Object
26 27 28 |
# File 'lib/qualspec/rubric.rb', line 26 def define(name, &block) registry[name.to_sym] = new(name, &block) end |
.defined?(name) ⇒ Boolean
34 35 36 |
# File 'lib/qualspec/rubric.rb', line 34 def defined?(name) registry.key?(name.to_sym) end |
.find(name) ⇒ Object
30 31 32 |
# File 'lib/qualspec/rubric.rb', line 30 def find(name) registry[name.to_sym] || raise(Error, "Rubric '#{name}' not found") end |
.registry ⇒ Object
22 23 24 |
# File 'lib/qualspec/rubric.rb', line 22 def registry @registry ||= {} end |
Instance Method Details
#criterion(description) ⇒ Object
13 14 15 |
# File 'lib/qualspec/rubric.rb', line 13 def criterion(description) @criteria << description end |
#to_s ⇒ Object
17 18 19 |
# File 'lib/qualspec/rubric.rb', line 17 def to_s @criteria.join("\n") end |