Module: Metanorma::Standoc::Front

Included in:
Converter
Defined in:
lib/metanorma/converter/front.rb,
lib/metanorma/converter/front_ext.rb,
lib/metanorma/converter/front_title.rb,
lib/metanorma/converter/front_committee.rb,
lib/metanorma/converter/front_contributor.rb,
lib/metanorma/converter/front_organisation.rb

Instance Method Summary collapse

Instance Method Details

#add_title_xml(xml, content, language, type) ⇒ Object



31
32
33
34
# File 'lib/metanorma/converter/front_title.rb', line 31

def add_title_xml(xml, content, language, type)
  add_noko_elem(xml, "title", Metanorma::Utils::asciidoc_sub(content),
                language: language, type: type)
end

#committee_abbrevsObject



188
189
190
# File 'lib/metanorma/converter/front_organisation.rb', line 188

def committee_abbrevs
  { "technical-committee" => "TC" }
end

#committee_contrib_org_prep(node, type, agency, opts) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/metanorma/converter/front_committee.rb', line 25

def committee_contrib_org_prep(node, type, agency, opts)
  agency_arr, agency_abbrev =
    committee_org_prep_agency(node, type, agency, [], [])
  { source: [type], role: "author", desc: "committee",
    default_org: false, committee: true, logo: opts[:logo],
    subdivtype: type.sub(/^approval-/, "").tr("-", " ").capitalize,
    agency: agency_arr, agency_abbrev: }.compact
end

#committee_contributors(node, xml, agency, opts) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/metanorma/converter/front_committee.rb', line 8

def committee_contributors(node, xml, agency, opts)
  t = if c = node.attr("committee-types")
        c.split(",")&.map(&:strip)
      else (node)
      end
  v = t.first
  committee_number_or_name?(node, v, "") or return
  node.attr(v) or node.set_attr(v, "")
  o = committee_contrib_org_prep(node, v, agency, opts)
  o[:groups] = t
  org_contributor(node, xml, o)
end

#committee_ident(type, number, level) ⇒ Object



192
193
194
195
196
197
# File 'lib/metanorma/converter/front_organisation.rb', line 192

def committee_ident(type, number, level)
  number.nil? || number.empty? and return
  type ||= committee_abbrevs[level]
  type == "Other" and type = ""
  "#{type} #{number}".strip
end

#committee_number_or_name?(node, type, suffix) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/metanorma/converter/front_committee.rb', line 4

def committee_number_or_name?(node, type, suffix)
  node.attr("#{type}-number#{suffix}") || node.attr("#{type}#{suffix}")
end

#committee_org_prep_agency(node, type, agency, agency_arr, agency_abbr) ⇒ Object



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

def committee_org_prep_agency(node, type, agency, agency_arr, agency_abbr)
  i = 1
  suffix = ""
  while committee_number_or_name?(node, type, suffix)
    agency_arr << (node.attr("#{type}-agency#{suffix}") || agency)
    agency_abbr << node.attr("#{type}-agency-abbr#{suffix}")
    i += 1
    suffix = "_#{i}"
  end
  [agency_arr, agency_abbr]
end

#contrib_committee_build(xml, agency, committee) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/metanorma/converter/front_committee.rb', line 46

def contrib_committee_build(xml, agency, committee)
  contrib_committee_build_agency(xml, agency, committee)
  s = committee
  loop do
    contrib_committee_subdiv(xml, s)
    s = s[:subdiv] or break
  end
  add_noko_elem(xml, "abbreviation", committee[:agency_abbrev])
  full_committee_id(xml.parent)
end

#contrib_committee_build_agency(xml, agency, committee) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/metanorma/converter/front_committee.rb', line 57

def contrib_committee_build_agency(xml, agency, committee)
  if name = org_abbrev.invert[agency]
    committee[:agency_abbrev] = agency
    agency = name
  end
  add_noko_elem(xml, "name", agency)
end

#contrib_committee_subdiv(xml, committee) ⇒ Object



65
66
67
68
69
70
71
72
73
74
# File 'lib/metanorma/converter/front_committee.rb', line 65

def contrib_committee_subdiv(xml, committee)
  contributors_committees_filter_empty?(committee) and return
  xml.subdivision **attr_code(type: committee[:subdivtype],
                              subtype: committee[:type]) do |o|
    add_noko_elem(o, "name", committee[:name])
    add_noko_elem(o, "abbreviation", committee[:abbr])
    add_noko_elem(o, "identifier", committee[:ident])
    (o, committee[:logo])
  end
