class IsoBibItem::BibliographicItem
Bibliographic item
Attributes
@return [Array<IsoBibItem::ContributionInfo>]
@return [IsoBibItem::CopyrightAssociation]
@return [Array<IsoBibItem::BibliographicDate>]
@return [Array<IsoBibItem::DocumentIdentifier>]
@return [String]
@return [Date]
@return [IsoBibItem::FormattedString]
@return [String]
@return [Array<String>] language Iso639 code
@return [Array<IsoBibItem::TypedUri>]
@return [Array<IsoBibItem::FormattedString>]
@return [IsoBibItem::DocRelationCollection]
@return [Array<String>] script Iso15924 code
@return [Array<IsoBibItem::Series>]
@return [IsoBibItem::DocumentStatus]
@return [Array<IsoBibItem::FormattedString>]
@return [IsoBibItem::BibItemType]
Public Class Methods
@param id [String] @param title [Array<IsoBibItem::FormattedString>] @param docid [Array<IsoBibItem::DocumentIdentifier] @param language [Arra<String>] @param script [Array<String>] @param docstatus [IsoBibItem::DocumentStatus, NilClass] @param dates [Array<Hash{type=>String, from=>String, to=>String}>] @param contributors [Array<Hash{entity=>Hash{name=>String, url=>String,
abbreviation=>String}, roles=>Array<String>}>]
@param abstract [Array<Hash{content=>String, language=>String,
script=>String, type=>String}>]
@param relations [Array<Hash{type=>String, identifier=>String}>] @param series [Array<IsoBibItem::Series>] @param fetched [Date] default today
# 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
Public Instance Methods
@param lang [String] language code Iso639 @return [IsoBibItem::FormattedString, Array
<IsoBibItem::FormattedString>]
# File lib/iso_bib_item/bibliographic_item.rb, line 206 def abstract(lang: nil) if lang @abstract.find { |a| a.language.include? lang } else @abstract end end
# 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
@return [String]
# 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
@return [String]
# 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