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



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

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

#bibdate(isoxml, _out) ⇒ Object



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

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".to_sym, val)
  end
end

#docid(isoxml, _out) ⇒ Object



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

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



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

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



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

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



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

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



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

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)
  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
# 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



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

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