class IsoBibItem::BibliographicItem

Bibliographic item

Attributes

contributors[R]

@return [Array<IsoBibItem::ContributionInfo>]

dates[R]

@return [Array<IsoBibItem::BibliographicDate>]

docidentifier[R]

@return [Array<IsoBibItem::DocumentIdentifier>]

edition[R]

@return [String]

fetched[R]

@return [Date]

formatted_ref[R]

@return [IsoBibItem::FormattedString]

id[R]

@return [String]

language[R]

@return [Array<String>] language Iso639 code

notes[R]

@return [Array<IsoBibItem::FormattedString>]

relations[R]

@return [IsoBibItem::DocRelationCollection]

script[R]

@return [Array<String>] script Iso15924 code

series[R]

@return [Array<IsoBibItem::Series>]

status[R]

@return [IsoBibItem::DocumentStatus]

title[R]

@return [Array<IsoBibItem::FormattedString>]

type[R]

@return [IsoBibItem::BibItemType]

Public Class Methods

new(**args) click to toggle source

@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

abstract(lang: nil) click to toggle source

@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
makeid(id, attribute, delim = '') click to toggle source
# 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) click to toggle source

@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
to_xml() click to toggle source

@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