Class: RelatonBib::BibliographicItem
- Inherits:
-
Object
- Object
- RelatonBib::BibliographicItem
show all
- Includes:
- RelatonBib
- Defined in:
- lib/relaton_bib/biblio_version.rb,
lib/relaton_bib/bibliographic_item.rb
Overview
Defined Under Namespace
Classes: Version
Constant Summary
collapse
- TYPES =
%W[article book booklet conference manual proceedings presentation
thesis techreport standard unpublished map electronic\sresource
audiovisual film video broadcast graphic_work music patent
inbook incollection inproceedings journal].freeze
Constants included
from RelatonBib
VERSION
Instance Attribute Summary collapse
-
#abstract(lang: nil) ⇒ RelatonBib::FormattedString+
readonly
-
#accesslocation ⇒ Array<Strig>
readonly
-
#biblionote ⇒ Array<RelatonBib::BiblioNote>
readonly
-
#classification ⇒ Relaton::Classification, NilClass
readonly
-
#contributor ⇒ Array<RelatonBib::ContributionInfo>
readonly
-
#copyright ⇒ RelatonBib::CopyrightAssociation, NilClass
readonly
-
#date ⇒ Array<RelatonBib::BibliographicDate>
readonly
-
#docidentifier ⇒ Array<RelatonBib::DocumentIdentifier>
readonly
-
#docnumber ⇒ String, NilClass
readonly
-
#edition ⇒ String, NillClass
readonly
-
#extent ⇒ Array<RelatonBib::BibItemLocality>
readonly
-
#fetched ⇒ Date
readonly
-
#formattedref ⇒ RelatonBib::FormattedRef, NilClass
readonly
-
#id ⇒ String, NilClass
readonly
-
#language ⇒ Array<String>
readonly
-
#link ⇒ Array<RelatonBib::TypedUri>
readonly
-
#medium ⇒ RelatonBib::Medium, NilClass
readonly
-
#place ⇒ Array<String>
readonly
-
#relation ⇒ RelatonBib::DocRelationCollection
readonly
-
#script ⇒ Array<String>
readonly
-
#series ⇒ Array<RelatonBib::Series>
readonly
-
#status ⇒ RelatonBib::DocumentStatus, NilClass
readonly
-
#title ⇒ Array<RelatonBib::TypedTitleString>
readonly
-
#type ⇒ String, NilClass
readonly
-
#validity ⇒ RelatonBib:Validity, NilClass
readonly
-
#version ⇒ RelatonBib::BibliongraphicItem::Version, NilClass
readonly
Instance Method Summary
collapse
Methods included from RelatonBib
array, formattedref, hash_to_bib, localizedstring, localname, parse_date, symbolize, timestamp_hash
Constructor Details
Returns a new instance of BibliographicItem.
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
216
217
218
219
220
221
222
223
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 170
def initialize(**args)
if args[:type] && !TYPES.include?(args[:type])
raise ArgumentError, %{Type "#{args[:type]}" is invalid.}
end
@title = (args[:title] || []).map do |t|
t.is_a?(Hash) ? TypedTitleString.new(t) : t
end
@date = (args[:date] || []).map do |d|
d.is_a?(Hash) ? BibliographicDate.new(d) : d
end
@contributor = (args[:contributor] || []).map do |c|
if c.is_a? Hash
e = c[:entity].is_a?(Hash) ? Organization.new(c[:entity]) : c[:entity]
ContributionInfo.new(entity: e, role: c[:role])
else c
end
end
@abstract = (args[:abstract] || []).map do |a|
a.is_a?(Hash) ? FormattedString.new(a) : a
end
if args[:copyright]
@copyright = if args[:copyright].is_a?(Hash)
CopyrightAssociation.new args[:copyright]
else args[:copyright]
end
end
@docidentifier = args[:docid] || []
@formattedref = args[:formattedref] if title.empty?
@id = args[:id] || makeid(nil, false)
@type = args[:type]
@docnumber = args[:docnumber]
@edition = args[:edition]
@version = args[:version]
@biblionote = args.fetch :biblionote, []
@language = args.fetch :language, []
@script = args.fetch :script, []
@status = args[:docstatus]
@relation = DocRelationCollection.new(args[:relation] || [])
@link = args.fetch(:link, []).map { |s| s.is_a?(Hash) ? TypedUri.new(s) : s }
@series = args.fetch :series, []
@medium = args[:medium]
@place = args.fetch(:place, [])
@extent = args[:extent] || []
@accesslocation = args.fetch :accesslocation, []
@classification = args[:classification]
@validity = args[:validity]
@fetched = args.fetch :fetched, nil end
|
Instance Attribute Details
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 78
|
#accesslocation ⇒ Array<Strig>
103
104
105
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 103
def accesslocation
@accesslocation
end
|
67
68
69
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 67
def biblionote
@biblionote
end
|
#classification ⇒ Relaton::Classification, NilClass
106
107
108
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 106
def classification
@classification
end
|
58
59
60
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 58
def contributor
@contributor
end
|
85
86
87
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 85
def copyright
@copyright
end
|
55
56
57
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 55
def date
@date
end
|
49
50
51
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 49
def docidentifier
@docidentifier
end
|
#docnumber ⇒ String, NilClass
52
53
54
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 52
def docnumber
@docnumber
end
|
#edition ⇒ String, NillClass
61
62
63
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 61
def edition
@edition
end
|
100
101
102
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 100
def extent
@extent
end
|
#fetched ⇒ Date
112
113
114
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 112
def fetched
@fetched
end
|
76
77
78
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 76
def formattedref
@formattedref
end
|
#id ⇒ String, NilClass
37
38
39
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 37
def id
@id
end
|
#language ⇒ Array<String>
Returns language Iso639 code.
70
71
72
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 70
def language
@language
end
|
43
44
45
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 43
def link
@link
end
|
94
95
96
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 94
def medium
@medium
end
|
#place ⇒ Array<String>
97
98
99
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 97
def place
@place
end
|
88
89
90
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 88
def relation
@relation
end
|
#script ⇒ Array<String>
Returns script Iso15924 code.
73
74
75
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 73
def script
@script
end
|
91
92
93
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 91
def series
@series
end
|
82
83
84
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 82
def status
@status
end
|
40
41
42
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 40
def title
@title
end
|
#type ⇒ String, NilClass
46
47
48
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 46
def type
@type
end
|
#validity ⇒ RelatonBib:Validity, NilClass
109
110
111
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 109
def validity
@validity
end
|
#version ⇒ RelatonBib::BibliongraphicItem::Version, NilClass
64
65
66
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 64
def version
@version
end
|
Instance Method Details
#makeid(id, attribute) ⇒ Object
237
238
239
240
241
242
243
244
245
246
247
248
249
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 237
def makeid(id, attribute)
return nil if attribute && !@id_attribute
id ||= @docidentifier.reject { |i| i.type == "DOI" }[0]
return unless id
idstr = id.id.gsub(/:/, "-").gsub /\s/, ""
idstr.strip
end
|
#shortref(identifier, **opts) ⇒ String
252
253
254
255
256
257
258
259
260
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 252
def shortref(identifier, **opts)
pubdate = date.select { |d| d.type == "published" }
year = if opts[:no_year] || pubdate.empty? then ""
else ":" + pubdate&.first&.on&.year.to_s
end
year += ": All Parts" if opts[:all_parts] || @all_parts
"#{makeid(identifier, false)}#{year}"
end
|
#to_hash ⇒ Hash
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 275
def to_hash
hash = {}
hash["id"] = id if id
hash["title"] = single_element_array(title) if title&.any?
hash["link"] = single_element_array(link) if link&.any?
hash["type"] = type if type
hash["docid"] = single_element_array(docidentifier) if docidentifier&.any?
hash["docnumber"] = docnumber if docnumber
hash["date"] = single_element_array(date) if date&.any?
hash["contributor"] = single_element_array(contributor) if contributor&.any?
hash["edition"] = edition if edition
hash["version"] = version.to_hash if version
hash["biblionote"] = single_element_array(biblionote) if biblionote&.any?
hash["language"] = single_element_array(language) if language&.any?
hash["script"] = single_element_array(script) if script&.any?
hash["formattedref"] = formattedref.to_hash if formattedref
hash["abstract"] = single_element_array(abstract) if abstract&.any?
hash["docstatus"] = status.to_hash if status
hash["copyright"] = copyright.to_hash if copyright
hash["relation"] = single_element_array(relation) if relation&.any?
hash["series"] = single_element_array(series) if series&.any?
hash["medium"] = medium.to_hash if medium
hash["place"] = single_element_array(place) if place&.any?
hash["extent"] = single_element_array(extent) if extent&.any?
hash["accesslocation"] = single_element_array(accesslocation) if accesslocation&.any?
hash["classification"] = classification.to_hash if classification
hash["validity"] = validity.to_hash if validity
hash["fetched"] = fetched.to_s if fetched
hash
end
|
#to_xml(builder = nil, **opts, &block) ⇒ String
264
265
266
267
268
269
270
271
272
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 264
def to_xml(builder = nil, **opts, &block)
if builder
render_xml builder, **opts, &block
else
Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
render_xml xml, **opts, &block
end.doc.root.to_xml
end
end
|