Class: EBSCO::EDS::Citations
- Inherits:
-
Object
- Object
- EBSCO::EDS::Citations
show all
- Includes:
- JSONable
- Defined in:
- lib/ebsco/eds/citations.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from JSONable
#as_json, included, #to_json
Constructor Details
#initialize(dbid:, an:, citation_result:, eds_config: nil) ⇒ Citations
Returns a new instance of Citations.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
# File 'lib/ebsco/eds/citations.rb', line 11
def initialize(dbid:, an:, citation_result:, eds_config: nil)
(ENV.has_key? 'EDS_DEBUG') ?
if %w(y Y yes Yes true True).include?(ENV['EDS_DEBUG'])
@debug = true
else
@debug = false
end :
@debug = eds_config[:debug]
(ENV.has_key? 'EDS_CITATION_LINK_FIND') ?
if !ENV['EDS_CITATION_LINK_FIND'].empty?
@citation_link_find = ENV['EDS_CITATION_LINK_FIND']
else
@citation_link_find = ""
end :
@citation_link_find = eds_config[:citation_link_find]
(ENV.has_key? 'EDS_CITATION_LINK_REPLACE') ?
if !ENV['EDS_CITATION_LINK_REPLACE'].empty?
@citation_link_replace = ENV['EDS_CITATION_LINK_REPLACE']
else
@citation_link_replace = ""
end :
@citation_link_replace = eds_config[:citation_link_replace]
(ENV.has_key? 'EDS_CITATION_DB_FIND') ?
if !ENV['EDS_CITATION_DB_FIND'].empty?
@citation_db_find = ENV['EDS_CITATION_DB_FIND']
else
@citation_db_find = ""
end :
@citation_db_find = eds_config[:citation_db_find]
(ENV.has_key? 'EDS_CITATION_DB_REPLACE') ?
if !ENV['EDS_CITATION_DB_REPLACE'].empty?
@citation_db_replace = ENV['EDS_CITATION_DB_REPLACE']
else
@citation_db_replace = ""
end :
@citation_db_replace = eds_config[:citation_db_replace]
(ENV.has_key? 'EDS_RIS_LINK_FIND') ?
if !ENV['EDS_RIS_LINK_FIND'].empty?
@ris_link_find = ENV['EDS_RIS_LINK_FIND']
else
@ris_link_find = ""
end :
@ris_link_find = eds_config[:ris_link_find]
(ENV.has_key? 'EDS_RIS_LINK_REPLACE') ?
if !ENV['EDS_RIS_LINK_REPLACE'].empty?
@ris_link_replace = ENV['EDS_RIS_LINK_REPLACE']
else
@ris_link_replace = ""
end :
@ris_link_replace = eds_config[:ris_link_replace]
(ENV.has_key? 'EDS_RIS_DB_FIND') ?
if !ENV['EDS_RIS_DB_FIND'].empty?
@ris_db_find = ENV['EDS_RIS_DB_FIND']
else
@ris_db_find = ""
end :
@ris_db_find = eds_config[:ris_db_find]
(ENV.has_key? 'EDS_RIS_DB_REPLACE') ?
if !ENV['EDS_RIS_DB_REPLACE'].empty?
@ris_db_replace = ENV['EDS_RIS_DB_REPLACE']
else
@ris_db_replace = ""
end :
@ris_db_replace = eds_config[:ris_db_replace]
@eds_database_id = dbid
@eds_accession_number = an
@eds_record_id = @eds_database_id + '__' + @eds_accession_number
@items = []
if citation_result.key? 'Citations'
citation_result['Citations'].each do |style|
item = {}
if style.key? 'Id'
item['id'] = JSON.parse(style['Id'].to_json)
end
if style.key? 'Label'
puts if @debug
puts style['Label'].inspect if @debug
item['label'] = JSON.parse(style['Label'].to_json)
end
if style.key? 'Data'
data = JSON.parse(style['Data'].to_json)
if data
puts 'BEFORE: ' + data.inspect if @debug
unless @citation_link_find.empty?
replace_template = ERB.new(@citation_link_replace)
find_template = ERB.new(@citation_link_find)
replace_link = replace_template.result(binding)
find_link_regex = find_template.result(binding)
link_regex = Regexp.new find_link_regex
data = data.gsub!(link_regex, replace_link) || data
end
unless @citation_db_find.empty?
replace_template = ERB.new(@citation_db_replace)
find_template = ERB.new(@citation_db_find)
replace_db = replace_template.result(binding)
find_db_regex = find_template.result(binding)
link_regex = Regexp.new find_db_regex
data = data.gsub!(link_regex, replace_db) || data
end
puts 'AFTER: ' + data.inspect if @debug
end
item['data'] = data
end
if style.key? 'Caption'
item['caption'] = JSON.parse(style['Caption'].to_json)
end
if style.key? 'SectionLabel'
item['section_label'] = JSON.parse(style['SectionLabel'].to_json)
end
if style.key? 'Error'
item['error'] = JSON.parse(style['Error'].to_json)
end
@items.push item
end
else
item = {}
if citation_result.key? 'Format'
item['id'] = JSON.parse(citation_result['Format'].to_json)
end
if citation_result.key? 'Label'
item['label'] = JSON.parse(citation_result['Label'].to_json)
end
if citation_result.key? 'Data'
data = JSON.parse(citation_result['Data'].to_json)
if data
puts "BEFORE: \n" if @debug
puts data if @debug
unless @citation_link_find.empty?
replace_template = ERB.new(@ris_link_replace)
find_template = ERB.new(@ris_link_find)
replace_link = replace_template.result(binding)
find_link_regex = find_template.result(binding)
link_regex = Regexp.new find_link_regex
data = data.gsub!(link_regex, replace_link) || data
end
unless @ris_db_find.empty?
replace_template = ERB.new(@ris_db_replace)
find_template = ERB.new(@ris_db_find)
replace_db = replace_template.result(binding)
find_db_regex = find_template.result(binding)
link_regex = Regexp.new find_db_regex
data = data.gsub!(link_regex, replace_db) || data
end
puts if @debug
puts "AFTER: \n" if @debug
puts data if @debug
end
item['data'] = data
end
if citation_result.key? 'Error'
item['error'] = JSON.parse(citation_result['Error'].to_json)
end
@items.push item
end
end
|
Instance Attribute Details
#eds_accession_number ⇒ Object
Returns the value of attribute eds_accession_number.
9
10
11
|
# File 'lib/ebsco/eds/citations.rb', line 9
def eds_accession_number
@eds_accession_number
end
|
#eds_database_id ⇒ Object
Returns the value of attribute eds_database_id.
9
10
11
|
# File 'lib/ebsco/eds/citations.rb', line 9
def eds_database_id
@eds_database_id
end
|
#eds_record_id ⇒ Object
Returns the value of attribute eds_record_id.
9
10
11
|
# File 'lib/ebsco/eds/citations.rb', line 9
def eds_record_id
@eds_record_id
end
|
#items ⇒ Object
Returns the value of attribute items.
9
10
11
|
# File 'lib/ebsco/eds/citations.rb', line 9
def items
@items
end
|
Instance Method Details
#applyDbTemplateToExports(data) ⇒ Object
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
|
# File 'lib/ebsco/eds/citations.rb', line 291
def applyDbTemplateToExports(data)
if data
renderer = ERB.new(@db_template)
new_db = renderer.result(binding)
unless new_db.empty?
if @debug
puts 'doing db template...'
puts 'BEFORE:'
puts data.inspect
end
data.gsub!(/DP\s+-\s+EBSCOhost/, 'DP - ' + new_db)
if @debug
puts 'AFTER:'
puts data.inspect
end
end
end
data
end
|
#applyDbTemplateToStyles(data) ⇒ Object
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
# File 'lib/ebsco/eds/citations.rb', line 331
def applyDbTemplateToStyles(data)
if data
renderer = ERB.new(@db_template)
new_db = renderer.result(binding)
unless new_db.empty?
if @debug
puts 'doing db template...'
puts 'BEFORE:'
puts data.inspect
end
data.gsub!(/<i>EBSCOhost<\/i>/, '<i>' + new_db + '</i>')
if @debug
puts 'AFTER:'
puts data.inspect
end
end
end
data
end
|
#applyLinksTemplateToExports(data, dbid, an) ⇒ Object
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
# File 'lib/ebsco/eds/citations.rb', line 271
def applyLinksTemplateToExports(data, dbid, an)
if data
renderer = ERB.new(@links_template)
new_link = renderer.result(binding)
unless new_link.empty?
if @debug
puts 'doing links template...'
puts 'BEFORE:'
puts data.inspect
end
data.gsub!(/UR\s+--\s+http:\/\/search\.ebscohost\.com\/login\.aspx\?direct=true&site=eds-live&db=#{dbid}&AN=#{an}/, 'UR - ' + new_link)
if @debug
puts 'AFTER:'
puts data.inspect
end
end
end
data
end
|
#applyLinksTemplateToStyles(data, dbid, an) ⇒ Object
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
|
# File 'lib/ebsco/eds/citations.rb', line 311
def applyLinksTemplateToStyles(data, dbid, an)
if data
renderer = ERB.new(@links_template)
new_link = renderer.result(binding)
unless new_link.empty?
if @debug
puts 'doing links template...'
puts 'BEFORE:'
puts data.inspect
end
data.gsub!(/(http:\/\/)?search\.ebscohost\.com\/login\.aspx\?direct=true&site=eds-live&db=#{dbid}&AN=#{an}/, new_link)
if @debug
puts 'AFTER:'
puts data.inspect
end
end
end
data
end
|
#removeLinksFromExports(citation) ⇒ Object
258
259
260
261
262
263
264
265
266
267
268
269
|
# File 'lib/ebsco/eds/citations.rb', line 258
def removeLinksFromExports(citation)
if citation
citation.gsub!(/UR\s+-\s+http:\/\/search\.ebscohost\.com.+\s+/,'')
citation.gsub!(/DP\s+-\s+EBSCOhost\s+/, '')
end
citation
end
|
#removeLinksFromStyles(citation) ⇒ Object
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
|
# File 'lib/ebsco/eds/citations.rb', line 218
def removeLinksFromStyles(citation)
if citation
citation.gsub!(/[.,]\s+(<i>EBSCOhost|viewed|Available|Retrieved from|http:\/\/search.ebscohost.com|Disponível em).+$/, '.')
end
citation
end
|