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



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
77
# File 'lib/isodoc/ogc/metadata.rb', line 62

def author(isoxml, _out)
  tc = isoxml.at(ns("//bibdata/contributor[role/@type='author']/" \
    "organization/subdivision[@type='Committee']/name"))
  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



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

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


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

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, connectives_strip(@i18n.boolean_conj(c, "and")))
end

#docdate(isoxml) ⇒ Object



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

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



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

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



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

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

#doctype(isoxml, _out) ⇒ Object



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

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



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

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

#presentation(xml, _out) ⇒ Object



162
163
164
165
166
167
168
169
170
171
# File 'lib/isodoc/ogc/metadata.rb', line 162

def presentation(xml, _out)
  super
  .each do |k, v|
    /^presentation_metadata_color_/.match?(k) or next
    v.is_a?(Array) or next
    m = /^rgb\((\d+),\s*(\d+),\s*(\d+)\s*\)/.match(Array(v).first)
    [k] =
      sprintf("#%02x%02x%02x", m[1].to_i, m[2].to_i, m[3].to_i)
  end
end

#status_print(status) ⇒ Object



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

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



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

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

#unpublished(status) ⇒ Object



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

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

#url(xml, _out) ⇒ Object



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

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

#version(isoxml, _out) ⇒ Object



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

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