Class: RelatonBib::BibliographicItem
- Inherits:
-
Object
- Object
- RelatonBib::BibliographicItem
- Defined in:
- 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>, NilClass readonly
- #classification ⇒ Relaton::Classification, NilClass readonly
- #contributors ⇒ Array<RelatonBib::ContributionInfo> readonly
- #copyright ⇒ RelatonBib::CopyrightAssociation readonly
- #dates ⇒ Array<RelatonBib::BibliographicDate> readonly
- #docidentifier ⇒ Array<RelatonBib::DocumentIdentifier> readonly
-
#docnumber ⇒ String
readonly
Docnumber.
- #edition ⇒ String, NillClass readonly
- #extent ⇒ Array<RelatonBib::BibItemLocality> readonly
- #fetched ⇒ Date readonly
- #formattedref ⇒ RelatonBib::FormattedRef readonly
- #id ⇒ String readonly
-
#language ⇒ Array<String>
readonly
Language Iso639 code.
- #link ⇒ Array<RelatonBib::TypedUri> readonly
- #medium ⇒ RelatonBib::Medium, NilClass readonly
- #place ⇒ Array<String> readonly
- #relations ⇒ RelatonBib::DocRelationCollection readonly
-
#script ⇒ Array<String>
readonly
Script Iso15924 code.
- #series ⇒ Array<RelatonBib::Series> readonly
- #status ⇒ RelatonBib::DocumentStatus readonly
- #title ⇒ Array<RelatonBib::TypedTitleString> readonly
- #type ⇒ String readonly
- #validity ⇒ RelatonBib:Validity, NilClass readonly
- #version ⇒ RelatonBib::BibliongraphicItem::Version readonly
Instance Method Summary collapse
-
#initialize(**args) ⇒ BibliographicItem
constructor
A new instance of BibliographicItem.
- #makeid(id, attribute) ⇒ Object
- #shortref(identifier, **opts) ⇒ String
- #to_xml(builder = nil, **opts, &block) ⇒ String
Constructor Details
#initialize(**args) ⇒ BibliographicItem
Returns a new instance of BibliographicItem.
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 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 180 def initialize(**args) if args[:type] && !TYPES.include?(args[:type]) raise ArgumentError, %{Type "#{args[:type]}" is invalid.} end @title = (args[:titles] || []).map do |t| t.is_a?(Hash) ? TypedTitleString.new(t) : t end @dates = (args[:dates] || []).map do |d| d.is_a?(Hash) ? BibliographicDate.new(d) : d end @contributors = (args[:contributors] || []).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[:roles]) 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 @id = args[:id] || args[:docid]&.first&.id&.strip&.gsub(/\s/, "") @formattedref = args[:formattedref] if title.empty? @type = args[:type] @docidentifier = args[:docid] || [] @docnumber = args[:docnumber] @edition = args[:edition] @version = args[:version] @biblionote = args.fetch :biblionote, [] @language = args.fetch :language, [] @script = args.fetch :script, [] @status = args[:docstatus] @relations = DocRelationCollection.new(args[:relations] || []) @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 97
|
#accesslocation ⇒ Array<Strig> (readonly)
122 123 124 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 122 def accesslocation @accesslocation end |
#biblionote ⇒ Array<RelatonBib::BiblioNote>, NilClass (readonly)
86 87 88 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 86 def biblionote @biblionote end |
#classification ⇒ Relaton::Classification, NilClass (readonly)
125 126 127 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 125 def classification @classification end |
#contributors ⇒ Array<RelatonBib::ContributionInfo> (readonly)
77 78 79 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 77 def contributors @contributors end |
#copyright ⇒ RelatonBib::CopyrightAssociation (readonly)
104 105 106 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 104 def copyright @copyright end |
#dates ⇒ Array<RelatonBib::BibliographicDate> (readonly)
74 75 76 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 74 def dates @dates end |
#docidentifier ⇒ Array<RelatonBib::DocumentIdentifier> (readonly)
68 69 70 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 68 def docidentifier @docidentifier end |
#docnumber ⇒ String (readonly)
Returns docnumber.
71 72 73 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 71 def docnumber @docnumber end |
#edition ⇒ String, NillClass (readonly)
80 81 82 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 80 def edition @edition end |
#extent ⇒ Array<RelatonBib::BibItemLocality> (readonly)
119 120 121 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 119 def extent @extent end |
#fetched ⇒ Date (readonly)
131 132 133 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 131 def fetched @fetched end |
#formattedref ⇒ RelatonBib::FormattedRef (readonly)
95 96 97 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 95 def formattedref @formattedref end |
#id ⇒ String (readonly)
56 57 58 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 56 def id @id end |
#language ⇒ Array<String> (readonly)
Returns language Iso639 code.
89 90 91 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 89 def language @language end |
#link ⇒ Array<RelatonBib::TypedUri> (readonly)
62 63 64 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 62 def link @link end |
#medium ⇒ RelatonBib::Medium, NilClass (readonly)
113 114 115 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 113 def medium @medium end |
#place ⇒ Array<String> (readonly)
116 117 118 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 116 def place @place end |
#relations ⇒ RelatonBib::DocRelationCollection (readonly)
107 108 109 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 107 def relations @relations end |
#script ⇒ Array<String> (readonly)
Returns script Iso15924 code.
92 93 94 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 92 def script @script end |
#series ⇒ Array<RelatonBib::Series> (readonly)
110 111 112 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 110 def series @series end |
#status ⇒ RelatonBib::DocumentStatus (readonly)
101 102 103 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 101 def status @status end |
#title ⇒ Array<RelatonBib::TypedTitleString> (readonly)
59 60 61 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 59 def title @title end |
#type ⇒ String (readonly)
65 66 67 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 65 def type @type end |
#validity ⇒ RelatonBib:Validity, NilClass (readonly)
128 129 130 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 128 def validity @validity end |
#version ⇒ RelatonBib::BibliongraphicItem::Version (readonly)
83 84 85 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 83 def version @version end |
Instance Method Details
#makeid(id, attribute) ⇒ Object
247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 247 def makeid(id, attribute) return nil if attribute && !@id_attribute id ||= @docidentifier.reject { |i| i.type == "DOI" }[0] # contribs = publishers.map { |p| p&.entity&.abbreviation }.join '/' # idstr = "#{contribs}#{delim}#{id.project_number}" # idstr = id.project_number.to_s idstr = id.id.gsub(/:/, "-") # if id.part_number&.size&.positive? then idstr += "-#{id.part_number}" idstr.strip end |
#shortref(identifier, **opts) ⇒ String
260 261 262 263 264 265 266 267 268 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 260 def shortref(identifier, **opts) pubdate = dates.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_xml(builder = nil, **opts, &block) ⇒ String
272 273 274 275 276 277 278 279 280 |
# File 'lib/relaton_bib/bibliographic_item.rb', line 272 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 |