Class: Qualspec::Rubric

Inherits:
Object
  • Object
show all
Defined in:
lib/qualspec/rubric.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#criteriaObject (readonly)

Returns the value of attribute criteria.



5
6
7
# File 'lib/qualspec/rubric.rb', line 5

def criteria
  @criteria
end

#nameObject (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

Returns:

  • (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

.registryObject



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_sObject



17
18
19
# File 'lib/qualspec/rubric.rb', line 17

def to_s
  @criteria.join("\n")
end