Class: Metanorma::Iho::Converter

Inherits:
Generic::Converter
  • Object
show all
Defined in:
lib/metanorma/iho/log.rb,
lib/metanorma/iho/front.rb,
lib/metanorma/iho/converter.rb

Constant Summary collapse

IHO_LOG_MESSAGES =
{
  # rubocop:disable Naming/VariableNumber
  "IHO_1": { category: "AsciiDoc Input",
             error: "Missing workgroup attribute for document",
             severity: 2 },
}.freeze
SERIESNAME =
{
  B: "Bathymetric",
  C: "Capacity Building",
  M: "Miscellaneous",
  P: "Periodic",
  S: "Standards and Specifications",
}.freeze
TITLE_COMPONENTS =
{
  main: {},
  part: { id: :partid },
  annex: { id: :annexid, info: :infoannex },
  appendix: { id: :appendixid },
  supplement: { id: :supplementid },
}.freeze
TITLE_ID_LABELS =
{ main: "", annex: "Annex", appendix: "Appendix",
part: "Part", supplement: "Supplement" }.freeze

Instance Method Summary collapse

Instance Method Details

#configurationObject



14
15
16
# File 'lib/metanorma/iho/converter.rb', line 14

def configuration
  Metanorma::Iho.configuration
end

#doc_converter(node) ⇒ Object



33
34
35
# File 'lib/metanorma/iho/converter.rb', line 33

def doc_converter(node)
  IsoDoc::Iho::WordConvert.new(doc_extract_attributes(node))
end

#full_title(metadata, xml) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/metanorma/iho/front.rb', line 84

def full_title(, xml)
  parts = TITLE_COMPONENTS.keys.each_with_object([]) do |p, acc|
    acc << full_title_part(, p, TITLE_COMPONENTS[p][:id],
                           TITLE_COMPONENTS[p][:info])
  end
  add_title_xml(xml, parts.compact.join(", "), "en", "main")
end

#full_title_part(metadata, type, id, info) ⇒ Object



95
96
97
98
99
100
101
102
103
# File 'lib/metanorma/iho/front.rb', line 95

def full_title_part(, type, id, info)
  [type] or return nil
  lbl = TITLE_ID_LABELS[type.to_sym]
  [id] and lbl += " #{[id]}"
  [info] and lbl += " (Informative)"
  %i(appendix supplement part).include?(type) and lbl += ":"
  lbl == :main or lbl += " "
  lbl + [type]
end

#full_title_prep(node) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/metanorma/iho/front.rb', line 105

def full_title_prep(node)
  { main: node.attr("title") || node.title,
    annex: node.attr("title-annex"),
    appendix: node.attr("title-appendix"),
    supplement: node.attr("title-supplement"),
    part: node.attr("title-part"),
    partid: node.attr("partnumber"),
    annexid: node.attr("annex-id"),
    appendixid: node.attr("appendix-id"),
    supplementid: node.attr("supplement-id"),
    infoannex: node.attr("semantic-metadata-annex-informative") == "true" }
end

#html_converter(node) ⇒ Object



24
25
26
# File 'lib/metanorma/iho/converter.rb', line 24

def html_converter(node)
  IsoDoc::Iho::HtmlConvert.new(html_extract_attributes(node))
end

#log_messagesObject

rubocop:enable Naming/VariableNumber



12
13
14
# File 'lib/metanorma/iho/log.rb', line 12

def log_messages
  super.merge(IHO_LOG_MESSAGES)
end

#metadata_commentperiod(node, xml) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/metanorma/iho/front.rb', line 28

def (node, xml)
  from = node.attr("comment-from") or return
  xml.commentperiod do |c|
    add_noko_elem(c, "from", from)
    add_noko_elem(c, "to", node.attr("comment-to"))
  end
end

#metadata_ext(node, ext) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/metanorma/iho/front.rb', line 20

def (node, ext)
  unless node.attr("workgroup")
    @log.add("IHO_1", nil)
  end
  super
  (node, ext)
end

#metadata_series(node, xml) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/metanorma/iho/front.rb', line 12

def (node, xml)
  series = node.attr("series") or return
  xml.series type: "main" do |s|
    add_noko_elem(s, "title", SERIESNAME[series.to_sym] || "N/A")
    add_noko_elem(s, "abbreviation", series)
  end
end

#metadata_version(node, xml) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/metanorma/iho/front.rb', line 36

def (node, xml)
  if node.attr("edition-major")
    ed = node.attr("edition-major")
    e1 = node.attr("edition-minor") and ed += ".#{e1}"
    (e2 = node.attr("edition-patch")) && e1 and ed += ".#{e2}"
    node.set_attribute("edition", ed)
  end
  super
end

#pdf_converter(node) ⇒ Object



28
29
30
31
# File 'lib/metanorma/iho/converter.rb', line 28

def pdf_converter(node)
  node.attr("no-pdf") and return nil
  IsoDoc::Iho::PdfConvert.new(pdf_extract_attributes(node))
end

#presentation_xml_converter(node) ⇒ Object



18
19
20
21
22
# File 'lib/metanorma/iho/converter.rb', line 18

def presentation_xml_converter(node)
  IsoDoc::Iho::PresentationXMLConvert
    .new(html_extract_attributes(node)
    .merge(output_formats: ::Metanorma::Iho::Processor.new.output_formats))
end

#support_appendix?(_node) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/metanorma/iho/converter.rb', line 10

def support_appendix?(_node)
  true
end

#title(node, xml) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/metanorma/iho/front.rb', line 51

def title(node, xml)
  m = full_title_prep(node)
  full_title(m, xml)
  title_main(node, xml)
  %i(appendix annex part supplement).each do |w|
    typed_title(m, xml, w)
  end
  title_fallback(node, xml)
  title_nums(node, xml, @lang)
end

#title_main(node, xml) ⇒ Object



46
47
48
49
# File 'lib/metanorma/iho/front.rb', line 46

def title_main(node, xml)
  title = node.attr("title") or return
  add_title_xml(xml, title, "en", "title-main")
end

#title_nums_prep(node) ⇒ Object



77
78
79
80
81
82
# File 'lib/metanorma/iho/front.rb', line 77

def title_nums_prep(node)
  { part: node.attr("partnumber"),
    annex: node.attr("annex-id"),
    appendix: node.attr("appendix-id"),
    supplement: node.attr("supplement-id") }
end

#typed_title(metadata, xml, type) ⇒ Object



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

def typed_title(, xml, type)
  [type] or return
  title = full_title_part(, type, TITLE_COMPONENTS[type][:id],
                          TITLE_COMPONENTS[type][:info])
  add_title_xml(xml, title, "en", "title-#{type}")
end