class RelatonGb::GbBibliographicItem

GB bibliographic item class.

Attributes

ccs[R]

@return [Array<Cnccs::Ccs>]

committee[R]

@return [RelatonGb::GbTechnicalCommittee]

gbplannumber[R]

@return [String]

gbtype[R]

@return [RelatonGb::GbStandardType]

plan_number[R]

@return [String]

topic[R]

@return [String]

type[R]

@return [String]

Public Class Methods

from_hash(hash) click to toggle source

@param hash [Hash] @return [RelatonGb::GbBibliographicItem]

# File lib/relaton_gb/gb_bibliographic_item.rb, line 43
def self.from_hash(hash)
  item_hash = ::RelatonGb::HashConverter.hash_to_bib(hash)
  new **item_hash
end
new(**args) click to toggle source
Calls superclass method
# File lib/relaton_gb/gb_bibliographic_item.rb, line 32
def initialize(**args)
  super
  @committee = GbTechnicalCommittee.new **args[:committee] if args[:committee]
  @ccs = args[:ccs].map { |c| c.is_a?(Cnccs::Ccs) ? c : Cnccs.fetch(c) }
  @gbtype = GbStandardType.new **args[:gbtype]
  @gbplannumber = args[:gbplannumber] ||
    structuredidentifier&.project_number
end

Public Instance Methods

inspect() click to toggle source

@return [String]

# File lib/relaton_gb/gb_bibliographic_item.rb, line 90
def inspect
  "<#{self.class}:#{format('%<id>#.14x', id: object_id << 1)}>"
end
makeid(id, attribute, _delim = "") click to toggle source
# File lib/relaton_gb/gb_bibliographic_item.rb, line 99
def makeid(id, attribute, _delim = "")
  return nil if attribute && !@id_attribute

  id ||= @docidentifier.reject { |i| i.type == "DOI" }[0]
  idstr = id.id
  idstr.gsub(/\s/, "").strip
end
to_asciibib(prefix = "") click to toggle source

@param prefix [String] @return [String]

Calls superclass method
# File lib/relaton_gb/gb_bibliographic_item.rb, line 83
def to_asciibib(prefix = "")
  out = super
  ccs.each { |c| out += c.to_aciibib prefix, ccs.size }
  out
end
to_hash() click to toggle source

@return [Hash]

Calls superclass method
# File lib/relaton_gb/gb_bibliographic_item.rb, line 72
def to_hash # rubocop:disable Metrics/AbcSize
  hash = super
  hash["ccs"] = single_element_array(ccs) if ccs&.any?
  hash["committee"] = committee.to_hash if committee
  hash["plannumber"] = gbplannumber if gbplannumber
  hash["gbtype"] = gbtype.to_hash
  hash
end
to_s() click to toggle source

@return [String]

# File lib/relaton_gb/gb_bibliographic_item.rb, line 95
def to_s
  inspect
end
to_xml(**opts) click to toggle source

@param opts [Hash] @option opts [Nokogiri::XML::Builder] :builder XML builder @option opts [Boolean] :bibdata @option opts [Symbol, NilClass] :date_format (:short), :full @option opts [String, Symbol] :lang language @return [String] XML

Calls superclass method
# File lib/relaton_gb/gb_bibliographic_item.rb, line 54
def to_xml(**opts)
  super(**opts) do |b|
    if opts[:bibdata] && has_ext_attrs?
      b.ext do
        b.doctype doctype if doctype
        b.horizontal horizontal unless horizontal.nil?
        # b.docsubtype docsubtype if docsubtype
        committee&.to_xml b
        ics.each { |i| i.to_xml b }
        structuredidentifier&.to_xml b
        b.stagename stagename if stagename
        render_gbxml(b)
      end
    end
  end
end

Private Instance Methods

has_ext_attrs?() click to toggle source

@return [Boolean]

Calls superclass method
# File lib/relaton_gb/gb_bibliographic_item.rb, line 126
def has_ext_attrs?
  super || committee || docsubtype
end
render_gbxml(builder) click to toggle source

@param builder [Nokogiri::XML::Builder]

# File lib/relaton_gb/gb_bibliographic_item.rb, line 110
def render_gbxml(builder)
  gbtype.to_xml builder

  ccs&.each do |c|
    builder.ccs do
      builder.code c.code
      builder.text_ c.description
    end
  end

  builder.plannumber gbplannumber if gbplannumber
end