Class: RelatonBib::BibliographicItem
- Inherits:
-
Object
- Object
- RelatonBib::BibliographicItem
- 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
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
Docnumber.
- #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
Language Iso639 code.
- #link ⇒ Array<RelatonBib::TypedUri> readonly
- #medium ⇒ RelatonBib::Medium, NilClass readonly
- #place ⇒ Array<String> readonly
- #relation ⇒ RelatonBib::DocRelationCollection readonly
-
#script ⇒ Array<String>
readonly
Script Iso15924 code.
- #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
-
#initialize(**args) ⇒ BibliographicItem
constructor
A new instance of BibliographicItem.
- #makeid(id, attribute) ⇒ Object
- #shortref(identifier, **opts) ⇒ String
- #to_hash ⇒ Hash
- #to_xml(builder = nil, **opts, &block) ⇒ String
Constructor Details
#initialize(**args) ⇒ BibliographicItem
Returns a new instance of BibliographicItem.
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 216 217 218 219 220 221 222 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 169 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 # , Date.today # we should pass the fetched arg from scrappers end |
Instance Attribute Details
#abstract(lang: nil) ⇒ RelatonBib::FormattedString+ (readonly)
|
|
# 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 |
#biblionote ⇒ Array<RelatonBib::BiblioNote> (readonly)
66 67 68 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 66 def biblionote @biblionote end |
#classification ⇒ Relaton::Classification, NilClass (readonly)
105 106 107 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 105 def classification @classification end |
#contributor ⇒ Array<RelatonBib::ContributionInfo> (readonly)
57 58 59 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 57 def contributor @contributor end |
#copyright ⇒ RelatonBib::CopyrightAssociation, NilClass (readonly)
84 85 86 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 84 def copyright @copyright end |
#date ⇒ Array<RelatonBib::BibliographicDate> (readonly)
54 55 56 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 54 def date @date end |
#docidentifier ⇒ Array<RelatonBib::DocumentIdentifier> (readonly)
48 49 50 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 48 def docidentifier @docidentifier end |
#docnumber ⇒ String, NilClass (readonly)
Returns docnumber.
51 52 53 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 51 def docnumber @docnumber end |
#edition ⇒ String, NillClass (readonly)
60 61 62 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 60 def edition @edition 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 |
#id ⇒ String, NilClass (readonly)
36 37 38 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 36 def id @id 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 |
#link ⇒ Array<RelatonBib::TypedUri> (readonly)
42 43 44 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 42 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<String> (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 |
#title ⇒ Array<RelatonBib::TypedTitleString> (readonly)
39 40 41 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 39 def title @title end |
#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
#makeid(id, attribute) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 236 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 |
#shortref(identifier, **opts) ⇒ String
251 252 253 254 255 256 257 258 259 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 251 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
274 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 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 274 def to_hash hash = {} hash[:id] = id if id hash[:title] = title.map(&:to_hash) if title&.any? hash[:link] = link.map(&:to_hash) if link&.any? hash[:type] = type if type hash[:docid] = docidentifier.map(&:to_hash) if docidentifier&.any? hash[:docnumber] = docnumber if docnumber hash[:date] = date.map(&:to_hash) if date&.any? hash[:contributor] = contributor.map(&:to_hash) if contributor&.any? hash[:edition] = edition if edition hash[:version] = version.to_hash if version hash[:biblionote] = biblionote.map(&:to_hash) if biblionote&.any? hash[:language] = language if language&.any? hash[:script] = script if script&.any? hash[:formattedref] = formattedref.to_hash if formattedref hash[:abstract] = abstract.map(&:to_hash) if abstract&.any? hash[:docstatus] = status.to_hash if status hash[:copyright] = copyright.to_hash if copyright hash[:relation] = relation.map(&:to_hash) if relation&.any? hash[:series] = series.map(&:to_hash) if series&.any? hash[:medium] = medium.to_hash if medium hash[:place] = place if place&.any? hash[:extent] = extent.map(&:to_hash) if extent&.any? hash[:accesslocation] = 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
263 264 265 266 267 268 269 270 271 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 263 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 |