end

#contributors_committees_filter_empty?(committee) ⇒ Boolean

Returns:

  • (Boolean)


129
130
131
132
# File 'lib/metanorma/converter/front_committee.rb', line 129

def contributors_committees_filter_empty?(committee)
  (committee[:name].nil? || committee[:name].empty?) &&
    committee[:ident].nil?
end

#contributors_committees_nest1(committees) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
# File 'lib/metanorma/converter/front_committee.rb', line 134

def contributors_committees_nest1(committees)
  committees.empty? and return committees
  committees = committees.reverse
  committees.each_with_index do |m, i|
    i.zero? and next
    m.each_with_index do |m1, j|
      m1[:subdiv] = committees[i - 1][j]
    end
  end
  committees[-1]
end

#contributors_committees_pad_multiples(committees, node, group) ⇒ Object

ensure there is subcommittee, workgroup -number_2, -number_3 etc to parse multiple tech committees



119
120
121
122
123
124
125
126
127
# File 'lib/metanorma/converter/front_committee.rb', line 119

def contributors_committees_pad_multiples(committees, node, group)
  committees.each_with_index do |_r, j|
    suffix = j.zero? ? "" : "_#{j + 1}"
    node.attr("#{group}#{suffix}") or
      node.set_attr("#{group}#{suffix}", "")
    node.attr("#{group}-number#{suffix}") or
      node.set_attr("#{group}-number#{suffix}", "")
  end
end


108
109
110
111
112
113
114
# File 'lib/metanorma/converter/front_contributor.rb', line 108

def copyright_parse(node)
  opt = { source: ["copyright-holder", "publisher", "pub"],
          role: "publisher", default: default_publisher }
  ret = org_attrs_parse(node, opt)
  ret.empty? and ret = [{ name: "-" }]
  ret
end

#datetypesObject



101
102
103
104
105
# File 'lib/metanorma/converter/front.rb', line 101

def datetypes
  %w{ published accessed created implemented obsoleted
      confirmed updated corrected issued circulated unchanged received
      vote-started vote-ended announced }
end

#default_publisherObject



107
108
109
# File 'lib/metanorma/converter/front_organisation.rb', line 107

def default_publisher
  nil
end

#extract_org_attrs_address(node, opts, suffix) ⇒ Object



199
200
201
202
203
204
205
206
# File 'lib/metanorma/converter/front_organisation.rb', line 199

def extract_org_attrs_address(node, opts, suffix)
  %w(address phone fax email uri).each_with_object({}) do |a, m|
    opts[:source]&.each do |s|
      p = node.attr("#{s}-#{a}#{suffix}") and
        m[a.to_sym] = p
    end
  end
end

#extract_org_attrs_complex(node, opts, source, suffix) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
# File 'lib/metanorma/converter/front_organisation.rb', line 176

def extract_org_attrs_complex(node, opts, source, suffix)
  n = node.attr("#{source}-number#{suffix}") # for committees
  t = committee_ident(node.attr("#{source}-type#{suffix}"), n, source)
  { name: node.attr(source + suffix), ident: t,
    abbrev: node.attr("#{source}_abbr#{suffix}"),
    role: opts[:role], desc: opts[:desc],
    type: node.attr("#{source}-type#{suffix}"),
    subdiv: node.attr("#{source}_subdivision#{suffix}"),
    logo: node.attr("#{source}_logo#{suffix}") }.compact
    .merge(extract_org_attrs_address(node, opts, suffix))
end

#full_committee_agency_id(contrib) ⇒ Object



85
86
87
88
89
90
# File 'lib/metanorma/converter/front_committee.rb', line 85

def full_committee_agency_id(contrib)
  agency = contrib.at("./abbreviation")&.text
  ret = agency == default_publisher ? "" : "#{agency} "
  /^\s+/.match?(ret) and ret = ""
  ret
end

#full_committee_id(contrib) ⇒ Object



76
77
78
79
80
81
82
83
# File 'lib/metanorma/converter/front_committee.rb', line 76

def full_committee_id(contrib)
  ret = full_committee_agency_id(contrib)
  ids = contrib.xpath("./subdivision").map do |x|
    x.at("./identifier")&.text
  end.compact
  ins = contrib.at("./subdivision/identifier") and
    ins.next = "<identifier type='full'>#{ret}#{ids.join('/')}</identifier>"
end

#metadata(node, xml) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/metanorma/converter/front.rb', line 182

