Class: IsoDoc::Iho::PresentationXMLConvert
- Inherits:
-
Generic::PresentationXMLConvert
- Object
- Generic::PresentationXMLConvert
- IsoDoc::Iho::PresentationXMLConvert
show all
- Includes:
- Init
- Defined in:
- lib/isodoc/iho/presentation_xml_convert.rb
Constant Summary
collapse
- UPDATE_RELATIONS =
<<~XPATH.freeze
//bibdata/relation[@type = 'updatedBy' or @type = 'merges' or @type = 'splits' or @type = 'hasDraft']/bibitem
XPATH
Instance Method Summary
collapse
-
#bibdata(docxml) ⇒ Object
-
#biblio_ref_entry_code(ordinal, _idents, _ids, _standard, _datefn, _bib) ⇒ Object
-
#clausedelim ⇒ Object
-
#collapse_term(docxml) ⇒ Object
-
#collapse_term1(term) ⇒ Object
-
#ddMMMyyyy(isodate) ⇒ Object
-
#dochistory(docxml) ⇒ Object
-
#dochistory_contributor(contrib) ⇒ Object
-
#dochistory_contributors(item) ⇒ Object
-
#dochistory_date(item) ⇒ Object
-
#dochistory_description(item) ⇒ Object
-
#format_personalname(contrib) ⇒ Object
-
#generate_dochistory(updates, pref) ⇒ Object
-
#generate_dochistory_row(item) ⇒ Object
-
#middle_title(docxml) ⇒ Object
-
#norm_ref_entry_code(ordinal, _idents, _ids, _standard, _datefn, _bib) ⇒ Object
-
#omit_docid_prefix(prefix) ⇒ Object
-
#preface_insert_point(docxml) ⇒ Object
-
#term1(elem) ⇒ Object
-
#termcleanup(docxml) ⇒ Object
-
#termsource1(elem) ⇒ Object
-
#termsource_label(elem, sources) ⇒ Object
-
#ul_label_list(_elem) ⇒ Object
Methods included from Init
#bibrenderer, #i18n_init, #info, #metadata_init, #xref_init
Instance Method Details
#bibdata(docxml) ⇒ Object
20
21
22
23
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 20
def bibdata(docxml)
super
dochistory(docxml)
end
|
#biblio_ref_entry_code(ordinal, _idents, _ids, _standard, _datefn, _bib) ⇒ Object
13
14
15
16
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 13
def biblio_ref_entry_code(ordinal, _idents, _ids, _standard, _datefn,
_bib)
"[#{ordinal}]<tab/>"
end
|
#clausedelim ⇒ Object
141
142
143
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 141
def clausedelim
""
end
|
#collapse_term(docxml) ⇒ Object
130
131
132
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 130
def collapse_term(docxml)
docxml.xpath(ns("//term")).each { |t| collapse_term1(t) }
end
|
#collapse_term1(term) ⇒ Object
134
135
136
137
138
139
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 134
def collapse_term1(term)
defn = term.at(ns("./fmt-definition")) or return
source = term.at(ns("./fmt-termsource")) or return
defn.elements.last << source.children
source.remove
end
|
#ddMMMyyyy(isodate) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 96
def ddMMMyyyy(isodate)
isodate.nil? and return nil
arr = isodate.split("-")
if arr.size == 1 && (/^\d+$/.match isodate)
Date.new(*arr.map(&:to_i)).strftime("%Y")
elsif arr.size == 2
Date.new(*arr.map(&:to_i)).strftime("%B %Y")
else
Date.parse(isodate).strftime("%d %B %Y")
end
end
|
#dochistory(docxml) ⇒ Object
29
30
31
32
33
34
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 29
def dochistory(docxml)
updates = docxml.xpath(ns(UPDATE_RELATIONS))
updates.empty? and return
pref = preface_insert_point(docxml)
generate_dochistory(updates, pref)
end
|
#dochistory_contributor(contrib) ⇒ Object
75
76
77
78
79
80
81
82
83
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 75
def dochistory_contributor(contrib)
ret = contrib.at(ns("./organization/abbreviation")) ||
contrib.at(ns("./organization/subdivision")) ||
contrib.at(ns("./organization/name")) ||
contrib.at(ns("./person/name/abbreviation")) ||
contrib.at(ns("./person/name/completename"))
ret and return ret.text
format_personalname(contrib)
end
|
#dochistory_contributors(item) ⇒ Object
69
70
71
72
73
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 69
def dochistory_contributors(item)
item.xpath(ns("./contributor")).map do |c|
dochistory_contributor(c)
end.join(", ")
end
|
#dochistory_date(item) ⇒ Object
62
63
64
65
66
67
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 62
def dochistory_date(item)
d = item.at(ns("./date[@type = 'updated']")) ||
item.at(ns("./date[@type = 'published']")) ||
item.at(ns("./date[@type = 'issued']")) or return ""
ddMMMyyyy(d.text.strip)
end
|
#dochistory_description(item) ⇒ Object
91
92
93
94
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 91
def dochistory_description(item)
d = item.at(ns("./amend/description")) or return ""
d.children.to_xml
end
|
85
86
87
88
89
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 85
def format_personalname(contrib)
Relaton::Render::General.new(template: { book: "{{ creatornames }}" })
.render("<bibitem type='book'>#{contrib.to_xml}</bibitem>",
embedded: true)
end
|
#generate_dochistory(updates, pref) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 41
def generate_dochistory(updates, pref)
ret = updates.map { |u| generate_dochistory_row(u) }.flatten.join("\n")
pref << <<~XML
<clause id='_#{UUIDTools::UUID.random_create}'>
<title>#{@i18n.dochistory}</title>
<table unnumbered="true"><thead>
<tr><th>Version Number</th><th>Date</th><th>Author</th><th>Description</th></tr>
</thead><tbody>
#{ret}
</tbody></table></clause>
XML
end
|
#generate_dochistory_row(item) ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 54
def generate_dochistory_row(item)
e = item.at(ns("./edition"))&.text
date = dochistory_date(item)
c = dochistory_contributors(item)
desc = dochistory_description(item)
"<tr><td>#{e}</td><td>#{date}</td><td>#{c}</td><td>#{desc}</td></tr>"
end
|
#middle_title(docxml) ⇒ Object
18
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 18
def middle_title(docxml); end
|
#norm_ref_entry_code(ordinal, _idents, _ids, _standard, _datefn, _bib) ⇒ Object
9
10
11
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 9
def norm_ref_entry_code(ordinal, _idents, _ids, _standard, _datefn, _bib)
"[#{ordinal}]<tab/>"
end
|
#omit_docid_prefix(prefix) ⇒ Object
108
109
110
111
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 108
def omit_docid_prefix(prefix)
prefix == "IHO" and return true
super
end
|
#preface_insert_point(docxml) ⇒ Object
36
37
38
39
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 36
def preface_insert_point(docxml)
docxml.at(ns("//preface")) || docxml.at(ns("//sections"))
.add_previous_sibling("<preface> </preface>").first
end
|
#term1(elem) ⇒ Object
113
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 113
def term1(elem); end
|
#termcleanup(docxml) ⇒ Object
125
126
127
128
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 125
def termcleanup(docxml)
collapse_term docxml
super
end
|
#termsource1(elem) ⇒ Object
115
116
117
118
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 115
def termsource1(elem)
elem.parent.nil? and return
super
end
|
#termsource_label(elem, sources) ⇒ Object
120
121
122
123
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 120
def termsource_label(elem, sources)
elem.at("./ancestor::xmlns:term") or return
elem.replace(l10n("[#{sources}]"))
end
|
#ul_label_list(_elem) ⇒ Object
145
146
147
|
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 145
def ul_label_list(_elem)
%w(• — o)
end
|