Class: Metanorma::Ogc::Validate

Inherits:
Standoc::Validate
  • Object
show all
Defined in:
lib/metanorma/ogc/validate.rb

Constant Summary collapse

STANDARDTYPE =
%w{standard standard-with-suite abstract-specification
community-standard profile}.freeze
SEQ =

spec of permissible section sequence we skip normative references, it goes to end of list

[
  {
    msg: "Prefatory material must be followed by (clause) Scope",
    val: ["./self::clause[@type = 'scope']"],
  },
  {
    msg: "Scope must be followed by Conformance",
    val: ["./self::clause[@type = 'conformance']"],
  },
  {
    msg: "Normative References must be followed by " \
         "Terms and Definitions",
    val: ["./self::terms | .//terms"],
  },
].freeze

Instance Method Summary collapse

Instance Method Details

#bibdata_validate(doc) ⇒ Object



17
18
19
20
# File 'lib/metanorma/ogc/validate.rb', line 17

def bibdata_validate(doc)
  stage_validate(doc)
  version_validate(doc)
end

#content_validate(doc) ⇒ Object



12
13
14
15
# File 'lib/metanorma/ogc/validate.rb', line 12

def content_validate(doc)
  super
  bibdata_validate(doc.root)
end

#execsummary_validate(xmldoc) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/metanorma/ogc/validate.rb', line 54

def execsummary_validate(xmldoc)
  sect = xmldoc.at("//executivesummary")
  @doctype == "engineering-report" && sect.nil? and
    @log.add("OGC_5", nil)
  @doctype != "engineering-report" && !sect.nil? and
    @log.add("OGC_6", nil)
end

#norm_ref_validate(doc) ⇒ Object



134
135
136
137
138
139
# File 'lib/metanorma/ogc/validate.rb', line 134

def norm_ref_validate(doc)
  @doctype == "engineering-report" or return super
  doc.xpath("//references[@normative = 'true']").each do |b|
    @log.add("OGC_15", b)
  end
end

#preface_sequence_validate(root) ⇒ Object



121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/metanorma/ogc/validate.rb', line 121

def preface_sequence_validate(root)
  @doctype == "engineering-report" and return
  root.at("//preface/abstract") or @log.add("OGC_10", nil)
  root.at("//bibdata/keyword | //bibdata/ext/keyword") or
    @log.add("OGC_11", nil)
  root.at("//foreword") or @log.add("OGC_12", nil)
  root.at("//bibdata/contributor[role/@type = 'author']/organization/" \
          "name") or
    @log.add("OGC_13", nil)
  root.at("//clause[@type = 'submitters' or @type = 'contributors']") or
    @log.add("OGC_14", nil)
end

#schema_fileObject



4
5
6
# File 'lib/metanorma/ogc/validate.rb', line 4

def schema_file
  "ogc.rng"
end

#section_validate(doc) ⇒ Object



62
63
64
65
66
67
# File 'lib/metanorma/ogc/validate.rb', line 62

def section_validate(doc)
  preface_sequence_validate(doc.root)
  execsummary_validate(doc.root)
  sections_sequence_validate(doc.root)
  super
end

#sections_sequence_validate(root) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/metanorma/ogc/validate.rb', line 102

def sections_sequence_validate(root)
  STANDARDTYPE.include?(@doctype) or return
  names = root.xpath("//sections/* | //bibliography/*")
  names = seqcheck(names, SEQ[0][:msg], SEQ[0][:val])
  names = seqcheck(names, SEQ[1][:msg], SEQ[1][:val])
  names = seqcheck(names, SEQ[2][:msg], SEQ[2][:val])
  n = names.shift
  if n&.at("./self::definitions")
    n = names.shift
  end
  if n.nil? || n.name != "clause"
    @log.add("OGC_8", nil)
    return
  end
  root.at("//references | //clause[descendant::references]" \
          "[not(parent::clause)]") or
    @log.add("OGC_9", nil)
end

#seqcheck(names, msg, accepted) ⇒ Object



91
92
93
94
95
96
97
98
99
100
# File 'lib/metanorma/ogc/validate.rb', line 91

def seqcheck(names, msg, accepted)
  n = names.shift
  return [] if n.nil?

  test = accepted.map { |a| n.at(a) }
  if test.all?(&:nil?)
    @log.add("OGC_7", nil, params: [msg])
  end
  names
end

#stage_type_validate(stage, doctype) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/metanorma/ogc/validate.rb', line 31

def stage_type_validate(stage, doctype)
  case doctype
  when "standard", "abstract-specification-topic", "draft-standard"
    %w(draft work-item-draft).include?(stage)
  when "community-standard"
    %w(draft swg-draft).include?(stage)
  when "best-practice", "community-practice"
    %w(draft swg-draft work-item-draft).include?(stage)
  else %w(swg-draft oab-review public-rfc tc-vote work-item-draft
          deprecated rescinded legacy).include?(stage)
  end and
    @log.add("OGC_2", nil, params: [stage, doctype])
end

#stage_validate(xmldoc) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/metanorma/ogc/validate.rb', line 22

def stage_validate(xmldoc)
  @doctype == "engineering-report" and return
  stage = xmldoc&.at("//bibdata/status/stage")&.text
  %w(draft swg-draft oab-review public-rfc tc-vote work-item-draft
     approved deprecated retired rescinded legacy).include? stage or
    @log.add("OGC_1", nil, params: [stage])
  stage_type_validate(stage, @doctype)
end

#title_validate(_root) ⇒ Object



8
9
10
# File 'lib/metanorma/ogc/validate.rb', line 8

def title_validate(_root)
  nil
end

#version_validate(xmldoc) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/metanorma/ogc/validate.rb', line 45

def version_validate(xmldoc)
  version = xmldoc.at("//bibdata/edition")&.text
  if %w(engineering-report discussion-paper).include? @doctype
    version.nil? or @log.add("OGC_3", nil, params: [@doctype])
  else
    version.nil? and @log.add("OGC_4", nil, params: [@doctype])
  end
end