Class: IsoDoc::Ogc::Metadata

Inherits:
Metadata
  • Object
show all
Defined in:
lib/isodoc/ogc/metadata.rb

Instance Method Summary collapse

Constructor Details

#initialize(lang, script, locale, i18n) ⇒ Metadata

Returns a new instance of Metadata.



39
40
41
42
43
44
45
46
47
# File 'lib/isodoc/ogc/metadata.rb', line 39

def initialize(lang, script, locale, i18n)
  super
  here = File.dirname(__FILE__)
  set(:logo_old,
      File.expand_path(File.join(here, "html", "logo.png")))
  set(:logo_new,
      File.expand_path(File.join(here, "html",
                                 "logo.2021.svg")))
end

Instance Method Details

#author(isoxml, _out) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/isodoc/ogc/metadata.rb', line 62

def author(isoxml, _out)
  tc = isoxml.at(ns("//bibdata/ext/editorialgroup/committee"))
  set(:tc, tc.text) if tc
  authors = isoxml.xpath(ns("//bibdata/contributor" \
                            "[role/@type = 'author']/person"))
  set(:authors, extract_person_names(authors))
  editors = isoxml.xpath(ns("//bibdata/contributor" \
                            "[role/@type = 'editor']/person"))
  set(:editors, extract_person_names(editors))
  contributors = isoxml.xpath(ns("//bibdata/contributor" \
                                 "[role/@type = 'contributor']/person"))
  set(:contributors, extract_person_names(contributors))
  agency(isoxml)
  copyright(isoxml)
end

#bibdate(isoxml, _out) ⇒ Object



149
150
151
152
153
154
155
156
157
158
159
# File 'lib/isodoc/ogc/metadata.rb', line 149

def bibdate(isoxml, _out)
  super
  d = docdate(isoxml)
  begin
    old = d.nil? || d.empty? ||
      DateTime.iso8601("2021-11-08") > DateTime.parse(d.text)
  rescue StandardError
    old = false
  end
  set(:logo_word, old ? get[:logo_old] : get[:logo_new])
end


78
79
80
81
82
83
84
85
# File 'lib/isodoc/ogc/metadata.rb', line 78

def copyright(isoxml)
  c = isoxml.xpath(ns("//bibdata/copyright/owner/organization/name"))
    .each_with_object([]) do |n, m|
    m << n.text
  end
  c.empty? and c = ["Open Geospatial Consortium"]
  set(:copyright_holder, @i18n.boolean_conj(c, "and"))
end

#docdate(isoxml) ⇒ Object



140
141
142
143
144
145
146
147
# File 'lib/isodoc/ogc/metadata.rb', line 140

def docdate(isoxml)
  isoxml.xpath(ns("//bibdata/date[@type = 'published']/on")) ||
    isoxml.xpath(ns("//bibdata/date[@type = 'published']/from")) ||
    isoxml.xpath(ns("//bibdata/date[@type = 'issued']/on")) ||
    isoxml.xpath(ns("//bibdata/date[@type = 'issued']/from")) ||
    isoxml.xpath(ns("//bibdata/date/from")) ||
    isoxml.xpath(ns("//bibdata/date/on"))
end

#docid(isoxml, _out) ⇒ Object



87
88
89
90
91
92
# File 'lib/isodoc/ogc/metadata.rb', line 87

def docid(isoxml, _out)
  set(:docnumber, isoxml&.at(ns("//bibdata/docidentifier" \
                                "[@type = 'ogc-internal']"))&.text)
  set(:externalid, isoxml&.at(ns("//bibdata/docidentifier" \
                                 "[@type = 'ogc-external']"))&.text)
end

#docsubtype_abbr(subtype, _type) ⇒ Object



132
133
134
# File 'lib/isodoc/ogc/metadata.rb', line 132

def docsubtype_abbr(subtype, _type)
  IsoDoc::Ogc::DOCSUBTYPE_ABBR[subtype] || subtype
end

#doctype(isoxml, _out) ⇒ Object



117
118
119
120
121
122
123
124
125
126
# File 'lib/isodoc/ogc/metadata.rb', line 117

def doctype(isoxml, _out)
  if t = isoxml&.at(ns("//bibdata/ext/doctype"))&.text
    set(:doctype, type_capitalise(t))
    set(:doctype_abbr, doctype_abbr(t))
    if st = isoxml&.at(ns("//bibdata/ext/subdoctype"))&.text
      set(:docsubtype, type_capitalise(st))
      set(:docsubtype_abbr, docsubtype_abbr(st, t))
    end
  end
end

#doctype_abbr(type) ⇒ Object



128
129
130
# File 'lib/isodoc/ogc/metadata.rb', line 128

def doctype_abbr(type)
  IsoDoc::Ogc::DOCTYPE_ABBR[type] || type
end

#status_print(status) ⇒ Object



136
137
138
# File 'lib/isodoc/ogc/metadata.rb', line 136

def status_print(status)
  type_capitalise(status)
end

#subtitle(_isoxml, _out) ⇒ Object



58
59
60
# File 'lib/isodoc/ogc/metadata.rb', line 58

def subtitle(_isoxml, _out)
  nil
end

#title(isoxml, _out) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/isodoc/ogc/metadata.rb', line 49

def title(isoxml, _out)
  main = isoxml.at(ns("//bibdata/title[@language='en']"))
    &.children&.to_xml
  set(:doctitle, main)
  main = isoxml.at(ns("//bibdata/abstract"))
    &.text&.strip&.gsub(/\s+/, " ")
  set(:abstract, main)
end

#type_capitalise(type) ⇒ Object



111
112
113
114
115
# File 'lib/isodoc/ogc/metadata.rb', line 111

def type_capitalise(type)
  type.split(/[- ]/).map do |w|
    %w(SWG).include?(w) ? w : w.capitalize
  end.join(" ")
end

#unpublished(status) ⇒ Object



94
95
96
# File 'lib/isodoc/ogc/metadata.rb', line 94

def unpublished(status)
  !%w(approved deprecated retired).include?(status.downcase)
end

#url(xml, _out) ⇒ Object



105
106
107
108
109
# File 'lib/isodoc/ogc/metadata.rb', line 105

def url(xml, _out)
  super
  a = xml.at(ns("//bibdata/uri[@type = 'previous']")) and
    set(:previousuri, a.text)
end

#version(isoxml, _out) ⇒ Object



98
99
100
101
102
103
# File 'lib/isodoc/ogc/metadata.rb', line 98

def version(isoxml, _out)
  super
  set(:edition, isoxml&.at(ns("//bibdata/edition"))&.text)
  lg = ISO_639.find_by_code(isoxml&.at(ns("//bibdata/language"))&.text)
  set(:doclanguage, lg ? lg[3] : "English")
end