def (node, xml)
  title node, xml
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  (node, xml)
  xml.ext do
    (node, xml)
  end
end

#metadata_author(node, xml) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/metanorma/converter/front_contributor.rb', line 7

def (node, xml)
  org_author(node, xml)
  personal_author(node, xml)
  corporate_author = node.attr("corporate-author") ||
    node.attr("publisher") || default_publisher
  committee_contributors(node, xml, corporate_author, {})
end

#metadata_classifications(node, xml) ⇒ Object



174
175
176
177
178
179
180
# File 'lib/metanorma/converter/front.rb', line 174

def (node, xml)
  csv_split(node.attr("classification"), ",")&.each do |c|
    vals = c.split(/:/, 2)
    vals.size == 1 and vals = ["default", vals[0]]
    add_noko_elem(xml, "classification", vals[1], type: vals[0])
  end
end

#metadata_committee_types(_node) ⇒ Object



21
22
23
# File 'lib/metanorma/converter/front_committee.rb', line 21

def (_node)
  %w(technical-committee)
end


116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/metanorma/converter/front_contributor.rb', line 116

def (node, xml)
  copyright_parse(node).each do |p|
    xml.copyright do |c|
      c.from (node.attr("copyright-year") || Date.today.year)
      (p[:name].is_a?(String) && p[:name].match(/\p{L}/).nil?) or
        c.owner do |owner|
          owner.organization do |a|
            org_organization(node, a, p)
          end
        end
    end
  end
end

#metadata_coverpage_images(node, xml) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/metanorma/converter/front_ext.rb', line 39

def (node, xml)
  %w(coverpage-image innercoverpage-image tocside-image
     backpage-image).each do |n|
    if a = node.attr(n)
      xml.send n do |c|
        a.split(",").each do |x|
          c.image src: x
        end
      end
    end
  end
end

#metadata_date(node, xml) ⇒ Object



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

def (node, xml)
  datetypes.each { |t| (node, xml, t) }
  node.attributes.each_key do |a|
    a == "date" || /^date_\d+$/.match(a) or next
    type, date = node.attr(a).split(/ /, 2)
    type or next
    xml.date(type:) { |d| add_noko_elem(d, "on", date) }
  end
end

#metadata_date1(node, xml, type) ⇒ Object



94
95
96
97
98
99
# File 'lib/metanorma/converter/front.rb', line 94

def (node, xml, type)
  date = node.attr("#{type}-date")
  date and xml.date(type:) do |d|
    add_noko_elem(d, "on", date)
  end
end

#metadata_doctype(node, xml) ⇒ Object



26
27
28
29
# File 'lib/metanorma/converter/front_ext.rb', line 26

def (node, xml)
  add_noko_elem(xml, "doctype", doctype(node),
                abbreviation: node.attr("doctype-abbrev"))
end

#metadata_ext(node, ext) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/metanorma/converter/front_ext.rb', line 15

def (node, ext)
  (node, ext)
  (node, ext)
  (node, ext)
  (node, ext)
  structured_id(node, ext)
  (node, ext)
end

#metadata_flavor(_node, ext) ⇒ Object



35
36
37
# File 'lib/metanorma/converter/front_ext.rb', line 35

def (_node, ext)
  add_noko_elem(ext, "flavor", processor.new.asciidoctor_backend.to_s)
end

#metadata_getrelation(node, xml, type, desc = nil) ⇒ Object



149
150
151
152
153
154
# File 'lib/metanorma/converter/front.rb', line 149

def (node, xml, type, desc = nil)
  docs = node.attr(desc || type) or return
  @c.decode(docs).split(/;\s*/).each do |d|
    (d, xml, type, desc)
  end
end

#metadata_getrelation1(doc, xml, type, desc) ⇒ Object



156
157
158
159
160
161
162
163
164
165
# File 'lib/metanorma/converter/front.rb', line 156

def (doc, xml, type, desc)
  id = doc.split(/,\s*/)
  xml.relation type: relation_normalise(type) do |r|
    desc.nil? or r.description desc.tr("-", " ")
    fetch_ref(r, doc, nil, **{}) or r.bibitem do |b|
      add_noko_elem(b, "title", id[1] || "--")
      add_noko_elem(b, "docidentifier", id[0])
    end
  end
end

#metadata_ics(node, xml) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/metanorma/converter/front_ext.rb', line 4

