Class: RelatonIsoBib::IsoBibliographicItem

Inherits:
RelatonBib::BibliographicItem
  • Object
show all
Defined in:
lib/relaton_iso_bib/iso_bibliographic_item.rb

Overview

Bibliographic item.

Constant Summary collapse

SUBDOCTYPES =
%w[specification method-of-test vocabulary code-of-practice].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ IsoBibliographicItem

Returns a new instance of IsoBibliographicItem.

Parameters:

  • edition (String)
  • docnumber (String, NilClass)
  • language (Array<String>)
  • script (Arrra<String>)
  • docstatus (RelatonBib::DocumentStatus, NilClass)
  • type (String, NilClass)
  • formattedref (RelatonBib::FormattedRef, NilClass)
  • version (RelatonBib::BibliographicItem::Version, NilClass)
  • biblionote (Array<RelatonBib::BiblioNote>)
  • series (Array<RelatonBib::Series>)
  • medium (RelatonBib::Medium, NilClas)
  • place (Array<String>)
  • extent (Array<Relaton::BibItemLocality>)
  • accesslocation (Array<String>)
  • classification (RelatonBib::Classification, NilClass)
  • validity (RelatonBib:Validity, NilClass)
  • docid (Array<RelatonBib::DocumentIdentifier>)
  • doctype (RelatonIsoBib::DocumentType)
  • subdoctype (String, nil)
  • horizontal (Boolean, nil)
  • structuredidentifier (RelatonIsoBib::StructuredIdentifier)
  • stagename (String, NilClass)
  • title (Array<Hash, RelatonBib::TypedTitleString>, RelatonBib::TypedTitleStringCollection)
  • editorialgroup (Hash, RelatonIsoBib::EditorialGroup)
  • ics (Array<Hash>)
  • date (Array<Hash>)
  • abstract (Array<Hash>)
  • contributor (Array<Hash>)
  • copyright (Hash)
  • link (Array<Hash, RelatonBib::TypedUri>)
  • relation (Array<Hash>)
  • workgrpup (Hash)

    a customizable set of options

  • technical_committee (Hash)

    a customizable set of options

  • entity (Hash)

    a customizable set of options

  • owner (Hash)

    a customizable set of options

Raises:

  • (ArgumentError)


119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 119

def initialize(**args)
  args[:type] ||= "standard"
  arg_names = %i[
    id title docnumber language script docstatus date abstract contributor
    edition version relation biblionote series medium place copyright link
    fetched docid formattedref extent accesslocation classification validity
    editorialgroup doctype keyword type
  ]
  super_args = args.select { |k| arg_names.include? k }
  super(**super_args)

  if args[:editorialgroup]
    @editorialgroup = if args[:editorialgroup].is_a?(Hash)
                        EditorialGroup.new(**args[:editorialgroup])
                      else args[:editorialgroup]
                      end
  end

  if args[:subdoctype] && !self.class::SUBDOCTYPES.include?(args[:subdoctype])
    Util.warn "Invald subdoctype `#{args[:subdoctype]}`. Allowed values are: #{self.class::SUBDOCTYPES.join(', ')}"
  end
  @subdoctype = args[:subdoctype]
  @structuredidentifier = args[:structuredidentifier]
  @horizontal = args[:horizontal]
  @ics = args.fetch(:ics, []).map { |i| i.is_a?(Hash) ? Ics.new(**i) : i }
  @stagename = args[:stagename]
  @id_attribute = true
end

Instance Attribute Details

#editorialgroupRelatonIsoBib::EditorialGroup (readonly)



36
37
38
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 36

def editorialgroup
  @editorialgroup
end

#horizontalBoolean? (readonly)

Returns:

  • (Boolean, nil)


33
34
35
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 33

def horizontal
  @horizontal
end

#icsArray<RelatonIsoBib::Ics> (readonly)



39
40
41
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 39

def ics
  @ics
end

#stagenameString? (readonly)

Returns:

  • (String, nil)


27
28
29
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 27

def stagename
  @stagename
end

#structuredidentifierRelatonIsoBib::StructuredIdentifier (readonly)



24
25
26
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 24

def structuredidentifier
  @structuredidentifier
end

#subdoctypeRelatonIsoBib::DocumentType (readonly)



# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 29

Instance Method Details

#ext_schemaString

Fetch the flavour schema version

Returns:

  • (String)

    flavour schema version



153
154
155
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 153

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

#to_asciibib(prefix = "") ⇒ String

Parameters:

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

Returns:

  • (String)


205
206
207
208
209
210
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 205

def to_asciibib(prefix = "")
  pref = prefix.empty? ? prefix : "#{prefix}."
  out = super
  out += "#{pref}stagename:: #{stagename}\n" if stagename
  out
end

#to_hash(embedded: false) ⇒ Hash

Render the document as HASH

Parameters:

  • embedded (Boolean) (defaults to: false)

    true if the bibitem is embedded in another bibitem

Returns:

  • (Hash)

    the document as HAS



196
197
198
199
200
201
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 196

def to_hash(embedded: false)
  hash = super
  hash["horizontal"] = horizontal unless horizontal.nil?
  hash["stagename"] = stagename if stagename
  hash
end

#to_xml(**opts) ⇒ String

Render the document as an XML string.

Parameters:

  • opts (Hash)

    options

Options Hash (**opts):

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

    XML builder

  • :bibdata (Boolean)

    if true, bibdata element is created

  • :embedded (Boolean)

    if true the document is embedded in another document

  • :lang (String)

    language

Returns:

  • (String)

    XML



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 168

def to_xml(**opts)
  super(**opts) do |b|
    if block_given? then yield b
    elsif opts[:bibdata] && has_ext_attrs?
      ext = b.ext do
        doctype.to_xml b if doctype
        b.subdoctype subdoctype if subdoctype
        b.horizontal horizontal unless horizontal.nil?
        editorialgroup&.to_xml b
        ics.each { |i| i.to_xml b }
        structuredidentifier&.to_xml b
        b.stagename stagename if stagename
      end
      ext["schema-version"] = ext_schema unless opts[:embedded]
    end
  end
end