sist02 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d64c931b843408724f21c5a8928d4ca5b551a9d
4
- data.tar.gz: dad112aaad585dc30a2d26d48399b98fd8b70bd0
3
+ metadata.gz: ac92de232990d6691dde4e19ab925239359835bd
4
+ data.tar.gz: 8760f071ea9644fe57dbc0c0ef2940f7e508e6c1
5
5
  SHA512:
6
- metadata.gz: 6ea6887bce7b60cc062bff943707559e798815d6d98bea021ea87150741bb0350d44178559560f514168e7599c98ccd706637641f78ddc562ebb2fb92e85f04a
7
- data.tar.gz: 98fcd00179efae037e27bd0a1da54824c700e8b90988666c360cf82ba684a20066125d694bf5c4b7c68a9fd3318513c8279ee7ec44264c3786ba7fd19b744e24
6
+ metadata.gz: 54e874f84116f29dd2b4c9d902945ffe1580a31ca27f5eb5509db5312d18ac06d698d0704150c1f8bded3cd4e5f6f3d2162a8fef167ee3fe253e014b7492c9a6
7
+ data.tar.gz: 71f968862b162704338ab319c712bfe0e2c345a60dc44df7bcc9769848ff4a3d3e7747158e6aa2a2577457cabba1ac4ac4743fbd1177550a32d4f0481f592df2
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in sist02.gemspec
4
+ gem 'rspec'
4
5
  gemspec
data/README.md CHANGED
@@ -47,7 +47,7 @@ p Sist02::CiNii.book_ref(ncid)
47
47
 
48
48
  # 博士論文
49
49
  naid = "500000587337"
50
- p Sist02::CiNii.thesis_ref(naid)
50
+ p Sist02::CiNii.dissertations_ref(naid)
51
51
  => "今井, 福司. 日本占領期におけるアメリカ学校図書館の導入 : 日米の学校教育実践における学校図書館の位置づけ. 東京大学, 2013, 博士論文."
52
52
 
