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, locale, labels) ⇒ Metadata

Returns a new instance of Metadata.



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/isodoc/generic/metadata.rb', line 34

def initialize(lang, script, locale, 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.



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

def _file
  @_file
end

Class Method Details

.inherited(klass) ⇒ Object

rubocop:disable Lint/MissingSuper



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

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



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

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

#doctype(isoxml, _out) ⇒ Object



71
72
73
74
75
76
# File 'lib/isodoc/generic/metadata.rb', line 71

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



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

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



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

def stage_abbr(status)
  return super unless configuration.stage_abbreviations

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

#unpublished(status) ⇒ Object



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

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

#xmlhash2hash(hash) ⇒ Object



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

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



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/isodoc/generic/metadata.rb', line 88

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