Class: IsoDoc::IHO::PresentationXMLConvert

Inherits:
Generic::PresentationXMLConvert
  • Object
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

Methods included from Init

#i18n_init, #info, #metadata_init, #omit_docid_prefix, #xref_init

Instance Method Details

#bibdata(docxml) ⇒ Object



37
38
39
40
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 37

def bibdata(docxml)
  super
  dochistory(docxml)
end

#biblio_ref_entry_code(ordinal, _idents, _ids, _standard, _datefn, _bib) ⇒ Object



17
18
19
20
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 17

def biblio_ref_entry_code(ordinal, _idents, _ids, _standard, _datefn,
_bib)
  "[#{ordinal}]<tab/>"
end

#bibrendererObject



9
10
11
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 9

def bibrenderer
  ::Relaton::Render::IHO::General.new(language: @lang)
end

#ddMMMyyyy(isodate) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 112

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



46
47
48
49
50
51
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 46

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



92
93
94
95
96
97
98
99
100
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 92

def dochistory_contributor(contrib)
  ret = contrib.at("./organization/abbreviation") ||
    contrib.at("./organization/subdivision") ||
    contrib.at("./organization/name") ||
    contrib.at("./person/name/abbreviation") ||
    contrib.at("./person/name/completename")
  ret and return ret.text
  format_personalname(contrib)
end

#dochistory_contributors(item) ⇒ Object



86
87
88
89
90
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 86

def dochistory_contributors(item)
  item.xpath(ns("./contributor")).map do |c|
    dochistory_contributor(c)
  end.join(", ")
end

#dochistory_date(item) ⇒ Object



79
80
81
82
83
84
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 79

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



107
108
109
110
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 107

def dochistory_description(item)
  d = item.at(ns("./amend/description")) or return ""
  d.children.to_xml
end

#format_personalname(contrib) ⇒ Object



102
103
104
105
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 102

def format_personalname(contrib)
  Relaton::Render::General.new(template: { book: "{{ creatornames }}" })
    .render("<bibitem type='book'>#{contrib.to_xml}</bibitem>")
end

#generate_dochistory(updates, pref) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 58

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



71
72
73
74
75
76
77
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 71

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



22
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 22

def middle_title(docxml); end

#norm_ref_entry_code(ordinal, _idents, _ids, _standard, _datefn, _bib) ⇒ Object



13
14
15
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 13

def norm_ref_entry_code(ordinal, _idents, _ids, _standard, _datefn, _bib)
  "[#{ordinal}]<tab/>"
end

#preface_insert_point(docxml) ⇒ Object



53
54
55
56
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 53

def preface_insert_point(docxml)
  docxml.at(ns("//preface")) || docxml.at(ns("//sections"))
    .add_previous_sibling("<preface> </preface>").first
end

#preface_rearrange(doc) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/isodoc/iho/presentation_xml_convert.rb', line 24

def preface_rearrange(doc)
  preface_move(doc.at(ns("//preface/abstract")),
               %w(foreword executivesummary introduction clause acknowledgements), doc)
  preface_move(doc.at(ns("//preface/foreword")),
               %w(executivesummary introduction clause acknowledgements), doc)
  preface_move(doc.at(ns("//preface/executivesummary")),
               %w(introduction clause acknowledgements), doc)
  preface_move(doc.at(ns("//preface/introduction")),
               %w(clause acknowledgements), doc)
  preface_move(doc.at(ns("//preface/acknowledgements")),
               %w(), doc)
end