53
53
  ```
data/lib/sist02/cinii.rb CHANGED
@@ -4,73 +4,79 @@ require 'date'
4
4
 
5
5
  module Sist02
6
6
  module CiNii
7
+ # enable required program to call following functions
7
8
  module_function
8
- def article_ref(naid)
9
+
10
+ def article_ref naid
11
+
9
12
  begin
10
- html = open("http://ci.nii.ac.jp/naid/#{naid}.json").read
11
- json = JSON.parser.new(html)
12
- hash = json.parse["@graph"][0]
13
- title = hash["dc:title"][0]["@value"]
14
- creator_raw = hash["dc:creator"]
15
- creator = ''
16
- creator_raw.each do |item|
17
- creator += "#{item[0]["@value"]}, "
18
- end
19
- creator = creator.gsub(/\,\s$/, '')
20
- publication_name = hash["prism:publicationName"][0]["@value"]
21
- year = hash["dc:date"].match(/\d{4}/)
22
- volume = hash["prism:volume"]
23
- number = hash["prism:number"]
24
- start_p = hash["prism:startingPage"]
25
- end_p = hash["prism:endingPage"]
26
- result = "#{creator}. #{title}. #{publication_name}. #{year}, vol. #{volume}, no. #{number}, p. #{start_p}-#{end_p}."
13
+
14
+ url = "http://ci.nii.ac.jp/naid/#{naid}.json"
15
+ content = get_content url
16
+ common_info = get_common_info content
17
+ volume = content["prism:volume"]
18
+ number = content["prism:number"]
19
+ start_p = content["prism:startingPage"]
20
+ end_p = content["prism:endingPage"]
21
+ result = "#{common_info["maker"]}. #{common_info["title"]}. #{common_info["publicationName"]}. #{common_info["year"]}, vol. #{volume}, no. #{number}, p. #{start_p}-#{end_p}."
27
22
  rescue => e
28
23
  result = e
29
24
  end
30
25
  return result
31
26
  end
32
27
 
33
- def book_ref(ncid)
28
+ def book_ref ncid
34
29
  begin
35
- html = open("http://ci.nii.ac.jp/ncid/#{ncid}.json").read
36
- json = JSON.parser.new(html)
37
- hash = json.parse["@graph"][0]
38
- title = hash["dc:title"][0]["@value"]
39
- publisher = hash["dc:publisher"][0]
40
- year = hash["dc:date"].match(/\d{4}/)
41
- edition = hash["prism:edition"]
42
- author_ary = Array.new
43
- hash["foaf:maker"].each do |item|
44
- author_ary << item["foaf:name"][0]["@value"].gsub(/(\s| |,)+/, '')
45
- end
46
- author = author_ary.join(", ")
47
-
30
+ url = "http://ci.nii.ac.jp/ncid/#{ncid}.json"
31
+ content = get_content url
32
+ common_info = get_common_info content
33
+ edition = content["prism:edition"]
48
34
  ris = open("http://ci.nii.ac.jp/ncid/#{ncid}.ris").read
49
- pages = ris.match(/EP - ([a-z]*, )?\d+p/).to_s.gsub(/EP - /, '')
50
- pages = "ページ数不明" if pages == ''
51
- result = "#{author}. #{title}. #{edition}, #{publisher}, #{year}, #{pages}." unless edition == nil
52
- result = "#{author}. #{title}. #{publisher}, #{year}, #{pages}." if edition == nil # for bibliographic information that doesn't have edition display
35
+ edition = ris.match(/ET\s{2}-\s(.*)\r/) ? ris.match(/ET\s{2}-\s(.*)\r/)[1] : nil
36
+ publisher = ris.match(/PB\s{2}-\s(.*)\r/) ? ris.match(/PB\s{2}-\s(.*)\r/)[1] : nil
37
+ page = ris.match(/EP\s{2}-\s.*?(\d*?p)/) ? ris.match(/EP\s{2}-\s.*?(\d*?p)/)[1] : 'ページ数不明'
38
+ result = "#{common_info["maker"]}. #{common_info["title"]}. #{edition}, #{publisher}, #{common_info["year"]}, #{page}." if edition
39
+ result = "#{common_info["maker"]}. #{common_info["title"]}. #{publisher}, #{common_info["year"]}, #{page}." unless edition
53
40
  rescue => e
54
41
  result = e
55
42
  end
56
43
  return result
57
44
  end
58
45
 
59
- def thesis_ref(naid)
46
+ def dissertations_ref naid
47
+
60
48
  begin
61
- html = open("http://ci.nii.ac.jp/naid/#{naid}.json").read
62
- json = JSON.parser.new(html)
63
- hash = json.parse["@graph"][0]
64
- author = hash["dc:creator"][0][0]["@value"]
65
- title = hash["dc:title"][0]["@value"]
66
- publisher = hash["dc:publisher"][0]["@value"]
67
- year = hash["dc:date"].match(/\d{4}/)
68
- result = "#{author}. #{title}. #{publisher}, #{year}, 博士論文."
49
+
50
+ url = "http://ci.nii.ac.jp/naid/#{naid}.json"
51
+ content = get_content url
52
+ common_info = get_common_info content
53
+ result = "#{common_info["maker"]}. #{common_info["title"]}. #{common_info["publisher"]}, #{common_info["year"]}, 博士論文."
69
54
  rescue => e
70
55
  result = e
71
56
  end
72
57
  return result
73
58
  end
74
59
 
60
+ def get_content url
61
+ html = open(url).read
62
+ json = JSON.parser.new(html)
63
+ json.parse["@graph"][0]
64
+ end
65
+
66
+
67
+ def get_common_info content
68
+ common_info = {}
69
+ common_info["title"] = content["dc:title"][0]["@value"]
70
+ common_info["publisher"] = content["dc:publisher"][0]["@value"]
71
+ common_info["publicationName"] = content["prism:publicationName"][0]["@value"] if content["prism:publicationName"]
72
+ common_info["year"] = content["dc:date"].match(/\d{4}/)
73
+ author_ary = Array.new
74
+ content["foaf:maker"].each do |item|
75
+ author_ary << item["foaf:name"][0]["@value"].gsub(/(\s| |,)+/, '')
76
+ end
77
+ common_info["maker"] = author_ary.join(", ")
78
+ return common_info
79
+ end
80
+
75
81
  end
76
82
  end
@@ -1,3 +1,3 @@
1
1
  module Sist02
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sist02
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Makoto Hiramatsu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-06-10 00:00:00.000000000 Z
11
+ date: 2015-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler