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.3.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.



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

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_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



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

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



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

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

#model(type) ⇒ Object



54
55
56
# File 'lib/metanorma/requirements/selector.rb', line 54

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

#model_namesObject



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

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



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

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



90
91
92
93
94
# File 'lib/metanorma/requirements/selector.rb', line 90

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



96
97
98
99
100
# File 'lib/metanorma/requirements/selector.rb', line 96

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



84
85
86
87
88
# File 'lib/metanorma/requirements/selector.rb', line 84

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



78
79
80
81
82
# File 'lib/metanorma/requirements/selector.rb', line 78

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



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

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



72
73
74
75
76
# File 'lib/metanorma/requirements/selector.rb', line 72

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