def (node, xml)
  ics = node.attr("library-ics")
  ics&.split(/,\s*/)&.each do |i|
    xml.ics do |elem|
      add_noko_elem(elem, "code", i)
      icsdata = Isoics.fetch i
      elem.text_ icsdata.description
    end
  end
end

#metadata_id(node, xml) ⇒ Object

specifically the primary identifier



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

def (node, xml)
  if node.attr("docidentifier")
    (node, xml)
  else
    (node, xml)
  end
end

#metadata_id_build(node) ⇒ Object



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

def (node)
  part, subpart = node&.attr("partnumber")&.split("-")
  id = node.attr("docnumber") || ""
  id += "-#{part}" if part
  id += "-#{subpart}" if subpart
  id
end

#metadata_id_docidentifier(node, xml) ⇒ Object



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

def (node, xml)
  add_noko_elem(xml, "docidentifier", node.attr("docidentifier"),
                primary: "true",
                boilerplate: true,
                type: (node))
end

#metadata_id_nonprimary(node, xml) ⇒ Object



44
# File 'lib/metanorma/converter/front.rb', line 44

def (node, xml); end

#metadata_id_primary(node, xml) ⇒ Object



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

def (node, xml)
  id = (node)
  add_noko_elem(xml, "docidentifier", id, primary: "true",
                                          type: (node))
end

#metadata_id_primary_type(node) ⇒ Object



28
# File 'lib/metanorma/converter/front.rb', line 28

def (node); end

#metadata_keywords(node, xml) ⇒ Object



167
168
169
170
171
172
# File 'lib/metanorma/converter/front.rb', line 167

def (node, xml)
  node.attr("keywords") or return
  node.attr("keywords").split(/,\s*/).each do |kw|
    add_noko_elem(xml, "keyword", kw)
  end
end

#metadata_language(node, xml) ⇒ Object



117
118
119
120
# File 'lib/metanorma/converter/front.rb', line 117

def (node, xml)
  add_noko_elem(xml, "language", node.attr("language") || "en")
  add_noko_elem(xml, "locale", node.attr("locale"))
end

#metadata_note(node, xml) ⇒ Object



206
# File 'lib/metanorma/converter/front.rb', line 206

def (node, xml); end

#metadata_other_id(node, xml) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/metanorma/converter/front.rb', line 46

def (node, xml)
  (node, xml)
  a = node.attr("isbn") and
    add_noko_elem(xml, "docidentifier", a, type: "ISBN")
  a = node.attr("isbn10") and
    add_noko_elem(xml, "docidentifier", a, type: "ISBN10")
  csv_split(node.attr("docidentifier-additional"), ",")&.each do |n|
    t, v = n.split(":", 2)
    add_noko_elem(xml, "docidentifier", v, type: t)
  end
  add_noko_elem(xml, "docnumber", node.attr("docnumber"))
end

#metadata_publisher(node, xml) ⇒ Object



95
96
97
98
99
# File 'lib/metanorma/converter/front_contributor.rb', line 95

def (node, xml)
  o = { source: ["publisher", "pub"], role: "publisher",
        default: default_publisher }
  org_contributor(node, xml, o)
end

#metadata_relations(node, xml) ⇒ Object



135
136
137
138
139
140
141
142
# File 'lib/metanorma/converter/front.rb', line 135

def (node, xml)
  relaton_relations.each do |t|
    (node, xml, t)
  end
  relaton_relation_descriptions.each do |k, v|
    (node, xml, v, k)
  end
end

#metadata_script(node, xml) ⇒ Object



122
123
124
125
# File 'lib/metanorma/converter/front.rb', line 122

def (node, xml)
  add_noko_elem(xml, "script", node.attr("script") ||
              Metanorma::Utils.default_script(node.attr("language")))
end

#metadata_series(node, xml) ⇒ Object



208
# File 'lib/metanorma/converter/front.rb', line 208

def (node, xml); end

#metadata_source(node, xml) ⇒ Object



87
88
89
90
91
92
# File 'lib/metanorma/converter/front.rb', line 87

def (node, xml)
  add_noko_elem(xml, "uri", node.attr("uri"))
  %w(xml html pdf doc relaton).each do |t|
    add_noko_elem(xml, "uri", node.attr("#{t}-uri"), type: t)
  end
end

#metadata_sponsor(node, xml) ⇒ Object



101
102
103
104
105
106
# File 'lib/metanorma/converter/front_contributor.rb', line 101

def (node, xml)
  o = { source: ["sponsor"], role: "enabler" }
  org_contributor(node, xml, o)
  o = { source: ["authorizer"], role: "authorizer" }
  org_contributor(node, xml, o)
