Class: RelatonBib::BibliographicItem
- Includes:
- RelatonBib
- Defined in:
- lib/relaton_bib/biblio_version.rb,
lib/relaton_bib/bibliographic_item.rb
Overview
Bibliographic item
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
Instance Attribute Summary collapse
- #abstract(lang: nil) ⇒ RelatonBib::FormattedString+
- #accesslocation ⇒ Array<Strig> readonly
- #all_parts ⇒ TrueClass, ...
- #biblionote ⇒ Array<RelatonBib::BiblioNote> readonly
- #classification ⇒ Array<Relaton::Classification> readonly
- #contributor ⇒ Array<RelatonBib::ContributionInfo> readonly
- #copyright ⇒ Array<RelatonBib::CopyrightAssociation> readonly
- #date ⇒ Array<RelatonBib::BibliographicDate>
- #docidentifier ⇒ Array<RelatonBib::DocumentIdentifier> readonly
- #docnumber ⇒ String, NilClass readonly
- #doctype ⇒ String, NilClass readonly
- #edition ⇒ String, NilClass readonly
- #editorialgroup ⇒ RelatonBib::EditorialGroup? readonly
- #extent ⇒ Array<RelatonBib::BibItemLocality> readonly
- #fetched ⇒ Date readonly
- #formattedref ⇒ RelatonBib::FormattedRef, NilClass readonly
- #ics ⇒ Array<RelatonBib:ICS> readonly
- #id ⇒ String, NilClass readonly
- #keyword ⇒ Array<RelatonBib::LocalizedString> readonly
-
#language ⇒ Array<String>
readonly
Language Iso639 code.
- #license ⇒ Array<Strig> readonly
- #link ⇒ Array<RelatonBib::TypedUri> readonly
- #medium ⇒ RelatonBib::Medium, NilClass readonly
- #place ⇒ Array<RelatonBib::Place> readonly
- #relation ⇒ RelatonBib::DocRelationCollection readonly
-
#script ⇒ Array<String>
readonly
Script Iso15924 code.
- #series ⇒ Array<RelatonBib::Series> readonly
- #status ⇒ RelatonBib::DocumentStatus, NilClass readonly
- #structuredidentifier ⇒ RelatonBib::StructuredIdentifierCollection readonly
- #title(lang: nil) ⇒ Array<RelatonIsoBib::TypedTitleString> readonly
- #type ⇒ String, NilClass readonly
- #validity ⇒ RelatonBib:Validity, NilClass readonly
- #version ⇒ RelatonBib::BibliongraphicItem::Version, NilClass readonly
Instance Method Summary collapse
- #deep_clone ⇒ Object
- #disable_id_attribute ⇒ Object
-
#initialize(**args) ⇒ BibliographicItem
constructor
A new instance of BibliographicItem.
- #makeid(id, attribute) ⇒ Object
-
#revdate ⇒ String, NilClass
If revision_date exists then returns it else returns published date or nil.
- #shortref(identifier, **opts) ⇒ String
-
#to_all_parts ⇒ Object
remove title part components and abstract.
- #to_bibtex(bibtex = nil) ⇒ String
- #to_hash ⇒ Hash
-
#to_most_recent_reference ⇒ Object
convert ISO:yyyy reference to reference to most recent instance of reference, removing date-specific infomration: date of publication, abstracts.
- #to_xml(builder = nil, **opts, &block) ⇒ String
- #url(type = :src) ⇒ String
Methods included from RelatonBib
Constructor Details
#initialize(**args) ⇒ BibliographicItem
Returns a new instance of BibliographicItem.
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 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 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 191 def initialize(**args) if args[:type] && !TYPES.include?(args[:type]) warn %{[relaton-bib] document 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 @copyright = args.fetch(:copyright, []).map do |c| c.is_a?(Hash) ? CopyrightAssociation.new(c) : c 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 do |s| if s.is_a?(Hash) then TypedUri.new(s) elsif s.is_a?(String) then TypedUri.new(content: s) else s end end @series = args.fetch :series, [] @medium = args[:medium] @place = args.fetch(:place, []).map { |pl| pl.is_a?(String) ? Place.new(name: pl) : pl } @extent = args[:extent] || [] @accesslocation = args.fetch :accesslocation, [] @classification = args.fetch :classification, [] @validity = args[:validity] @fetched = args.fetch :fetched, nil # , Date.today # we should pass the fetched arg from scrappers @keyword = (args[:keyword] || []).map { |kw| LocalizedString.new(kw) } @license = args.fetch :license, [] @doctype = args[:doctype] @editorialgroup = args[:editorialgroup] @ics = args.fetch :ics, [] @structuredidentifier = args[:structuredidentifier] end |
Instance Attribute Details
#abstract(lang: nil) ⇒ RelatonBib::FormattedString+
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 77
|
#accesslocation ⇒ Array<Strig> (readonly)
102 103 104 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 102 def accesslocation @accesslocation end |
#all_parts ⇒ TrueClass, ...
42 43 44 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 42 def all_parts @all_parts end |
#biblionote ⇒ Array<RelatonBib::BiblioNote> (readonly)
66 67 68 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 66 def biblionote @biblionote end |
#classification ⇒ Array<Relaton::Classification> (readonly)
105 106 107 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 105 def classification @classification end |
#contributor ⇒ Array<RelatonBib::ContributionInfo> (readonly)
60 61 62 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 60 def contributor @contributor end |
#copyright ⇒ Array<RelatonBib::CopyrightAssociation> (readonly)
84 85 86 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 84 def copyright @copyright end |
#date ⇒ Array<RelatonBib::BibliographicDate>
57 58 59 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 57 def date @date end |
#docidentifier ⇒ Array<RelatonBib::DocumentIdentifier> (readonly)
54 55 56 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 54 def docidentifier @docidentifier end |
#docnumber ⇒ String, NilClass (readonly)
45 46 47 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 45 def docnumber @docnumber end |
#doctype ⇒ String, NilClass (readonly)
45 46 47 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 45 def doctype @doctype end |
#edition ⇒ String, NilClass (readonly)
45 46 47 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 45 def edition @edition end |
#editorialgroup ⇒ RelatonBib::EditorialGroup? (readonly)
117 118 119 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 117 def editorialgroup @editorialgroup end |
#extent ⇒ Array<RelatonBib::BibItemLocality> (readonly)
99 100 101 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 99 def extent @extent end |
#fetched ⇒ Date (readonly)
111 112 113 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 111 def fetched @fetched end |
#formattedref ⇒ RelatonBib::FormattedRef, NilClass (readonly)
75 76 77 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 75 def formattedref @formattedref end |
#ics ⇒ Array<RelatonBib:ICS> (readonly)
120 121 122 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 120 def ics @ics end |
#id ⇒ String, NilClass (readonly)
45 46 47 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 45 def id @id end |
#keyword ⇒ Array<RelatonBib::LocalizedString> (readonly)
114 115 116 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 114 def keyword @keyword end |
#language ⇒ Array<String> (readonly)
Returns language Iso639 code.
69 70 71 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 69 def language @language end |
#license ⇒ Array<Strig> (readonly)
102 103 104 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 102 def license @license end |
#link ⇒ Array<RelatonBib::TypedUri> (readonly)
51 52 53 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 51 def link @link end |
#medium ⇒ RelatonBib::Medium, NilClass (readonly)
93 94 95 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 93 def medium @medium end |
#place ⇒ Array<RelatonBib::Place> (readonly)
96 97 98 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 96 def place @place end |
#relation ⇒ RelatonBib::DocRelationCollection (readonly)
87 88 89 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 87 def relation @relation end |
#script ⇒ Array<String> (readonly)
Returns script Iso15924 code.
72 73 74 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 72 def script @script end |
#series ⇒ Array<RelatonBib::Series> (readonly)
90 91 92 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 90 def series @series end |
#status ⇒ RelatonBib::DocumentStatus, NilClass (readonly)
81 82 83 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 81 def status @status end |
#structuredidentifier ⇒ RelatonBib::StructuredIdentifierCollection (readonly)
123 124 125 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 123 def structuredidentifier @structuredidentifier end |
#title(lang: nil) ⇒ Array<RelatonIsoBib::TypedTitleString> (readonly)
|
# File 'lib/relaton_bib/bibliographic_item.rb', line 47
|
#type ⇒ String, NilClass (readonly)
45 46 47 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 45 def type @type end |
#validity ⇒ RelatonBib:Validity, NilClass (readonly)
108 109 110 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 108 def validity @validity end |
#version ⇒ RelatonBib::BibliongraphicItem::Version, NilClass (readonly)
63 64 65 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 63 def version @version end |
Instance Method Details
#deep_clone ⇒ Object
392 393 394 395 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 392 def deep_clone dump = Marshal.dump self Marshal.load dump end |
#disable_id_attribute ⇒ Object
397 398 399 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 397 def disable_id_attribute @id_attribute = false end |
#makeid(id, attribute) ⇒ Object
266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 266 def makeid(id, attribute) return nil if attribute && !@id_attribute id ||= @docidentifier.reject { |i| i.type == "DOI" }[0] return unless id # contribs = publishers.map { |p| p&.entity&.abbreviation }.join '/' # idstr = "#{contribs}#{delim}#{id.project_number}" # idstr = id.project_number.to_s idstr = id.id.gsub(/:/, "-").gsub /\s/, "" # if id.part_number&.size&.positive? then idstr += "-#{id.part_number}" idstr.strip end |
#revdate ⇒ String, NilClass
If revision_date exists then returns it else returns published date or nil
443 444 445 446 447 448 449 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 443 def revdate @revdate ||= if version&.revision_date version.revision_date else date.detect { |d| d.type == "published" }&.on&.to_s end end |
#shortref(identifier, **opts) ⇒ String
281 282 283 284 285 286 287 288 289 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 281 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_all_parts ⇒ Object
remove title part components and abstract
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 402 def to_all_parts me = deep_clone me.disable_id_attribute me.relation << RelatonBib::DocumentRelation.new( type: "instance", bibitem: self, ) me.language.each do |l| me.title.delete_if { |t| t.type == "title-part" } ttl = me.title.select { |t| t.type != "main" && t.title.language&.include?(l) } tm_en = ttl.map { |t| t.title.content }.join " – " me.title.detect { |t| t.type == "main" && t.title.language&.include?(l) }&.title&.content = tm_en end me.abstract = [] me.docidentifier.each(&:remove_part) me.docidentifier.each(&:all_parts) me.structuredidentifier.remove_part me.structuredidentifier.all_parts me.docidentifier.each &:remove_date me.structuredidentifier&.remove_date me.all_parts = true me end |
#to_bibtex(bibtex = nil) ⇒ String
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 349 def to_bibtex(bibtex = nil) item = BibTeX::Entry.new item.type = bibtex_type item.key = id bibtex_title item item.edition = edition if edition item bibtex_contributor item item.address = place.first.name if place.any? bibtex_note item bibtex_relation item bibtex_extent item bibtex_date item bibtex_series item bibtex_classification item item.keywords = keyword.map(&:content).join(", ") if keyword.any? bibtex_docidentifier item item. = fetched.to_s if fetched bibtex_link item bibtex ||= BibTeX::Bibliography.new bibtex << item bibtex.to_s end |
#to_hash ⇒ Hash
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 306 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["revdate"] = revdate if revdate 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"] = single_element_array(copyright) if copyright&.any? 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"] = single_element_array(classification) if classification&.any? hash["validity"] = validity.to_hash if validity hash["fetched"] = fetched.to_s if fetched hash["keyword"] = single_element_array(keyword) if keyword&.any? hash["license"] = single_element_array(license) if license&.any? hash["doctype"] = doctype if doctype hash["editorialgroup"] = editorialgroup.to_hash if editorialgroup hash["ics"] = single_element_array ics if ics.any? if structuredidentifier&.presence? hash["structuredidentifier"] = structuredidentifier.to_hash end hash end |
#to_most_recent_reference ⇒ Object
convert ISO:yyyy reference to reference to most recent instance of reference, removing date-specific infomration: date of publication, abstracts. Make dated reference Instance relation of the redacated document
429 430 431 432 433 434 435 436 437 438 439 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 429 def to_most_recent_reference me = deep_clone disable_id_attribute me.relation << DocumentRelation.new(type: "instance", bibitem: self) me.abstract = [] me.date = [] me.docidentifier.each &:remove_date me.structuredidentifier&.remove_date me.id&.sub! /-[12]\d\d\d/, "" me end |
#to_xml(builder = nil, **opts, &block) ⇒ String
293 294 295 296 297 298 299 300 301 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 293 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 |
#url(type = :src) ⇒ String
384 385 386 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 384 def url(type = :src) @link.detect { |s| s.type == type.to_s }.content.to_s end |