Class: RelatonUn::UnBibliographicItem

Inherits:
RelatonBib::BibliographicItem
  • Object
show all
Includes:
RelatonBib
Defined in:
lib/relaton_un/un_bibliographic_item.rb

Constant Summary collapse

DISTRIBUTIONS =
{ "GEN" => "general", "LTD" => "limited",
"DER" => "restricted", "PRO" => "provisional" }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ UnBibliographicItem

Returns a new instance of UnBibliographicItem.

Parameters:

  • session (RelatonUn::Session, NilClass)
  • distribution (String, nil)
  • job_number (String, nil)


20
21
22
23
24
25
26
27
28
29
# File 'lib/relaton_un/un_bibliographic_item.rb', line 20

def initialize(**args)
  if args[:distribution] && !DISTRIBUTIONS.has_value?(args[:distribution])
    Util.warn "Invalid distribution: `#{args[:distribution]}`"
  end
  @submissionlanguage = args.delete :submissionlanguage
  @distribution = args.delete :distribution
  @session = args.delete :session
  @job_number = args.delete :job_number
  super(**args)
end

Instance Attribute Details

#distributionString, NilClass (readonly)

Returns:

  • (String, NilClass)


12
13
14
# File 'lib/relaton_un/un_bibliographic_item.rb', line 12

def distribution
  @distribution
end

#job_numberString, NilClass (readonly)

Returns:

  • (String, NilClass)


12
13
14
# File 'lib/relaton_un/un_bibliographic_item.rb', line 12

def job_number
  @job_number
end

#sessionRelatonUn::Session, NilClass (readonly)

Returns:



9
10
11
# File 'lib/relaton_un/un_bibliographic_item.rb', line 9

def session
  @session
end

#submissionlanguageArray<String> (readonly)

Returns:

  • (Array<String>)


15
16
17
# File 'lib/relaton_un/un_bibliographic_item.rb', line 15

def submissionlanguage
  @submissionlanguage
end

Instance Method Details

#ext_schemaString

Fetches flavor schema version.

Returns:

  • (String)

    flavor schema version



36
37
38
# File 'lib/relaton_un/un_bibliographic_item.rb', line 36

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

#to_asciibib(prefix = "") ⇒ String

Parameters:

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

Returns:

  • (String)


80
81
82
83
84
85
86
87
88
89
90
# File 'lib/relaton_un/un_bibliographic_item.rb', line 80

def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize
  pref = prefix.empty? ? prefix : "#{prefix}."
  out = super
  submissionlanguage.each do |sl|
    out += "#{pref}submissionlanguage:: #{sl}\n"
  end
  out += "#{pref}distribution:: #{distribution}\n" if distribution
  out += session.to_asciibib prefix if session
  out += "#{pref}job_number:: #{job_number}\n" if job_number
  out
end

#to_hash(embedded: false) ⇒ Hash

Renders the document as a hash.

Parameters:

  • embedded (Boolean) (defaults to: false)

    embedded in another document

Returns:

  • (Hash)


67
68
69
70
71
72
73
74
75
76
# File 'lib/relaton_un/un_bibliographic_item.rb', line 67

def to_hash(embedded: false) # rubocop:disable Metrics/AbcSize
  hash = super
  if submissionlanguage&.any?
    hash["submissionlanguage"] = single_element_array submissionlanguage
  end
  hash["distribution"] = distribution if distribution
  hash["session"] = session.to_hash if session
  hash["job_number"] = job_number if job_number
  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



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/relaton_un/un_bibliographic_item.rb', line 45

def to_xml(**opts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
  super(**opts) do |b|
    ext = b.ext do
      doctype&.to_xml b
      submissionlanguage&.each { |sl| b.submissionlanguage sl }
      editorialgroup&.to_xml b
      ics&.each { |i| i.to_xml b }
      b.distribution distribution if distribution
      session&.to_xml b
      b.job_number job_number if job_number
    end
    ext["schema-version"] = ext_schema unless opts[:embedded]
  end
end