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, #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
# File 'lib/kriterion/standard.rb', line 19

def initialize(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



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

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



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

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

Instance Method Details

#complianceObject



61
62
63
# File 'lib/kriterion/standard.rb', line 61

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

#typeObject



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

def type
  :standard
end