Class: Metanorma::Requirements

Inherits:
Object
  • Object
show all
Defined in:
lib/metanorma/default/utils.rb,
lib/metanorma/default/xrefs.rb,
lib/metanorma/modspec/xrefs.rb,
lib/metanorma/default/isodoc.rb,
lib/metanorma/modspec/isodoc.rb,
lib/metanorma/default/cleanup.rb,
lib/metanorma/default/default.rb,
lib/metanorma/modspec/cleanup.rb,
lib/metanorma/modspec/modspec.rb,
lib/metanorma/modspec/validate.rb,
lib/metanorma/modspec/reqt_label.rb,
lib/metanorma/requirements/version.rb,
lib/metanorma/requirements/selector.rb

Defined Under Namespace

Classes: Default, Modspec

Constant Summary collapse

VERSION =
"0.1.8".freeze
REQRECPER =
"//requirement | //recommendation | //permission".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Requirements

Returns a new instance of Requirements.



12
13
14
15
16
17
18
19
20
21
# File 'lib/metanorma/requirements/selector.rb', line 12

def initialize(options)
  @default = options[:default]
  @i18n = i18n_klass(options[:lang] || "en",
                     options[:script] || "Latn",
                     options[:locale],
                     options[:i18nhash])
  @labels = @i18n.get.deep_merge(options[:labels] || {})["requirements"]
  @models =
    model_names.each_with_object({}) { |k, m| m[k] = create(k) }
end

Instance Attribute Details

#i18nObject

Returns the value of attribute i18n.



8
9
10
# File 'lib/metanorma/requirements/selector.rb', line 8

def i18n
  @i18n
end

#labelsObject

Returns the value of attribute labels.



8
9
10
# File 'lib/metanorma/requirements/selector.rb', line 8

def labels
  @labels
end

Instance Method Details

#create(type) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/metanorma/requirements/selector.rb', line 48

def create(type)
  case type
  when :modspec, :ogc
    Metanorma::Requirements::Modspec.new(parent: self)
  else Metanorma::Requirements::Default.new(parent: self)
  end
end

#i18n_klass(lang, script, locale = nil, i18nhash = nil) ⇒ Object



27
28
29
30
# File 'lib/metanorma/requirements/selector.rb', line 27

def i18n_klass(lang, script, locale = nil, i18nhash = nil)
  ::IsoDoc::MnRequirementsI18n.new(lang, script, locale: locale,
                                                 i18nhash: i18nhash)
end

#model(type) ⇒ Object



56
57
58
# File 'lib/metanorma/requirements/selector.rb', line 56

def model(type)
  @models[type&.to_sym] || @models[@default]
end

#model_namesObject



23
24
25
# File 'lib/metanorma/requirements/selector.rb', line 23

def model_names
  i[default ogc]
end

#requirement_cleanup(xmldoc) ⇒ Object

all cleanup steps by all possible models are included here, and each model can skip a given step. This class iterates through the entire document, and picks the model for each requirement; then that model’s method is applied to that particular requirement instance



66
67
68
69
70
71
72
# File 'lib/metanorma/requirements/selector.rb', line 66

def requirement_cleanup(xmldoc)
  (xmldoc)
  requirement_type_cleanup(xmldoc)
  requirement_inherit_cleanup(xmldoc)
  requirement_descriptions_cleanup(xmldoc)
  requirement_identifier_cleanup(xmldoc)
end

#requirement_descriptions_cleanup(xmldoc) ⇒ Object



92
93
94
95
96
# File 'lib/metanorma/requirements/selector.rb', line 92

def requirement_descriptions_cleanup(xmldoc)
  xmldoc.xpath(REQRECPER).each do |r|
    model(r["model"]).requirement_descriptions_cleanup(r)
  end
end

#requirement_identifier_cleanup(xmldoc) ⇒ Object



98
99
100
101
102
# File 'lib/metanorma/requirements/selector.rb', line 98

def requirement_identifier_cleanup(xmldoc)
  xmldoc.xpath(REQRECPER).each do |r|
    model(r["model"]).requirement_identifier_cleanup(r)
  end
end

#requirement_inherit_cleanup(xmldoc) ⇒ Object



86
87
88
89
90
# File 'lib/metanorma/requirements/selector.rb', line 86

def requirement_inherit_cleanup(xmldoc)
  xmldoc.xpath(REQRECPER).each do |r|
    model(r["model"]).requirement_inherit_cleanup(r)
  end
end

#requirement_metadata_cleanup(xmldoc) ⇒ Object



80
81
82
83
84
# File 'lib/metanorma/requirements/selector.rb', line 80

def (xmldoc)
  xmldoc.xpath(REQRECPER).each do |r|
    model(r["model"]).(r)
  end
end

#requirement_rolesObject

all roles that can be assigned to an example to make it a reqt, across all models (because the model may not be an attribute but embedded in the definition list). Mapped to obligation TODO may need to make it conditional on model



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/metanorma/requirements/selector.rb', line 36

def requirement_roles
  {
    recommendation: "recommendation",
    requirement: "requirement",
    permission: "permission",
    requirements_class: "requirement",
    conformance_test: "requirement",
    conformance_class: "requirement",
    abstract_test: "requirement",
  }
end

#requirement_type_cleanup(xmldoc) ⇒ Object



74
75
76
77
78
# File 'lib/metanorma/requirements/selector.rb', line 74

def requirement_type_cleanup(xmldoc)
  xmldoc.xpath(REQRECPER).each do |r|
    model(r["model"]).requirement_type_cleanup(r)
  end
end