Class: RelatonUn::UnBibliographicItem
- Inherits:
-
RelatonBib::BibliographicItem
- Object
- RelatonBib::BibliographicItem
- RelatonUn::UnBibliographicItem
- 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
- #distribution ⇒ String, NilClass readonly
- #job_number ⇒ String, NilClass readonly
- #session ⇒ RelatonUn::Session, NilClass readonly
- #submissionlanguage ⇒ Array<String> readonly
Instance Method Summary collapse
-
#ext_schema ⇒ String
Fetches flavor schema version.
-
#initialize(**args) ⇒ UnBibliographicItem
constructor
A new instance of UnBibliographicItem.
- #to_asciibib(prefix = "") ⇒ String
-
#to_hash(embedded: false) ⇒ Hash
Renders the document as a hash.
-
#to_xml(**opts) ⇒ String
XML.
Constructor Details
#initialize(**args) ⇒ UnBibliographicItem
Returns a new instance of UnBibliographicItem.
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
#distribution ⇒ String, NilClass (readonly)
12 13 14 |
# File 'lib/relaton_un/un_bibliographic_item.rb', line 12 def distribution @distribution end |
#job_number ⇒ String, NilClass (readonly)
12 13 14 |
# File 'lib/relaton_un/un_bibliographic_item.rb', line 12 def job_number @job_number end |
#session ⇒ RelatonUn::Session, NilClass (readonly)
9 10 11 |
# File 'lib/relaton_un/un_bibliographic_item.rb', line 9 def session @session end |
#submissionlanguage ⇒ Array<String> (readonly)
15 16 17 |
# File 'lib/relaton_un/un_bibliographic_item.rb', line 15 def submissionlanguage @submissionlanguage end |
Instance Method Details
#ext_schema ⇒ String
Fetches 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
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.
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.
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 |