Class: IsoDoc::Generic::Metadata

Inherits:
Metadata
  • Object
show all
Includes:
Utils
Defined in:
lib/isodoc/generic/metadata.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

#baselocation, #configuration, #fileloc

Constructor Details

#initialize(lang, script, labels) ⇒ Metadata

Returns a new instance of Metadata.



32
33
34
35
36
37
38
39
40
# File 'lib/isodoc/generic/metadata.rb', line 32

def initialize(lang, script, labels)
  super
  here = File.dirname(__FILE__)
  default_logo_path = File.expand_path(File.join(here, "html", "logo.jpg"))
  set(:logo, baselocation(configuration.logo_path) || default_logo_path)
  unless configuration.logo_paths.nil?
    set(:logo_paths, Array(configuration.logo_paths).map { |p| baselocation(p) })
  end
end

Class Attribute Details

._fileObject

Returns the value of attribute _file.



43
44
45
# File 'lib/isodoc/generic/metadata.rb', line 43

def _file
  @_file
end

Class Method Details

.inherited(k) ⇒ Object



46
47
48
# File 'lib/isodoc/generic/metadata.rb', line 46

def self.inherited( k )
  k._file = caller_locations.first.absolute_path
end

Instance Method Details

#author(isoxml, _out) ⇒ Object



50
51
52
53
54
# File 'lib/isodoc/generic/metadata.rb', line 50

def author(isoxml, _out)
  super
  tc = isoxml.at(ns("//bibdata/ext/editorialgroup/committee"))
  set(:tc, tc.text) if tc
end

#doctype(isoxml, _out) ⇒ Object



66
67
68
69
70
71
# File 'lib/isodoc/generic/metadata.rb', line 66

def doctype(isoxml, _out)
  super
  b = isoxml&.at(ns("//bibdata/ext/doctype#{currlang}")) || 
    isoxml&.at(ns("//bibdata/ext/doctype#{NOLANG}")) || return
  a = b["abbreviation"] and set(:doctype_abbr, a)
end

#ext(isoxml, out) ⇒ Object



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

def ext(isoxml, out)
  b = isoxml&.at(ns("//bibdata/ext")) or return
  set(:metadata_extensions, xmlhash2hash(b.to_hash)["ext"])
end

#stage_abbr(status) ⇒ Object



56
57
58
59
# File 'lib/isodoc/generic/metadata.rb', line 56

def stage_abbr(status)
  return super unless configuration.stage_abbreviations
  Hash(configuration.stage_abbreviations).dig(status)
end

#unpublished(status) ⇒ Object



61
62
63
64
# File 'lib/isodoc/generic/metadata.rb', line 61

def unpublished(status)
  stages = configuration&.published_stages || ["published"]
  !(Array(stages).map { |m| m.downcase }.include? status.downcase)
end

#xmlhash2hash(h) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/isodoc/generic/metadata.rb', line 73

def xmlhash2hash(h)
  ret = {}
  return ret if h.nil? || h[:kind] != "element"
  h[:attr].nil? or h[:attr].each { |k, v| ret["#{h[:name]}_#{k}"] = v }
  ret[h[:name]] = h[:kids] ? xmlhash2hash_kids(h) : h[:text]
  ret
end

#xmlhash2hash_kids(h) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/isodoc/generic/metadata.rb', line 81

def xmlhash2hash_kids(h)
  c = {}
  h[:kids].each do |n|
    xmlhash2hash(n).each do |k1, v1|
      c[k1] = c[k1].nil? ? v1 :
        c[k1].is_a?(Array) ? c[k1] << v1 :
        [c[k1], v1]
    end
  end
  c
end