Class: IsoBibItem::BibliographicItem
- Inherits:
-
Object
- Object
- IsoBibItem::BibliographicItem
- Defined in:
- lib/iso_bib_item/bibliographic_item.rb
Overview
Bibliographic item
Direct Known Subclasses
Instance Attribute Summary collapse
- #abstract(lang: nil) ⇒ IsoBibItem::FormattedString+ readonly
- #contributors ⇒ Array<IsoBibItem::ContributionInfo> readonly
- #copyright ⇒ IsoBibItem::CopyrightAssociation readonly
- #dates ⇒ Array<IsoBibItem::BibliographicDate> readonly
- #docidentifier ⇒ Array<IsoBibItem::DocumentIdentifier> readonly
- #edition ⇒ String readonly
- #fetched ⇒ Date readonly
- #formatted_ref ⇒ IsoBibItem::FormattedString readonly
- #id ⇒ String readonly
-
#language ⇒ Array<String>
readonly
Language Iso639 code.
- #link ⇒ Array<IsoBibItem::TypedUri> readonly
- #notes ⇒ Array<IsoBibItem::FormattedString> readonly
- #relations ⇒ IsoBibItem::DocRelationCollection readonly
-
#script ⇒ Array<String>
readonly
Script Iso15924 code.
- #series ⇒ Array<IsoBibItem::Series> readonly
- #status ⇒ IsoBibItem::DocumentStatus readonly
- #title ⇒ Array<IsoBibItem::FormattedString> readonly
- #type ⇒ IsoBibItem::BibItemType readonly
Instance Method Summary collapse
-
#initialize(**args) ⇒ BibliographicItem
constructor
A new instance of BibliographicItem.
- #makeid(id, attribute, delim = '') ⇒ Object
- #shortref(identifier, **opts) ⇒ String
- #to_xml ⇒ String
Constructor Details
#initialize(**args) ⇒ BibliographicItem
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 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 170 def initialize(**args) @id = args[:id] @title = (args[:titles] || []).map { |t| FormattedString.new t } @docidentifier = args[:docid] || [] @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 @notes = [] @language = args[:language] @script = args[:script] @status = args[:docstatus] @abstract = (args[:abstract] || []).map do |a| a.is_a?(Hash) ? FormattedString.new(a) : a end @relations = DocRelationCollection.new(args[:relations] || []) if args[:copyright] @copyright = if args[:copyright].is_a?(Hash) CopyrightAssociation.new args[:copyright] else args[:copyright] end end @link = args[:link].map { |s| s.is_a?(Hash) ? TypedUri.new(s) : s } @series = args[:series] @fetched = args.fetch :fetched, Date.today end |
Instance Attribute Details
#abstract(lang: nil) ⇒ IsoBibItem::FormattedString+ (readonly)
|
# File 'lib/iso_bib_item/bibliographic_item.rb', line 135
|
#contributors ⇒ Array<IsoBibItem::ContributionInfo> (readonly)
118 119 120 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 118 def contributors @contributors end |
#copyright ⇒ IsoBibItem::CopyrightAssociation (readonly)
142 143 144 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 142 def copyright @copyright end |
#dates ⇒ Array<IsoBibItem::BibliographicDate> (readonly)
115 116 117 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 115 def dates @dates end |
#docidentifier ⇒ Array<IsoBibItem::DocumentIdentifier> (readonly)
112 113 114 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 112 def docidentifier @docidentifier end |
#edition ⇒ String (readonly)
121 122 123 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 121 def edition @edition end |
#fetched ⇒ Date (readonly)
151 152 153 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 151 def fetched @fetched end |
#formatted_ref ⇒ IsoBibItem::FormattedString (readonly)
133 134 135 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 133 def formatted_ref @formatted_ref end |
#id ⇒ String (readonly)
100 101 102 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 100 def id @id end |
#language ⇒ Array<String> (readonly)
Returns language Iso639 code.
127 128 129 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 127 def language @language end |
#link ⇒ Array<IsoBibItem::TypedUri> (readonly)
106 107 108 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 106 def link @link end |
#notes ⇒ Array<IsoBibItem::FormattedString> (readonly)
124 125 126 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 124 def notes @notes end |
#relations ⇒ IsoBibItem::DocRelationCollection (readonly)
145 146 147 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 145 def relations @relations end |
#script ⇒ Array<String> (readonly)
Returns script Iso15924 code.
130 131 132 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 130 def script @script end |
#series ⇒ Array<IsoBibItem::Series> (readonly)
148 149 150 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 148 def series @series end |
#status ⇒ IsoBibItem::DocumentStatus (readonly)
139 140 141 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 139 def status @status end |
#title ⇒ Array<IsoBibItem::FormattedString> (readonly)
103 104 105 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 103 def title @title end |
#type ⇒ IsoBibItem::BibItemType (readonly)
109 110 111 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 109 def type @type end |
Instance Method Details
#makeid(id, attribute, delim = '') ⇒ Object
214 215 216 217 218 219 220 221 222 223 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 214 def makeid(id, attribute, delim = '') return nil if attribute && !@id_attribute id = @docidentifier.reject { |i| i.type == "DOI" }[0] 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(/:/, "-") #if id.part_number&.size&.positive? then idstr += "-#{id.part_number}" idstr.strip end |
#shortref(identifier, **opts) ⇒ String
226 227 228 229 230 231 232 233 234 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 226 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 ⇒ String
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/iso_bib_item/bibliographic_item.rb', line 239 def to_xml Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml| xml.bibitem(id: id) do xml.fetched fetched title.each { |t| xml.title { t.to_xml xml } } link.each { |s| s.to_xml xml } docidentifier.each { |di| di.to_xml xml } dates.each { |d| d.to_xml xml, full_date: true } contributors.each do |c| xml.contributor do c.role.each { |r| r.to_xml xml } c.to_xml xml end end language.each { |l| xml.language l } script.each { |s| xml.script s } abstract.each { |a| xml.abstract { a.to_xml(xml) } } status.to_xml xml if status copyright.to_xml xml if copyright relations.each { |r| r.to_xml xml } series.each { |s| s.to_xml xml } if series end end.doc.root.to_xml end |