Module: Sist02::CiNii

Defined in:
lib/sist02/cinii.rb

Class Method Summary collapse

Class Method Details

.article_ref(naid) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sist02/cinii.rb', line 8

def article_ref(naid)
  begin
    html = open("http://ci.nii.ac.jp/naid/#{naid}.json").read
    json = JSON.parser.new(html)
    hash = json.parse["@graph"][0]
    title =  hash["dc:title"][0]["@value"]
    creator_raw = hash["dc:creator"]
    creator = ''
    creator_raw.each do |item|
      creator += "#{item[0]["@value"]}, "
    end
    creator = creator.gsub(/\,\s$/, '')
    publication_name = hash["prism:publicationName"][0]["@value"]
    year = hash["dc:date"].match(/\d{4}/)
    volume = hash["prism:volume"]
    number = hash["prism:number"]
    start_p = hash["prism:startingPage"]
    end_p = hash["prism:endingPage"]
    result = "#{creator}. #{title}. #{publication_name}. #{year}, vol. #{volume}, no. #{number}, p. #{start_p}-#{end_p}."
  rescue => e
    result = e
  end
  return result
end

.book_ref(ncid) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/sist02/cinii.rb', line 33

def book_ref(ncid)
  begin
    html = open("http://ci.nii.ac.jp/ncid/#{ncid}.json").read
    json = JSON.parser.new(html)
    hash = json.parse["@graph"][0]
    title = hash["dc:title"][0]["@value"]
    publisher = hash["dc:publisher"][0]
    year = hash["dc:date"].match(/\d{4}/)
    edition = hash["prism:edition"]
    author_ary = Array.new
    hash["foaf:maker"].each do |item|
      author_ary << item["foaf:name"][0]["@value"].gsub(/(\s| |,)+/, '')
    end
    author = author_ary.join(", ")

    ris = open("http://ci.nii.ac.jp/ncid/#{ncid}.ris").read
    pages = ris.match(/EP  - ([a-z]*, )?\d+p/).to_s.gsub(/EP  - /, '')
    pages = "ページ数不明" if pages == ''
    result = "#{author}. #{title}. #{edition}, #{publisher}, #{year}, #{pages}." unless edition == nil
    result = "#{author}. #{title}. #{publisher}, #{year}, #{pages}." if edition == nil # for bibliographic information that doesn't have edition display
  rescue => e
      result = e
  end
  return result
end