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.2".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.



9
10
11
12
13
14
15
16
17
# File 'lib/metanorma/requirements/selector.rb', line 9

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

Instance Attribute Details

#i18nObject

Returns the value of attribute i18n.



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

def i18n
  @i18n
end

#labelsObject

Returns the value of attribute labels.



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

def labels
  @labels
end

Instance Method Details

#create(type) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/metanorma/requirements/selector.rb', line 43

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 = "en", script = "Latn", i18nhash = nil) ⇒ Object



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

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

#model(type) ⇒ Object



51
52
53
# File 'lib/metanorma/requirements/selector.rb', line 51

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

#model_namesObject



19
20
21
# File 'lib/metanorma/requirements/selector.rb', line 19

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



61
62
63
64
65
66
67
# File 'lib/metanorma/requirements/selector.rb', line 61

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



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

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



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

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



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

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



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

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



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/metanorma/requirements/selector.rb', line 31

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



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

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