class IsoBibItem::IsoBibliographicItem

Bibliographic item.

Attributes

docidentifier[R]

@return [Array<IsoBibItem::IsoDocumentId>]

edition[R]

@return [String]

ics[R]

@return [Array<IsoBibItem::Ics>]

status[R]

@return [IsoBibItem::IsoDocumentStatus]

type[R]

@return [IsoBibItem::IsoDocumentType]

workgroup[R]

@return [IsoBibItem::IsoProjectGroup]

Public Class Methods

new(**args) click to toggle source

@param docid [Hash{project_number=>Integer, part_number=>Integer, prefix=>string},

IsoBibItem::IsoDocumentId]

@param titles [Array<Hash{title_intro=>String, title_main=>String,

title_part=>String, language=>String, script=>String}>]

@param edition [String] @param language [Array<String>] @param script [Arrra<String>] @param type [String] @param docstatus [Hash{status=>String, stage=>String, substage=>String}] @param workgroup [Hash{name=>String, abbreviation=>String, url=>String,

technical_committee=>Hash{name=>String, type=>String, number=>Integer}}]

@param ics [Array<Hash{field=>Integer, group=>Integer,

subgroup=>Integer}>]

@param dates [Array<Hash{type=>String, from=>String, to=>String}>] @param abstract [Array<Hash{content=>String, language=>String,

script=>String, type=>String}>]

@param contributors [Array<Hash{entity=>Hash{name=>String, url=>String,

abbreviation=>String}, roles=>Array<String>}>]

@param copyright [Hash{owner=>Hash{name=>String, abbreviation=>String,

url=>String}, form=>String, to=>String}]

@param link [Array<Hash{type=>String, content=>String}, IsoBibItem::TypedUri>] @param relations [Array<Hash{type=>String, identifier=>String}>]

Calls superclass method IsoBibItem::BibliographicItem::new
# File lib/iso_bib_item/iso_bibliographic_item.rb, line 167
def initialize(**args)
  super_args = args.select do |k|
    %i[
      id language script dates abstract contributors relations copyright link
    ].include? k
  end
  super(super_args)
  args[:docid] = [args[:docid]] unless args[:docid].is_a?(Array)
  @docidentifier = args[:docid].map do |t|
    t.is_a?(Hash) ? IsoDocumentId.new(t) : t
  end
  @edition = args[:edition]
  @title   = args[:titles].map do |t|
    t.is_a?(Hash) ? IsoLocalizedTitle.new(t) : t
  end
  @type   = args[:type]
  @status = if args[:docstatus].is_a?(Hash)
              IsoDocumentStatus.new(args[:docstatus])
            else args[:docstatus] end
  if args[:workgroup]
    @workgroup = if args[:workgroup].is_a?(Hash)
                   IsoProjectGroup.new(args[:workgroup])
                 else args[:workgroup] end
  end
  @ics = args[:ics].map { |i| i.is_a?(Hash) ? Ics.new(i) : i }
  @link = args[:link].map { |s| s.is_a?(Hash) ? TypedUri.new(s) : s }
  @id_attribute = true
end

Public Instance Methods

disable_id_attribute() click to toggle source
# File lib/iso_bib_item/iso_bibliographic_item.rb, line 196
def disable_id_attribute
  @id_attribute = false
end
title(lang: nil) click to toggle source

@param lang [String] language code Iso639 @return [IsoBibItem::IsoLocalizedTitle]

# File lib/iso_bib_item/iso_bibliographic_item.rb, line 227
def title(lang: nil)
  if lang
    @title.find { |t| t.language == lang }
  else
    @title
  end
end
to_all_parts() click to toggle source

remove title part components and abstract

# File lib/iso_bib_item/iso_bibliographic_item.rb, line 201
def to_all_parts
  me = DeepClone.clone(self)
  me.disable_id_attribute
  @relations << DocumentRelation.new(type: "partOf", identifier: nil, url: nil, bibitem: me)
  @title.each(&:remove_part)
  @abstract = []
  @docidentifier.each(&:remove_part)
  @docidentifier.each(&:all_parts)
  @all_parts = true
end
to_most_recent_reference() click to toggle source

convert ISO:yyyy reference to reference to most recent instance of reference, removing date-specific infomration: date of publication, abstracts. Make dated reference Instance relation of the redacated document

# File lib/iso_bib_item/iso_bibliographic_item.rb, line 216
def to_most_recent_reference
  me = DeepClone.clone(self)
  me.disable_id_attribute
  @relations << DocumentRelation.new(type: "instance", identifier: nil, url: nil, bibitem: me)
  @abstract = []
  @dates = []
  @docidentifier.each(&:remove_date)
end
to_xml(builder = nil, **opts, &block) click to toggle source

@return [String]

# File lib/iso_bib_item/iso_bibliographic_item.rb, line 242
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
url(type = :src) click to toggle source

@param type [Symbol] type of url, can be :src/:obp/:rss @return [String]

# File lib/iso_bib_item/iso_bibliographic_item.rb, line 237
def url(type = :src)
  @link.find { |s| s.type == type.to_s }.content.to_s
end

Private Instance Methods

makeid(id, attribute, delim = '') click to toggle source

@return [Array<IsoBibItem::ContributionInfo>] def publishers

@contributors.select do |c|
  c.role.select { |r| r.type == 'publisher' }.any?
end

end

# File lib/iso_bib_item/iso_bibliographic_item.rb, line 261
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(/:/, "-")
  idstr = "IEV" if id.project_number == "IEV"
  #if id.part_number&.size&.positive? then idstr += "-#{id.part_number}"
  idstr.strip
end
render_xml(builder, **opts) { |builder| ... } click to toggle source
# File lib/iso_bib_item/iso_bibliographic_item.rb, line 280
def render_xml(builder, **opts)
  builder.send(:bibitem, xml_attrs(type)) do
    builder.fetched fetched
    title.each { |t| t.to_xml builder }
    link.each { |s| s.to_xml builder }
    docidentifier.each { |i| i.to_xml builder }
    dates.each { |d| d.to_xml builder, opts }
    contributors.each do |c|
      builder.contributor do
        c.role.each { |r| r.to_xml builder }
        c.to_xml builder
      end
    end
    builder.edition edition if edition
    language.each { |l| builder.language l }
    script.each { |s| builder.script s }
    abstract.each { |a| builder.abstract { a.to_xml(builder) } }
    status.to_xml builder
    copyright.to_xml builder if copyright
    relations.each { |r| r.to_xml builder }
    workgroup.to_xml builder if workgroup
    if opts[:note]
      builder.note("ISO DATE: #{opts[:note]}", format: 'text/plain')
    end
    ics.each { |i| i.to_xml builder }
    builder.allparts 'true' if @all_parts
    yield(builder) if block_given?
  end
end
xml_attrs(type) click to toggle source
# File lib/iso_bib_item/iso_bibliographic_item.rb, line 273
def xml_attrs(type)
  attrs = { type: type }
  attr_id = makeid(nil, true)&.gsub(/ /, "")
  attrs[:id] = attr_id if attr_id
  attrs
end