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.



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

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.



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

def _file
  @_file
end

Class Method Details

.inherited(klass) ⇒ Object

rubocop:disable Lint/MissingSuper



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

def self.inherited(klass) # rubocop:disable Lint/MissingSuper
  klass._file = caller_locations(1..1).first.absolute_path
end

Instance Method Details

#author(isoxml, _out) ⇒ Object



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

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

#doctype(isoxml, _out) ⇒ Object



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

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



98
99
100
101
# File 'lib/isodoc/generic/metadata.rb', line 98

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



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

def stage_abbr(status)
  return super unless configuration.stage_abbreviations

  Hash(configuration.stage_abbreviations).dig(status)
end

#unpublished(status) ⇒ Object



63
64
65
66
# File 'lib/isodoc/generic/metadata.rb', line 63

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

#xmlhash2hash(hash) ⇒ Object



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

def xmlhash2hash(hash)
  ret = {}
  return ret if hash.nil? || hash[:kind] != "element"

  hash[:attr].nil? or
    hash[:attr].each { |k, v| ret["#{hash[:name]}_#{k}"] = v }
  ret[hash[:name]] = hash[:kids] ? xmlhash2hash_kids(hash) : hash[:text]
  ret
end

#xmlhash2hash_kids(hash) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/isodoc/generic/metadata.rb', line 85

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