Module: Metanorma::Standoc::Front

Included in:
Converter
Defined in:
lib/metanorma/standoc/front.rb,
lib/metanorma/standoc/front_contributor.rb

Instance Method Summary collapse

Instance Method Details

#committee_component(compname, node, out) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/metanorma/standoc/front_contributor.rb', line 10

def committee_component(compname, node, out)
  out.send compname.gsub(/-/, "_"), node.attr(compname),
           **attr_code(number: node.attr("#{compname}-number"),
                       type: node.attr("#{compname}-type"))
  i = 2
  while node.attr(compname + "_#{i}")
    out.send compname.gsub(/-/, "_"), node.attr(compname + "_#{i}"),
             **attr_code(number: node.attr("#{compname}-number_#{i}"),
                         type: node.attr("#{compname}-type_#{i}"))
    i += 1
  end
end

#datetypesObject



82
83
84
85
86
# File 'lib/metanorma/standoc/front.rb', line 82

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

#default_publisherObject



156
157
158
# File 'lib/metanorma/standoc/front_contributor.rb', line 156

def default_publisher
  nil
end

#metadata(node, xml) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/metanorma/standoc/front.rb', line 167

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)
  xml.ext do
    (node, xml)
  end
end

#metadata_author(node, xml) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/metanorma/standoc/front_contributor.rb', line 47

def (node, xml)
  csv_split(node.attr("publisher") || default_publisher || "")
    &.each do |p|
    xml.contributor do |c|
      c.role type: "author"
      c.organization do |a|
        organization(a, p, false, node, !node.attr("publisher"))
      end
    end
  end
  personal_author(node, xml)
end

#metadata_classifications(node, xml) ⇒ Object



159
160
161
162
163
164
165
# File 'lib/metanorma/standoc/front.rb', line 159

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

#metadata_committee(node, xml) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/metanorma/standoc/front.rb', line 46

def (node, xml)
  return unless node.attr("technical-committee")

  xml.editorialgroup do |a|
    committee_component("technical-committee", node, a)
  end
end


176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/metanorma/standoc/front_contributor.rb', line 176

def (node, xml)
  pub = node.attr("copyright-holder") || node.attr("publisher")
  csv_split(pub || default_publisher || "-")&.each do |p|
    xml.copyright do |c|
      c.from (node.attr("copyright-year") || Date.today.year)
      p.match(/[A-Za-z]/).nil? or c.owner do |owner|
        owner.organization do |a|
          organization(a, p, true, node, !pub)
        end
      end
    end
  end
end

#metadata_date(node, xml) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/metanorma/standoc/front.rb', line 88

def (node, xml)
  datetypes.each { |t| (node, xml, t) }
  node.attributes.each_key do |a|
    next unless a == "date" || /^date_\d+$/.match(a)

    type, date = node.attr(a).split(/ /, 2)
    type or next
    xml.date type: type do |d|
      d.on date
    end
  end
end

#metadata_date1(node, xml, type) ⇒ Object



75
76
77
78
79
80
# File 'lib/metanorma/standoc/front.rb', line 75

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

#metadata_doctype(node, xml) ⇒ Object



197
198
199
# File 'lib/metanorma/standoc/front.rb', line 197

def (node, xml)
  xml.doctype doctype(node)
end

#metadata_ext(node, ext) ⇒ Object



190
191
192
193
194
195
# File 'lib/metanorma/standoc/front.rb', line 190

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

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



133
134
135
136
137
138
# File 'lib/metanorma/standoc/front.rb', line 133

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



140
141
142
143
144
145
146
147
148
149
# File 'lib/metanorma/standoc/front.rb', line 140

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

#metadata_ics(node, xml) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/metanorma/standoc/front.rb', line 54

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

#metadata_id(node, xml) ⇒ Object



11
12
13
14
15
# File 'lib/metanorma/standoc/front.rb', line 11

def (node, xml)
  id = node.attr("docidentifier") || (node)
  xml.docidentifier id
  xml.docnumber node.attr("docnumber")
end

#metadata_id_build(node) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/metanorma/standoc/front.rb', line 17

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

#metadata_keywords(node, xml) ⇒ Object



