citero 1.0.0.alpha3 → 1.0.0.alpha5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/citero.rb +5 -1
- data/lib/citero/inputs.rb +1 -0
- data/lib/citero/inputs/pnx_json.rb +153 -0
- data/lib/citero/outputs/openurl.rb +36 -7
- data/lib/citero/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ad3b53896c3eb9cd5781a598794877bf63cc7a1
|
4
|
+
data.tar.gz: 2c8952c07311e3a8665fd273acb049129a0d9f17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4eed240b48f8210f9d1cb177058d98d0104cc7396bf0bec0f30f71fe8e90a32e0eafd5df7e3986c1a357349da2bee56b8b6dacf92cea2e4fbf547750b44bf9c
|
7
|
+
data.tar.gz: 90819b5af6ae0dac5f001965da5a541b1d3491b05d2d9a88fa183186d97aa2a1c74230c766ae376c4439ce0ecdadbe4c7ea7417d1ec9edfa406964cb2507490d
|
data/lib/citero.rb
CHANGED
@@ -6,7 +6,7 @@ module Citero
|
|
6
6
|
require_relative 'citero/utils'
|
7
7
|
|
8
8
|
def self.from_formats
|
9
|
-
[:csf, :openurl, :pnx]
|
9
|
+
[:csf, :openurl, :pnx, :pnx_json]
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.to_formats
|
@@ -38,6 +38,8 @@ module Citero
|
|
38
38
|
from = Citero::Inputs::OpenUrl.new(@input)
|
39
39
|
when :pnx
|
40
40
|
from = Citero::Inputs::Pnx.new(@input)
|
41
|
+
when :pnx_json
|
42
|
+
from = Citero::Inputs::PnxJson.new(@input)
|
41
43
|
else
|
42
44
|
raise ArgumentError
|
43
45
|
end
|
@@ -57,6 +59,8 @@ module Citero
|
|
57
59
|
from = Citero::Inputs::OpenUrl.new(@input)
|
58
60
|
when :pnx
|
59
61
|
from = Citero::Inputs::Pnx.new(@input)
|
62
|
+
when :pnx_json
|
63
|
+
from = Citero::Inputs::PnxJson.new(@input)
|
60
64
|
else
|
61
65
|
raise ArgumentError
|
62
66
|
end
|
data/lib/citero/inputs.rb
CHANGED
@@ -0,0 +1,153 @@
|
|
1
|
+
module Citero
|
2
|
+
module Inputs
|
3
|
+
class PnxJson
|
4
|
+
|
5
|
+
attr_reader :csf
|
6
|
+
|
7
|
+
def initialize(raw_data)
|
8
|
+
@json = raw_data
|
9
|
+
construct_csf
|
10
|
+
@csf
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def to_csf
|
16
|
+
return @csf unless @csf.nil?
|
17
|
+
@csf = CSF.new
|
18
|
+
@hash = {}
|
19
|
+
add_item_type
|
20
|
+
parse_and_add_creators
|
21
|
+
parse_and_add_publisher
|
22
|
+
add_pages
|
23
|
+
add_isbn
|
24
|
+
add_issn
|
25
|
+
add_eissn
|
26
|
+
add_all_other_fields
|
27
|
+
add_imported_from
|
28
|
+
@csf.load_from_hash(@hash)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def item_type_conversion_hash
|
34
|
+
@item_type_conversion_hash ||= {
|
35
|
+
"audio" => "audioRecording",
|
36
|
+
"video" => "videoRecording",
|
37
|
+
"article" => "journalArticle",
|
38
|
+
"books" => "book",
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def item_type_conversion_array
|
43
|
+
@item_type_conversion_array ||= [
|
44
|
+
"book",
|
45
|
+
"report",
|
46
|
+
"webpage",
|
47
|
+
"journal",
|
48
|
+
"map",
|
49
|
+
"thesis"
|
50
|
+
]
|
51
|
+
end
|
52
|
+
|
53
|
+
def qualified_method_names
|
54
|
+
@qualified_method_names ||= {
|
55
|
+
"title" => "title",
|
56
|
+
"publicationDate" => "publicationDate",
|
57
|
+
"journalTitle" => "journalTitle",
|
58
|
+
"date" => "date",
|
59
|
+
"language" => "languageId",
|
60
|
+
"edition" => "edition",
|
61
|
+
"tags" => "tags",
|
62
|
+
"callNumber" => "callNumber",
|
63
|
+
"pnxRecordId" => "pnxRecordId",
|
64
|
+
"description" => "description",
|
65
|
+
"notes" => "notes"
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_item_type(raw_item_type)
|
70
|
+
raw_item_type.downcase!
|
71
|
+
return raw_item_type if item_type_conversion_array.include?(raw_item_type)
|
72
|
+
return item_type_conversion_hash[raw_item_type] if item_type_conversion_hash.include?(raw_item_type)
|
73
|
+
return 'document'
|
74
|
+
end
|
75
|
+
|
76
|
+
def add_item_type
|
77
|
+
type = @json["type"] || @json["@TYPE"] || 'document'
|
78
|
+
@hash["itemType"] = get_item_type(type)
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def parse_and_add_creators
|
83
|
+
contributors = []
|
84
|
+
creator = [@json["creator"]].compact
|
85
|
+
|
86
|
+
creators = @json["creator"]
|
87
|
+
creators = @json["contributor"] if creator.empty?
|
88
|
+
contributors = @json["contributor"] unless creator.empty?
|
89
|
+
|
90
|
+
creators = @json["addau"] if (creator.empty? && [@json["contributor"]].compact.empty?)
|
91
|
+
|
92
|
+
add_creators(creators, "author")
|
93
|
+
add_creators(contributors, "contributor")
|
94
|
+
end
|
95
|
+
|
96
|
+
def add_creators(creators,creator_type)
|
97
|
+
if (creators && !creators.empty?)
|
98
|
+
creators.each do |name|
|
99
|
+
@hash[creator_type] = [@hash[creator_type], name.strip].flatten.compact
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def parse_and_add_publisher
|
105
|
+
return if [@json["publisher"]].compact.empty?
|
106
|
+
@json["publisher"].each do |json_pub|
|
107
|
+
if json_pub.include? " : "
|
108
|
+
pub_place, publisher = json_pub.split(" : ",2).map(&:strip)
|
109
|
+
add_publisher_and_place(publisher, pub_place)
|
110
|
+
else
|
111
|
+
add_publisher_and_place(json_pub)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def add_publisher_and_place(publisher = nil, place = nil)
|
117
|
+
@hash['publisher'] = publisher if publisher
|
118
|
+
@hash['place'] = place if place
|
119
|
+
end
|
120
|
+
|
121
|
+
def add_pages
|
122
|
+
return unless @json["pages"]
|
123
|
+
raw_pages = @json["pages"].gsub(/[\(\)\[\]]/, "").gsub(/\D/, " ").strip()
|
124
|
+
@hash['numPages'] = raw_pages.split(" ").first unless raw_pages.empty?
|
125
|
+
end
|
126
|
+
|
127
|
+
def add_isbn
|
128
|
+
isbn = [@json['isbn'], @json['isbn10'], @json['isbn13']].flatten.compact.uniq
|
129
|
+
@hash['isbn'] = [@hash['isbn'], isbn].flatten.compact unless isbn.empty?
|
130
|
+
end
|
131
|
+
|
132
|
+
def add_eissn
|
133
|
+
eissn = @json['eissn'] || []
|
134
|
+
@hash['eissn'] = [@hash['eissn'], eissn].flatten.compact unless eissn.empty?
|
135
|
+
end
|
136
|
+
|
137
|
+
def add_issn
|
138
|
+
issn = @json['issn'] || []
|
139
|
+
@hash['issn'] = [@hash['issn'], issn].flatten.compact unless issn.empty?
|
140
|
+
end
|
141
|
+
|
142
|
+
def add_all_other_fields
|
143
|
+
qualified_method_names.each do |standard_form, method_name|
|
144
|
+
@hash[standard_form] = @json[method_name] unless [@json[method_name]].compact.empty?
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def add_imported_from
|
149
|
+
@hash['importedFrom'] = "PNX_JSON"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
@@ -51,7 +51,7 @@ module Citero
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def output_isbn
|
54
|
-
openurl_param('rft_id=
|
54
|
+
openurl_param('rft_id=urn:isbn:', @csf['isbn'], false) + openurl_param('isbn', @csf['isbn'])
|
55
55
|
end
|
56
56
|
|
57
57
|
def output_type
|
@@ -65,11 +65,28 @@ module Citero
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def output_date
|
68
|
-
|
68
|
+
output = ""
|
69
|
+
output = openurl_param('date', @csf['issueDate']) if @csf['itemType'].eql?("patent")
|
70
|
+
output += openurl_param('date', @csf['date'])
|
71
|
+
end
|
72
|
+
|
73
|
+
def output_series
|
74
|
+
openurl_param('series', @csf['series'])
|
75
|
+
end
|
76
|
+
|
77
|
+
def output_journalAbbreviation
|
78
|
+
openurl_param('stitle', @csf['journalAbbreviation'])
|
79
|
+
end
|
80
|
+
|
81
|
+
def output_degree
|
82
|
+
openurl_param('degree', @csf['type'])
|
69
83
|
end
|
70
84
|
|
71
85
|
def output_title
|
72
|
-
|
86
|
+
openurl_key = 'title'
|
87
|
+
openurl_key = 'atitle' if ["journalArticle", "bookSection", "conferencePaper"].include?(@csf['itemType'])
|
88
|
+
openurl_key = 'btitle' if @csf['itemType'].eql?('book')
|
89
|
+
openurl_param(openurl_key, @csf['title'])
|
73
90
|
end
|
74
91
|
|
75
92
|
def output_author
|
@@ -77,7 +94,10 @@ module Citero
|
|
77
94
|
end
|
78
95
|
|
79
96
|
def output_bookTitle
|
80
|
-
|
97
|
+
output = ""
|
98
|
+
output = openurl_param('btitle', @csf['proceedingsTitle']) if @csf['itemType'].eql?('bookSection')
|
99
|
+
output = openurl_param('btitle', @csf['publicationsTitle']) if @csf['itemType'].eql?('conferencePaper')
|
100
|
+
output += openurl_param('btitle', @csf['bookTitle'])
|
81
101
|
end
|
82
102
|
|
83
103
|
def output_publicationTitle
|
@@ -97,7 +117,11 @@ module Citero
|
|
97
117
|
end
|
98
118
|
|
99
119
|
def output_volume
|
100
|
-
|
120
|
+
output = ""
|
121
|
+
if @csf['itemType'].eql? "journalArticle"
|
122
|
+
output = openurl_param('volume', @csf['volume']) + openurl_param('volume', @csf['title'])
|
123
|
+
end
|
124
|
+
output += openurl_param('volume', @csf['volume'])
|
101
125
|
end
|
102
126
|
|
103
127
|
def output_reportNumber
|
@@ -113,7 +137,9 @@ module Citero
|
|
113
137
|
end
|
114
138
|
|
115
139
|
def output_publisher
|
116
|
-
|
140
|
+
output = ""
|
141
|
+
output = openurl_param('inst', @csf['publisher']) if @csf['itemType'].eql? "thesis"
|
142
|
+
output += openurl_param('publisher', @csf['publisher'])
|
117
143
|
end
|
118
144
|
|
119
145
|
def output_place
|
@@ -192,7 +218,10 @@ module Citero
|
|
192
218
|
:output_numPages,
|
193
219
|
:output_isbn,
|
194
220
|
:output_issn,
|
195
|
-
:output_tags
|
221
|
+
:output_tags,
|
222
|
+
:output_series,
|
223
|
+
:output_journalAbbreviation,
|
224
|
+
:output_degree
|
196
225
|
]
|
197
226
|
end
|
198
227
|
end
|
data/lib/citero/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: citero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.alpha5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hab278
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- lib/citero/inputs.rb
|
123
123
|
- lib/citero/inputs/openurl.rb
|
124
124
|
- lib/citero/inputs/pnx.rb
|
125
|
+
- lib/citero/inputs/pnx_json.rb
|
125
126
|
- lib/citero/inputs/readers.rb
|
126
127
|
- lib/citero/inputs/readers/pnx_reader.rb
|
127
128
|
- lib/citero/outputs.rb
|