Module: Metanorma::Standoc::Validate::Section
- Included in:
- Metanorma::Standoc::Validate
- Defined in:
- lib/metanorma/validate/section.rb
Instance Method Summary collapse
- #asset_style(root) ⇒ Object
- #asset_title_style(root) ⇒ Object
- #callouts_error(elem, callouts, annotations) ⇒ Object
- #hanging_para_style(root) ⇒ Object
- #norm_ref_validate(doc) ⇒ Object
- #reject_metanorma_extension ⇒ Object
- #section_validate(doc) ⇒ Object
- #sourcecode_style(root) ⇒ Object
- #style_warning(node, msg, text = nil) ⇒ Object
Instance Method Details
#asset_style(root) ⇒ Object
56 57 58 |
# File 'lib/metanorma/validate/section.rb', line 56 def asset_style(root) asset_title_style(root) end |
#asset_title_style(root) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/metanorma/validate/section.rb', line 45 def asset_title_style(root) root.xpath("//figure[image][not(name)]") .reject(&).each do |node| style_warning(node, "Figure should have title", nil) end (root.xpath("//table[not(name)]") - root.xpath("//sourcecode//table")) .reject(&).each do |node| style_warning(node, "Table should have title", nil) end end |
#callouts_error(elem, callouts, annotations) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/metanorma/validate/section.rb', line 21 def callouts_error(elem, callouts, annotations) callouts.size != annotations.size or return if annotations.empty? @log.add("STANDOC_62", elem) else @log.add("STANDOC_47", elem, params: [callouts.size, annotations.size]) end end |
#hanging_para_style(root) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/metanorma/validate/section.rb', line 60 def hanging_para_style(root) root.xpath("//clause | //annex | //foreword | //introduction | " \ "//acknowledgements | //executivesummary").each do |c| c.at("./clause") or next c.elements.reject do |n| %w(clause title).include? n.name end.empty? and next style_warning(c, "Hanging paragraph in clause") end end |
#norm_ref_validate(doc) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/metanorma/validate/section.rb', line 71 def norm_ref_validate(doc) doc.xpath("//references[@normative = 'true']/bibitem").each do |b| docid = b.at("./docidentifier[@type = 'metanorma']") or next /^\[\d+\]$/.match?(docid.text) or next @log.add("STANDOC_49", b) end end |
#reject_metanorma_extension ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/metanorma/validate/section.rb', line 37 def ->(node) { node.ancestors.detect do |x| x.name == "metanorma-extension" end } end |
#section_validate(doc) ⇒ Object
7 8 9 10 11 |
# File 'lib/metanorma/validate/section.rb', line 7 def section_validate(doc) sourcecode_style(doc.root) hanging_para_style(doc.root) asset_style(doc.root) end |
#sourcecode_style(root) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/metanorma/validate/section.rb', line 13 def sourcecode_style(root) root.xpath("//sourcecode").each do |x| callouts = x.xpath("./body/callout") annotations = x.xpath("./callout-annotation") callouts_error(x, callouts, annotations) end end |
#style_warning(node, msg, text = nil) ⇒ Object
31 32 33 34 35 |
# File 'lib/metanorma/validate/section.rb', line 31 def style_warning(node, msg, text = nil) w = msg w += ": #{text}" if text @log.add("STANDOC_48", node, params: [w]) end |