151
152
153
154
155
156
157
# File 'lib/metanorma/standoc/front.rb', line 151

def (node, xml)
  return unless node.attr("keywords")

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

#metadata_language(node, xml) ⇒ Object



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

def (node, xml)
  xml.language (node.attr("language") || "en")
  l = node.attr("locale") and xml.locale l
end

#metadata_note(node, xml) ⇒ Object



205
# File 'lib/metanorma/standoc/front.rb', line 205

def (node, xml); end

#metadata_other_id(node, xml) ⇒ Object



25
26
27
28
# File 'lib/metanorma/standoc/front.rb', line 25

def (node, xml)
  a = node.attr("isbn") and xml.docidentifier a, type: "ISBN"
  a = node.attr("isbn10") and xml.docidentifier a, type: "ISBN10"
end

#metadata_publisher(node, xml) ⇒ Object



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

def (node, xml)
  publishers = node.attr("publisher") || default_publisher || return
  csv_split(publishers)&.each do |p|
    xml.contributor do |c|
      c.role type: "publisher"
      c.organization do |a|
        organization(a, p, true, node, !node.attr("publisher"))
      end
    end
  end
end

#metadata_relations(node, xml) ⇒ Object



119
120
121
122
123
124
125
126
# File 'lib/metanorma/standoc/front.rb', line 119

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



106
107
108
109
# File 'lib/metanorma/standoc/front.rb', line 106

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

#metadata_series(node, xml) ⇒ Object



207
# File 'lib/metanorma/standoc/front.rb', line 207

def (node, xml); end

#metadata_source(node, xml) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/metanorma/standoc/front.rb', line 65

def (node, xml)
  node.attr("uri") && xml.uri(node.attr("uri"))
  node.attr("xml-uri") && xml.uri(node.attr("xml-uri"), type: "xml")
  node.attr("html-uri") && xml.uri(node.attr("html-uri"), type: "html")
  node.attr("pdf-uri") && xml.uri(node.attr("pdf-uri"), type: "pdf")
  node.attr("doc-uri") && xml.uri(node.attr("doc-uri"), type: "doc")
  node.attr("relaton-uri") && xml.uri(node.attr("relaton-uri"),
                                      type: "relaton")
end

#metadata_status(node, xml) ⇒ Object



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

def (node, xml)
  xml.status do |s|
    s.stage (node.attr("status") || node.attr("docstage") || "published")
    node.attr("docsubstage") and s.substage node.attr("docsubstage")
    node.attr("iteration") and s.iteration node.attr("iteration")
  end
end

#metadata_subdoctype(node, xml) ⇒ Object



201
202
203
# File 'lib/metanorma/standoc/front.rb', line 201

def (node, xml)
  s = node.attr("docsubtype") and xml.subdoctype s
end

#metadata_version(node, xml) ⇒ Object



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

def (node, xml)
  xml.edition node.attr("edition") if node.attr("edition")
  xml.version do |v|
    v.revision_date node.attr("revdate") if node.attr("revdate")
    v.draft node.attr("draft") if node.attr("draft")
  end
end

#org_abbrevObject



160
161
162
# File 'lib/metanorma/standoc/front_contributor.rb', line 160

def org_abbrev
  {}
end

#org_address(node, person) ⇒ Object



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

def org_address(node, person)
  node.attr("pub-address") and person.address do |ad|
    ad.formattedAddress do |f|
      f << node.attr("pub-address").gsub(/ \+\n/, "<br/>")
    end
  end
  node.attr("pub-phone") and person.phone node.attr("pub-phone")
  node.attr("pub-fax") and
    person.phone node.attr("pub-fax"), type: "fax"
  node.attr("pub-email") and person.email node.attr("pub-email")
  node.attr("pub-uri") and person.uri node.attr("pub-uri")
end

#organization(org, orgname, is_pub, node = nil, default_org = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/metanorma/standoc/front_contributor.rb', line 23

def organization(org, orgname, is_pub, node = nil, default_org = nil)
  abbrevs = org_abbrev
  n = abbrevs.invert[orgname] and orgname = n
  org.name orgname
  default_org and a = node.attr("subdivision") and org.subdivision a
  abbr = org_abbrev[orgname]
  default_org && b = node.attr("subdivision-abbr") and abbr = b
  abbr and org.abbreviation abbr
  is_pub && node and org_address(node, org)
