Class: RelatonNist::NistBibliographicItem

Inherits:
RelatonBib::BibliographicItem
  • Object
show all
Defined in:
lib/relaton_nist/nist_bibliographic_item.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ NistBibliographicItem

Returns a new instance of NistBibliographicItem.

Parameters:

  • id (String, nil)
  • title (Array<RelatonBib::TypedTitleString>)
  • formattedref (RelatonBib::FormattedRef, nil)
  • type (String, nil)
  • docid (Array<RelatonBib::DocumentIdentifier>)
  • docnumber (String, nil)
  • language (Arra<String>)
  • script (Array<String>)
  • docstatus (RelatonNist::DocumentStatus, nil)
  • edition (String, nil)
  • version (RelatonBib::BibliographicItem::Version, nil)
  • biblionote (Array<RelatonBib::FormattedStrong>)
  • series (Array<RelatonBib::Series>)
  • medium (RelatonBib::Medium, NilClas)
  • place (Array<String>)
  • extent (Array<Relaton::BibItemLocality>)
  • accesslocation (Array<String>)
  • classification (RelatonBib::Classification, nil)
  • validity (RelatonBib:Validity, nil)
  • fetched (Date, nil)

    default nil

  • doctype (RelatonBib::DocumentType, nil)
  • keyword (Array<RelatonBib::Keyword>)
  • commentperiod (RelatonNist::CommentPeriod, nil)
  • date (Array<Hash>)
  • contributor (Array<Hash>)
  • abstract (Array<Hash>)
  • relation (Array<Hash, RelatonNist::DocumentRelation>)


55
56
57
58
59
60
61
# File 'lib/relaton_nist/nist_bibliographic_item.rb', line 55

def initialize(**args)
  # @doctype = args.delete(:doctype) || "standard"
  # args[:doctype] ||= "standard"
  # @keyword = args.delete(:keyword) || []
  @commentperiod = args.delete :commentperiod
  super
end

Instance Attribute Details

#commentperiodRelatonNist::CommentPeriod? (readonly)

Returns:



7
8
9
# File 'lib/relaton_nist/nist_bibliographic_item.rb', line 7

def commentperiod
  @commentperiod
end

Class Method Details

.from_hash(hash) ⇒ RelatonNist::GbBibliographicItem

Parameters:

  • hash (Hash)

Returns:

  • (RelatonNist::GbBibliographicItem)


74
75
76
77
# File 'lib/relaton_nist/nist_bibliographic_item.rb', line 74

def self.from_hash(hash)
  item_hash = RelatonNist::HashConverter.hash_to_bib(hash)
  new(**item_hash)
end

Instance Method Details

#ext_schemaString

Fetch flavor schema version

Returns:

  • (String)

    schema version



68
69
70
# File 'lib/relaton_nist/nist_bibliographic_item.rb', line 68

def ext_schema
  @ext_schema ||= schema_versions["relaton-model-nist"]
end

#ref_attrsHash<Symbol=>String>

Create BibXML reference attributes

Returns:

  • (Hash<Symbol=>String>)

    attributes



118
119
120
121
122
# File 'lib/relaton_nist/nist_bibliographic_item.rb', line 118

def ref_attrs
  docidentifier.detect(&:primary)&.tap do |di|
    return { anchor: di.id.gsub(" ", ".").squeeze(".") }
  end
end

#to_asciibib(prefix = "") ⇒ String

Parameters:

  • prefix (String) (defaults to: "")

Returns:

  • (String)


107
108
109
110
111
# File 'lib/relaton_nist/nist_bibliographic_item.rb', line 107

def to_asciibib(prefix = "")
  out = super
  out += commentperiod.to_asciibib prefix if commentperiod
  out
end

#to_hash(embedded: false) ⇒ Hash

Parameters:

  • embedded (Boolean) (defaults to: false)

    embedded in another document

Returns:

  • (Hash)


98
99
100
101
102
103
# File 'lib/relaton_nist/nist_bibliographic_item.rb', line 98

def to_hash(embedded: false)
  hash = super
  # hash["keyword"] = single_element_array(keyword) if keyword&.any?
  hash["commentperiod"] = commentperiod.to_hash if commentperiod
  hash
end

#to_xml(**opts) ⇒ String

Returns XML.

Parameters:

  • opts (Hash)

Options Hash (**opts):

  • :builder (Nokogiri::XML::Builder)

    XML builder

  • :bibdata (Boolean)
  • :lang (String)

    language

Returns:

  • (String)

    XML



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/relaton_nist/nist_bibliographic_item.rb', line 84

def to_xml(**opts)
  super date_format: :short, **opts do |b|
    if opts[:bibdata]
      ext = b.ext do
        doctype&.to_xml b
        commentperiod&.to_xml b
      end
      ext["schema-version"] = ext_schema unless opts[:embedded]
    end
  end
end