end

#metadata_status(node, xml) ⇒ Object



76
77
78
79
80
81
82
83
84
85
# File 'lib/metanorma/converter/front.rb', line 76

def (node, xml)
  xml.status do |s|
    add_noko_elem(s, "stage",
                  node.attr("status") || node.attr("docstage") ||
                  "published", abbreviation: node.attr("docstage-abbrev"))
    add_noko_elem(s, "substage", node.attr("docsubstage") ||
                  node.attr("substage"))
    add_noko_elem(s, "iteration", node.attr("iteration"))
  end
end

#metadata_subdoctype(node, xml) ⇒ Object



31
32
33
# File 'lib/metanorma/converter/front_ext.rb', line 31

def (node, xml)
  add_noko_elem(xml, "subdoctype", node.attr("docsubtype"))
end

#metadata_version(node, xml) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/metanorma/converter/front.rb', line 59

def (node, xml)
  draft = (node)
  add_noko_elem(xml, "edition", node.attr("edition"))
  draft || node.attr("revdate") or return
  xml.version do |v|
    add_noko_elem(v, "revision_date", node.attr("revdate"))
    add_noko_elem(v, "draft", draft)
  end
end

#metadata_version_value(node) ⇒ Object



69
70
71
72
73
74
# File 'lib/metanorma/converter/front.rb', line 69

def (node)
  draft = node.attr("version") and return draft
  draft = node.attr("draft") or return nil
  draft.empty? and return nil
  draft
end

#org_abbrevObject



111
112
113
# File 'lib/metanorma/converter/front_organisation.rb', line 111

def org_abbrev
  {}
end

#org_address(org, xml) ⇒ Object



54
55
56
57
58
59
# File 'lib/metanorma/converter/front_organisation.rb', line 54

def org_address(org, xml)
  p = org[:address] and xml.address do |ad|
    add_noko_elem(ad, "formattedAddress", p.gsub(/ \+\n/, "<br/>"))
  end
  org_contact(org, xml)
end

#org_attrs_add_committees(node, ret, opts, opts_orig) ⇒ Object



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

def org_attrs_add_committees(node, ret, opts, opts_orig)
  opts_orig[:groups].each_with_index do |g, i|
    i.zero? and next
    contributors_committees_pad_multiples(ret.first, node, g)
    opts = committee_contrib_org_prep(node, g, nil, opts_orig)
    ret << org_attrs_parse_core(node, opts).map do |x|
      x.merge(subdivtype: opts[:subdivtype])
    end
  end
  contributors_committees_nest1(ret)
end

#org_attrs_complex_parse(node, opts, source) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
# File 'lib/metanorma/converter/front_organisation.rb', line 164

def org_attrs_complex_parse(node, opts, source)
  i = 1
  suffix = ""
  ret = []
  while committee_number_or_name?(node, source, suffix)
    ret << extract_org_attrs_complex(node, opts, source, suffix)
    i += 1
    suffix = "_#{i}"
  end
  ret
end

#org_attrs_parse(node, opts) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/metanorma/converter/front_committee.rb', line 92

def org_attrs_parse(node, opts)
  opts_orig = opts.dup
  ret = []
  ret << org_attrs_parse_core(node, opts)&.map&.with_index do |x, i|
    x.merge(agency: opts.dig(:agency, i), subdivtype: opts[:subdivtype],
            agency_abbrev: opts.dig(:agency_abbrev, i), abbr: opts[:abbr],
            committee: opts[:committee], default_org: opts[:default_org])
  end
  if !opts_orig[:groups] || opts_orig[:groups].empty? then ret.first
  else org_attrs_add_committees(node, ret, opts, opts_orig)
  end
end

#org_attrs_parse_core(node, opts) ⇒ Object



142
143
144
145
146
# File 'lib/metanorma/converter/front_organisation.rb', line 142

def org_attrs_parse_core(node, opts)
  source = opts[:source]&.detect { |s| node.attr(s) }
  org_attrs_simple_parse(node, opts, source) ||
    org_attrs_complex_parse(node, opts, source)
end

#org_attrs_simple_parse(node, opts, source) ⇒ Object



148
149
150
151
152
153
154
155
# File 'lib/metanorma/converter/front_organisation.rb', line 148

def org_attrs_simple_parse(node, opts, source)
  !source and return org_attrs_simple_parse_no_source(node, opts)
  orgs = csv_split(node.attr(source))
  orgs.size > 1 and return orgs.map do |o|
    { name: o, role: opts[:role], desc: opts[:desc] }
  end
  nil
