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/modspec/table_cleanup.rb,
lib/metanorma/requirements/selector.rb

Defined Under Namespace

Classes: Default, Modspec

Constant Summary collapse

VERSION =
"0.1.9".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
22
# 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[:labels])
  # @labels = @i18n.get.deep_merge(options[:labels] || {})["requirements"]
  @labels = @i18n.get["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



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

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



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

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

#model(type) ⇒ Object



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

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

#model_namesObject



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

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



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

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



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

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



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

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



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

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



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

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



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

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



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

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