Class: IsoDoc::Ogc::Metadata

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

Instance Method Summary collapse

Instance Method Details

#author(isoxml, _out) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/isodoc/ogc/metadata.rb', line 106

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


123
124
125
126
127
128
129
130
# File 'lib/isodoc/ogc/metadata.rb', line 123

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



185
186
187
188
189
190
191
192
# File 'lib/isodoc/ogc/metadata.rb', line 185

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



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

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



177
178
179
# File 'lib/isodoc/ogc/metadata.rb', line 177

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

#doctype(isoxml, _out) ⇒ Object



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

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



173
174
175
# File 'lib/isodoc/ogc/metadata.rb', line 173

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

#image_html(xml, contrib) ⇒ Object



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

def image_html(xml, contrib)
   = xml.at(ns("#{contrib}[@type = 'html-blue']/image"))
  img = &.at("./*[local-name() = 'svg']") || 
  if img
    set(:logo_html_blue, img_mn2html(img))
  else
    src = File.expand_path(File.join(File.dirname(__FILE__), "html",
                                     - "logo.2018.png"))
    set(:logo_html_blue,
        "<img src='#{src}' alt='Open Geospatial Consortium'/>")
  end
end

#image_html_reverse(xml, contrib) ⇒ Object



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

def image_html_reverse(xml, contrib)
   = xml.at(ns("#{contrib}[@type = 'html-white']/image"))
  img = &.at("./*[local-name() = 'svg']") || 
  if img
    set(:logo_html_white, img_mn2html(img))
  else
    src = File.expand_path(File.join(File.dirname(__FILE__), "html",
                                     - "logo.2018-white.png"))
    set(:logo_html_white,
        "<img src='#{src}' alt='Open Geospatial Consortium'/>")
  end
end

#image_word(xml, contrib) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/isodoc/ogc/metadata.rb', line 52

def image_word(xml, contrib)
  if  = xml.at(ns("#{contrib}[@type = 'word']"))
    set(:logo_word, .elements.first["src"])
  else
    src = File.expand_path(File.join(File.dirname(__FILE__), "html",
                                     "logo.png"))
    set(:logo_word, src)
  end
end

#images(xml, _out) ⇒ Object



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

def images(xml, _out)
  c = "//contributor[role/@type = 'publisher']/" \
      "organization[abbreviation = 'OGC']/logo"
  image_html(xml, c)
  image_html_reverse(xml, c)
  docscheme = xml.at(ns("//presentation-metadata/document-scheme"))&.text
  case docscheme
  when "2026", nil then set(:logo_html, get[:logo_html_white])
  else set(:logo_html, get[:logo_html_blue])
  end
  image_word(xml, c)
end

#img_mn2html(img) ⇒ Object



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

def img_mn2html(img)
  img.to_xml.sub("<image", "<img").sub("</image>", "</img>")
end

#presentation(xml, _out) ⇒ Object



194
195
196
197
198
199
200
201
202
203
# File 'lib/isodoc/ogc/metadata.rb', line 194

def presentation(xml, _out)
  super
  @metadata.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)
    @metadata[k] =
      sprintf("#%02x%02x%02x", m[1].to_i, m[2].to_i, m[3].to_i)
  end
end

#status_print(status) ⇒ Object



181
182
183
# File 'lib/isodoc/ogc/metadata.rb', line 181

def status_print(status)
  type_capitalise(status)
end

#subtitle(_isoxml, _out) ⇒ Object



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

def subtitle(_isoxml, _out)
  nil
end

#title(isoxml, _out) ⇒ Object



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

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

#type_capitalise(type) ⇒ Object



156
157
158
159
160
# File 'lib/isodoc/ogc/metadata.rb', line 156

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

#unpublished(status) ⇒ Object



139
140
141
# File 'lib/isodoc/ogc/metadata.rb', line 139

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

#url(xml, _out) ⇒ Object



150
151
152
153
154
# File 'lib/isodoc/ogc/metadata.rb', line 150

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

#version(isoxml, _out) ⇒ Object



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

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