end

#org_attrs_simple_parse_no_source(node, opts) ⇒ Object



157
158
159
160
161
162
# File 'lib/metanorma/converter/front_organisation.rb', line 157

def org_attrs_simple_parse_no_source(node, opts)
  !opts[:default] && !opts[:name] and return []
  [{ name: opts[:name] || opts[:default],
     role: opts[:role], desc: opts[:desc] }
    .compact.merge(extract_org_attrs_address(node, opts, ""))]
end

#org_author(node, xml) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/metanorma/converter/front_contributor.rb', line 15

def org_author(node, xml)
  if node.attr("corporate-author")
    org_contributor(node, xml, { source: ["corporate-author"],
                                 role: "author" })
  else
    org_contributor(node, xml,
                    { source: ["publisher", "pub"], role: "author",
                      default: default_publisher })
  end
end

#org_contact(org, xml) ⇒ Object



61
62
63
64
65
66
# File 'lib/metanorma/converter/front_organisation.rb', line 61

def org_contact(org, xml)
  add_noko_elem(xml, "phone", org[:phone])
  add_noko_elem(xml, "phone", org[:fax], type: "fax")
  add_noko_elem(xml, "email", org[:email])
  add_noko_elem(xml, "uri", org[:uri])
end

#org_contributor(node, xml, opts) ⇒ Object



115
116
117
118
119
120
121
122
123
124
# File 'lib/metanorma/converter/front_organisation.rb', line 115

def org_contributor(node, xml, opts)
  org_attrs_parse(node, opts).each do |o|
    xml.contributor do |c|
      org_contributor_role(c, o)
      c.organization do |a|
        org_organization(node, a, o)
      end
    end
  end
end

#org_contributor_role(xml, org) ⇒ Object



126
127
128
129
130
# File 'lib/metanorma/converter/front_organisation.rb', line 126

def org_contributor_role(xml, org)
  xml.role type: org[:role] do |r|
    add_noko_elem(r, "description", org[:desc])
  end
end

#org_logo(xml, logo) ⇒ Object



101
102
103
104
105
# File 'lib/metanorma/converter/front_organisation.rb', line 101

def (xml, )
   and xml. do |l|
    l.image src: , mimetype: image_mimetype()
  end
end

#org_name_and_abbrev(org, orgname) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/metanorma/converter/front_organisation.rb', line 13

def org_name_and_abbrev(org, orgname)
  if org[:abbrev]
    [orgname, org[:abbrev]]
  else
    abbrevs = org_abbrev
    n = abbrevs.invert[orgname] and orgname = n
    [orgname, org_abbrev[orgname]]
  end
end

#org_organization(node, xml, org) ⇒ Object



132
133
134
135
136
137
138
139
140
# File 'lib/metanorma/converter/front_organisation.rb', line 132

def org_organization(node, xml, org)
  if org[:committee]
    contrib_committee_build(xml, org[:agency], org)
  else
    organization(xml, org[:name], node, !node.attr("publisher"), org)
    org_address(org, xml)
    (xml, org[:logo])
  end
end

#organization(org, orgname, node = nil, default_org = nil, attrs = {}) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/metanorma/converter/front_organisation.rb', line 4

def organization(org, orgname, node = nil, default_org = nil, attrs = {})
  orgname, abbr = org_name_and_abbrev(attrs, orgname)
  add_noko_elem(org, "name", orgname)
  default_org && (a = node&.attr("subdivision")) && !attrs[:subdiv] and
    subdivision(a, node&.attr("subdivision-abbr"), org)
  a = attrs[:subdiv] and subdivision(a, nil, org)
  add_noko_elem(org, "abbreviation", abbr)
end

#person_address(node, suffix, xml) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/metanorma/converter/front_organisation.rb', line 78

def person_address(node, suffix, xml)
  if node.attr("address#{suffix}")
    xml.address do |ad|
      add_noko_elem(ad, "formattedAddress",
                    node.attr("address#{suffix}").gsub(/ \+\n/, "<br/>"))
    end
  elsif node.attr("country#{suffix}") || node.attr("city#{suffix}")
    person_address_components(node, suffix, xml)
  end
end

#person_address_components(node, suffix, xml) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/metanorma/converter/front_organisation.rb', line 89

