Class: IsoDoc::Jis::Metadata

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

Instance Method Summary collapse

Instance Method Details

#agency(xml) ⇒ Object



76
77
78
79
80
# File 'lib/isodoc/jis/metadata.rb', line 76

def agency(xml)
  super
  investigative_organisation(xml)
  investigative_committee(xml)
end

#bibdate(isoxml, _out) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/isodoc/jis/metadata.rb', line 55

def bibdate(isoxml, _out)
  isoxml.xpath(ns("//bibdata/date")).each do |d|
    val = Common::date_range(d)
    @lang == "ja" && /^\d+[0-9-]+$/.match?(val) and
      val = @i18n.japanese_date(val)
    set(:"#{d['type'].tr('-', '_')}date", val)
  end
end

#docid(isoxml, _out) ⇒ Object



48
49
50
51
52
53
# File 'lib/isodoc/jis/metadata.rb', line 48

def docid(isoxml, _out)
  id = isoxml.at(ns("//bibdata/docidentifier[@type = 'JIS']"))&.text or
    return
  set(:docnumber, id)
  set(:docnumber_undated, id.sub(/:\d{4}$/, ""))
end

#extract_role(role, desc) ⇒ Object



82
83
84
85
86
# File 'lib/isodoc/jis/metadata.rb', line 82

def extract_role(role, desc)
  <<~XPATH
    //bibdata/contributor[xmlns:role/@type = '#{role}'][xmlns:role/description = '#{desc}' or xmlns:role/description = '#{desc.downcase}']
  XPATH
end

#investigative_committee(xml) ⇒ Object



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

def investigative_committee(xml)
  xpath = extract_role("authorizer", "Investigative committee")
  if o = xml.at(ns("#{xpath}/organization/name"))
    set_encoded(:"investigative-committee", o)
  elsif p = xml.at(ns("#{xpath}/person"))
    investigative_committee_person(p)
  end
end

#investigative_committee_person(person) ⇒ Object



106
107
108
109
110
111
112
113
114
115
# File 'lib/isodoc/jis/metadata.rb', line 106

def investigative_committee_person(person)
  n = extract_person_names([person])
  pos = person.at(ns("./affiliation/name")) || @i18n.chairperson
  org = person.at(ns("./affiliation/organization/name"))
  set_encoded(:"investigative-committee", org)
  unless n.empty?
    set_encoded(:"investigative-committee-representative-role", pos)
    set(:"investigative-committee-representative-name", n.first)
  end
end

#investigative_organisation(xml) ⇒ Object



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

def investigative_organisation(xml)
  p = extract_role("authorizer", "Investigative organization")
  org = xml.at(ns("#{p}/organization/name[@language = '#{@lang}']"))
  org ||= xml.at(ns("#{p}/organization/name"))
  if org then set_encoded(:"investigative-organization", org)
  else set(:"investigative-organization", get[:publisher])
  end
end

#set_encoded(name, field) ⇒ Object



42
43
44
45
46
# File 'lib/isodoc/jis/metadata.rb', line 42

def set_encoded(name, field)
  field or return
  field.respond_to?(:text) and field = field.text
  set(name, @c.encode(field, :hexadecimal))
end

#subtitle(isoxml, _out) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/isodoc/jis/metadata.rb', line 25

def subtitle(isoxml, _out)
  lang = @lang == "ja" ? "en" : "ja"
  tp = title_parts(isoxml, lang)
  tn = title_nums(isoxml)
  tp[:main] and set(:docsubtitlemain, tp[:main].children.to_xml)
  tp[:intro] and set(:docsubtitleintro, tp[:intro].children.to_xml)
  set(:docsubtitlepartlabel, title_part_prefix(isoxml, "part", lang))
  tp[:part] and set(:docsubtitlepart, tp[:part].children.to_xml)
  tn[:amd] and set(:docsubtitleamdlabel,
                   title_part_prefix(isoxml, "amendment", lang))
  tp[:amd] and set(:docsubtitleamd, tp[:amd].children.to_xml)
  tn[:corr] and set(:docsubtitlecorrlabel,
                    title_part_prefix(isoxml, "corrigendum", lang))
  main = compose_title(tp, tn, lang)
  set(:docsubtitle, main)
end

#title(isoxml, _out) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/isodoc/jis/metadata.rb', line 7

def title(isoxml, _out)
  lang = @lang
  %w(en ja).include?(lang) or lang = "ja"
  tp = title_parts(isoxml, lang)
  tn = title_nums(isoxml)
  tp[:main] and set(:doctitlemain, tp[:main].children.to_xml)
  tp[:intro] and set(:doctitleintro, tp[:intro].children.to_xml)
  set(:doctitlepartlabel, title_part_prefix(isoxml, "part", lang))
  tp[:part] and set(:doctitlepart, tp[:part].children.to_xml)
  tn[:amd] and set(:doctitleamdlabel,
                   title_part_prefix(isoxml, "amendment", lang))
  tp[:amd] and set(:doctitleamd, tp[:amd].children.to_xml)
  tn[:corr] and set(:doctitlecorrlabel,
                    title_part_prefix(isoxml, "corrigendum", lang))
  main = compose_title(tp, tn, lang)
  set(:doctitle, main)
end

#version(isoxml, out) ⇒ Object



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

def version(isoxml, out)
  super
  @lang == "ja" or return
  revdate = if revdate = isoxml.at(ns("//bibdata/date[@type = 'updated']/on"))
              @i18n.japanese_date(revdate.text)
            else
              isoxml.at(ns("//bibdata/date[@type = 'updated']"))&.text
            end
  set(:revdate, revdate)
  set(:draftinfo, draftinfo(get[:draft], revdate))
end