Class: Kriterion::Standard

Inherits:
Object
  • Object
show all
Defined in:
lib/kriterion/standard.rb

Constant Summary collapse

@@standards =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Object

#find_section, #flush_compliance!, #full_keys, #primary_key, primary_key, #to_h

Constructor Details

#initialize(data) ⇒ Standard

Returns a new instance of Standard.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/kriterion/standard.rb', line 19

def initialize(data)
  super(data)
  @uuid              = data['uuid'] || SecureRandom.uuid
  @name              = data['name']
  @date              = data['date']
  @description       = data['description']
  @title             = data['title']
  @version           = data['version']
  @item_syntax       = if data['item_syntax'].is_a? Regexp
                         data['item_syntax']
                       else
                         Regexp.new(data['item_syntax'])
                       end
  @section_separator = data['section_separator']
  @sections          = data['sections'] || []
  @items             = data['items'] || []
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



10
11
12
# File 'lib/kriterion/standard.rb', line 10

def date
  @date
end

#descriptionObject

Returns the value of attribute description.



11
12
13
# File 'lib/kriterion/standard.rb', line 11

def description
  @description
end

#item_syntaxObject

Returns the value of attribute item_syntax.



14
15
16
# File 'lib/kriterion/standard.rb', line 14

def item_syntax
  @item_syntax
end

#itemsObject

Returns the value of attribute items.



17
18
19
# File 'lib/kriterion/standard.rb', line 17

def items
  @items
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/kriterion/standard.rb', line 9

def name
  @name
end

#section_separatorObject

Returns the value of attribute section_separator.



15
16
17
# File 'lib/kriterion/standard.rb', line 15

def section_separator
  @section_separator
end

#sectionsObject

Returns the value of attribute sections.



16
17
18
# File 'lib/kriterion/standard.rb', line 16

def sections
  @sections
end

#titleObject

Returns the value of attribute title.



12
13
14
# File 'lib/kriterion/standard.rb', line 12

def title
  @title
end

#uuidObject

Returns the value of attribute uuid.



8
9
10
# File 'lib/kriterion/standard.rb', line 8

def uuid
  @uuid
end

#versionObject

Returns the value of attribute version.



13
14
15
# File 'lib/kriterion/standard.rb', line 13

def version
  @version
end

Class Method Details

.get(name) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/kriterion/standard.rb', line 37

def self.get(name)
  # Reload all standards
  Kriterion::Standard.reload_all!

  results = @@standards.select { |s| s.name == name }

  case results.length
  when 0
    raise "No standards found with name: #{name}"
  when 1
    results.first
  else
    raise "Multiple standards found with #{name}"
  end
end

.reload_all!Object



53
54
55
56
# File 'lib/kriterion/standard.rb', line 53

def self.reload_all!
  backend = Kriterion::Backend.get
  @@standards = backend.standards
end

Instance Method Details

#complianceObject



73
74
75
# File 'lib/kriterion/standard.rb', line 73

def compliance
  super([items, sections].flatten)
end

#expandable?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/kriterion/standard.rb', line 58

def expandable?
  true
end

#expandable_keysObject



62
63
64
65
66
67
# File 'lib/kriterion/standard.rb', line 62

def expandable_keys
  %i[
    sections
    items
  ]
end

#typeObject



69
70
71
# File 'lib/kriterion/standard.rb', line 69

def type
  :standard
end