def person_address_components(node, suffix, xml)
  xml.address do |ad|
    %w(street city state country postcode).each do |k|
      add_noko_elem(ad, k, node.attr("#{k}#{suffix}"))
    end
  end
end

#person_affiliation(node, _xml, suffix, person) ⇒ Object



84
85
86
87
88
89
90
91
92
93
# File 'lib/metanorma/converter/front_contributor.rb', line 84

def person_affiliation(node, _xml, suffix, person)
  aff = node.attr("affiliation#{suffix}")
  pos = node.attr("contributor-position#{suffix}")
  (aff || pos) and person.affiliation do |a|
    add_noko_elem(a, "name", pos)
    aff and a.organization do |o|
      person_organization(node, suffix, o)
    end
  end
end

#person_credentials(node, _xml, suffix, person) ⇒ Object



79
80
81
82
# File 'lib/metanorma/converter/front_contributor.rb', line 79

def person_credentials(node, _xml, suffix, person)
  add_noko_elem(person, "credentials",
                node.attr("contributor-credentials#{suffix}"))
end

#person_name(node, _xml, suffix, person) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/metanorma/converter/front_contributor.rb', line 67

def person_name(node, _xml, suffix, person)
  person.name do |n|
    if node.attr("fullname#{suffix}")
      add_noko_elem(n, "completename", node.attr("fullname#{suffix}"))
    else
      add_noko_elem(n, "forename", node.attr("givenname#{suffix}"))
      add_noko_elem(n, "initial", node.attr("initials#{suffix}"))
      add_noko_elem(n, "surname", node.attr("surname#{suffix}"))
    end
  end
end

#person_org_logo(node, suffix, xml) ⇒ Object



97
98
99
# File 'lib/metanorma/converter/front_organisation.rb', line 97

def (node, suffix, xml)
  p = node.attr("affiliation_logo#{suffix}") and (xml, p)
end

#person_organization(node, suffix, xml) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/metanorma/converter/front_organisation.rb', line 68

def person_organization(node, suffix, xml)
  add_noko_elem(xml, "name", node.attr("affiliation#{suffix}"))
  add_noko_elem(xml, "abbreviation",
                node.attr("affiliation_abbrev#{suffix}"))
  a = node.attr("affiliation_subdiv#{suffix}") and
    subdivision(a, nil, xml)
  person_address(node, suffix, xml)
  (node, suffix, xml)
end

#personal_author(node, xml) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/metanorma/converter/front_contributor.rb', line 26

def personal_author(node, xml)
  (node.attr("fullname") || node.attr("surname")) and
    personal_author1(node, xml, "")
  i = 2
  while node.attr("fullname_#{i}") || node.attr("surname_#{i}")
    personal_author1(node, xml, "_#{i}")
    i += 1
  end
end

#personal_author1(node, xml, suffix) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/metanorma/converter/front_contributor.rb', line 55

def personal_author1(node, xml, suffix)
  xml.contributor do |c|
    personal_role(node, c, suffix)
    c.person do |p|
      person_name(node, xml, suffix, p)
      person_credentials(node, xml, suffix, p)
      person_affiliation(node, xml, suffix, p)
      personal_contact(node, suffix, p)
    end
  end
end

#personal_contact(node, suffix, person) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/metanorma/converter/front_contributor.rb', line 44

def personal_contact(node, suffix, person)
  node.attr("phone#{suffix}") and
    add_noko_elem(person, "phone", node.attr("phone#{suffix}"))
  node.attr("fax#{suffix}") and
    add_noko_elem(person, "phone", node.attr("fax#{suffix}"), type: "fax")
  node.attr("email#{suffix}") and
    add_noko_elem(person, "email", node.attr("email#{suffix}"))
  node.attr("contributor-uri#{suffix}") and
    add_noko_elem(person, "uri", node.attr("contributor-uri#{suffix}"))
end

#personal_role(node, contrib, suffix) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/metanorma/converter/front_contributor.rb', line 36

def personal_role(node, contrib, suffix)
  type = node.attr("role#{suffix}")&.downcase || "author"
  desc = node.attr("role-description#{suffix}")
  contrib.role type: type do |r|
    add_noko_elem(r, "description", desc)
  end
end

#relation_normalise(type) ⇒ Object



144
145
146
147
# File 'lib/metanorma/converter/front.rb', line 144

def relation_normalise(type)
  type.sub(/-by$/, "By").sub(/-of$/, "Of").sub(/-from$/, "From")
    .sub(/-in$/, "In").sub(/^has-([a-z])/) { "has#{$1.upcase}" }