end

#person_address(node, suffix, xml) ⇒ Object



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

def person_address(node, suffix, xml)
  if node.attr("address#{suffix}")
    xml.address do |ad|
      ad.formattedAddress do |f|
        f << node.attr("address#{suffix}").gsub(/ \+\n/, "<br/>")
      end
    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



146
147
148
149
150
151
152
153
154
# File 'lib/metanorma/standoc/front_contributor.rb', line 146

def person_address_components(node, suffix, xml)
  xml.address do |ad|
    s = node.attr("street#{suffix}") and ad.street s
    s = node.attr("city#{suffix}") and ad.city s
    s = node.attr("state#{suffix}") and ad.state s
    s = node.attr("country#{suffix}") and ad.country s
    s = node.attr("postcode#{suffix}") and ad.postcode s
  end
end

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



113
114
115
116
117
118
119
120
121
122
# File 'lib/metanorma/standoc/front_contributor.rb', line 113

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|
    pos and a.name { |n| n << pos }
    aff and a.organization do |o|
      person_organization(node, suffix, o)
    end
  end
end

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



108
109
110
111
# File 'lib/metanorma/standoc/front_contributor.rb', line 108

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

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



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/metanorma/standoc/front_contributor.rb', line 96

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

#person_organization(node, suffix, xml) ⇒ Object



124
125
126
127
128
129
130
131
132
# File 'lib/metanorma/standoc/front_contributor.rb', line 124

def person_organization(node, suffix, xml)
  xml.name node.attr("affiliation#{suffix}")
  abbr = node.attr("affiliation_abbrev#{suffix}") and
    xml.abbreviation abbr
  csv_split(node.attr("affiliation_subdiv#{suffix}"))&.each do |s|
    xml.subdivision s
  end
  person_address(node, suffix, xml)
end

#personal_author(node, xml) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/metanorma/standoc/front_contributor.rb', line 60

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



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

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



75
76
77
78
79
80
81
82
# File 'lib/metanorma/standoc/front_contributor.rb', line 75

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

#personal_role(node, contrib, suffix) ⇒ Object



70
71
72
73
# File 'lib/metanorma/standoc/front_contributor.rb', line 70

def personal_role(node, contrib, suffix)
  type = node.attr("role#{suffix}")&.downcase || "author"
  contrib.role type: type
end

#relation_normalise(type) ⇒ Object



128
129
130
131
# File 'lib/metanorma/standoc/front.rb', line 128

def relation_normalise(type)
  type.sub(/-by$/, "By").sub(/-of$/, "Of").sub(/-from$/, "From")
    .sub(/-in$/, "In")
end

#relaton_relation_descriptionsObject



115
116
117
# File 'lib/metanorma/standoc/front.rb', line 115

def relaton_relation_descriptions
  {}
end

#relaton_relationsObject



111
112
113
# File 'lib/metanorma/standoc/front.rb', line 111

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

#title(node, xml) ⇒ Object



209
210
211
212
# File 'lib/metanorma/standoc/front.rb', line 209

def title(node, xml)
  title_english(node, xml)
  title_otherlangs(node, xml)
end

#title_english(node, xml) ⇒ Object



214
215
216
217
218
219
220
221
222
223
# File 'lib/metanorma/standoc/front.rb', line 214

def title_english(node, xml)
  ["en"].each do |lang|
    at = { language: lang, format: "text/plain" }
    xml.title **attr_code(at) do |t|
      t << (Metanorma::Utils::asciidoc_sub(node.attr("title") ||
                                           node.attr("title-en")) ||
      node.title)
    end
  end
end

#title_otherlangs(node, xml) ⇒ Object



225
226
227
228
229
230
231
232
# File 'lib/metanorma/standoc/front.rb', line 225

def title_otherlangs(node, xml)
  node.attributes.each do |k, v|
    next unless /^title-(?<titlelang>.+)$/ =~ k
    next if titlelang == "en"

    xml.title v, { language: titlelang, format: "text/plain" }
  end
end