Class: IsoDoc::JIS::Metadata

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

Constant Summary collapse

PART_LABEL =
{ en: "Part", ja: "その" }.freeze

Instance Method Summary collapse

Instance Method Details

#agency(xml) ⇒ Object



70
71
72
73
74
# File 'lib/isodoc/jis/metadata.rb', line 70

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

#bibdate(isoxml, _out) ⇒ Object



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

def bibdate(isoxml, _out)
  isoxml.xpath(ns("//bibdata/date")).each do |d|
    val = Common::date_range(d)
    @lang == "ja" and val = @i18n.japanese_date(val)
    set("#{d['type'].gsub(/-/, '_')}date".to_sym, val)
  end
end

#docid(isoxml, _out) ⇒ Object



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

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



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

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



91
92
93
94
95
96
97
98
# File 'lib/isodoc/jis/metadata.rb', line 91

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



100
101
102
103
104
105
106
107
108
109
# File 'lib/isodoc/jis/metadata.rb', line 100

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



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

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



38
39
40
41
42
# File 'lib/isodoc/jis/metadata.rb', line 38

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



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

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)
  main = compose_title(tp, tn, lang)
  set(:docsubtitle, main)
  tp[:intro] and set(:docsubtitleintro, tp[:intro].children.to_xml)
  set(:docsubtitlepartlabel, part_prefix(tn, lang))
  tp[:part] and set(:docsubtitlepart, tp[:part].children.to_xml)
  set(:docsubtitleamdlabel, amd_prefix(tn, lang)) if tn[:amd]
  tp[:amd] and set(:docsubtitleamd, tp[:amd].children.to_xml)
  set(:docsubtitlecorrlabel, corr_prefix(tn, lang)) if tn[:corr]
end

#title(isoxml, _out) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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)
  main = compose_title(tp, tn, lang)
  set(:doctitle, main)
  tp[:intro] and set(:doctitleintro, tp[:intro].children.to_xml)
  set(:doctitlepartlabel, part_prefix(tn, lang))
  tp[:part] and set(:doctitlepart, tp[:part].children.to_xml)
  set(:doctitleamdlabel, amd_prefix(tn, lang)) if tn[:amd]
  tp[:amd] and set(:doctitleamd, tp[:amd].children.to_xml)
  set(:doctitlecorrlabel, corr_prefix(tn, lang)) if tn[:corr]
end

#version(isoxml, out) ⇒ Object



61
62
63
64
65
66
67
68
# File 'lib/isodoc/jis/metadata.rb', line 61

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