end

#relaton_relation_descriptionsObject



131
132
133
# File 'lib/metanorma/converter/front.rb', line 131

def relaton_relation_descriptions
  {}
end

#relaton_relationsObject



127
128
129
# File 'lib/metanorma/converter/front.rb', line 127

def relaton_relations
  %w(part-of translated-from)
end

#structured_id(node, xml) ⇒ Object



24
# File 'lib/metanorma/converter/front_ext.rb', line 24

def structured_id(node, xml); end

#subdiv_build(list, org) ⇒ Object



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

def subdiv_build(list, org)
  list.empty? and return
  org.subdivision **attr_code(type: list[0][:type]) do |s|
    add_noko_elem(s, "name", list[0][:value])
    subdiv_build(list[1..], s)
    add_noko_elem(s, "abbreviation", list[0][:abbr])
  end
end

#subdivision(attr, abbr, org) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/metanorma/converter/front_organisation.rb', line 23

def subdivision(attr, abbr, org)
  abbrs = csv_split(abbr) || []
  subdivs = csv_split(attr, ";")
  subdivs.size == abbrs.size or abbrs = []
  subdivs.each_with_index do |s, i|
    subdivision1(s, abbrs[i], org)
  end
end

#subdivision1(attr, abbr, org) ⇒ Object



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

def subdivision1(attr, abbr, org)
  m = csv_split(attr, ",").map do |s1|
    t, v = s1.split(":", 2).map(&:strip)
    if v.nil?
      v = t
      t = nil
    end
    { type: t, value: v }
  end
  abbr and m[0][:abbr] = abbr
  subdiv_build(m, org)
end

#title(node, xml) ⇒ Object



4
5
6
7
8
9
# File 'lib/metanorma/converter/front_title.rb', line 4

def title(node, xml)
  title_main(node, xml)
  title_other(node, xml)
  title_fallback(node, xml)
  title_nums(node, xml, @lang)
end

#title_fallback(node, xml) ⇒ Object



36
37
38
39
# File 'lib/metanorma/converter/front_title.rb', line 36

def title_fallback(node, xml)
  xml.parent.at("./title[not(normalize-space(.)='')]") and return
  add_title_xml(xml, node.attr("doctitle"), @lang, "main")
end

#title_main(node, xml) ⇒ Object

English plain title: :title: or implicit, typed as main



12
13
14
15
16
17
# File 'lib/metanorma/converter/front_title.rb', line 12

def title_main(node, xml)
  title = node.attr("title")
  title.nil? || title.empty? and return
  node.attr("title-en") and return
  add_title_xml(xml, title, "en", "main")
end

#title_num_prefix(key, value, xml, lang) ⇒ Object



60
61
62
63
64
65
# File 'lib/metanorma/converter/front_title.rb', line 60

def title_num_prefix(key, value, xml, lang)
  prefix = @i18n_cache[lang].get.dig("title_prefixes", key.to_s) or return
  value && !value.empty? or return
  title = "#{prefix}&#xa0;#{value}"
  add_title_xml(xml, title, lang, "title-#{key}-prefix")
end

#title_nums(node, xml, lang) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/metanorma/converter/front_title.rb', line 41

def title_nums(node, xml, lang)
  @i18n_cache ||= {}
  @i18n_cache[lang] ||= isodoc(lang, ::Metanorma::Utils::default_script(lang),
                               nil, i18nyaml_path(node)).i18n
  ret = title_nums_prep(node)
  ret[:part] && ret[:subpart] and ret[:part] += "&#x2013;#{ret[:subpart]}"
  ret.delete(:subpart)
  ret.each do |k, v|
    title_num_prefix(k, v, xml, lang)
  end
end

#title_nums_prep(node) ⇒ Object



53
54
55
56
57
58
# File 'lib/metanorma/converter/front_title.rb', line 53

def title_nums_prep(node)
  part, subpart = node.attr("partnumber")&.split("-")
  { part:, subpart:, amendment: node.attr("amendment-number"),
    corrigendum: node.attr("corrigendum-number"),
    addendum: node.attr("addendum-number") }
end

#title_other(node, xml) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/metanorma/converter/front_title.rb', line 19

def title_other(node, xml)
  node.attributes.each do |k, v|
    /^title-(?<remainder>.+)$/ =~ k or next
    type, language = remainder.split("-", 2)
    if language.nil?
      language = type
      type = "main"
    end
    add_title_xml(xml, v, language, type)
  end
end