Class: RelatonEtsi::BibliographicItem

Inherits:
RelatonBib::BibliographicItem
  • Object
show all
Defined in:
lib/relaton_etsi/bibliographic_item.rb

Constant Summary collapse

MAKER =
%w[Current Superseded].freeze
CUSTOM_COLLECTION =
["HSs cited in OJ", "HSs not yet cited in OJ", "HSs RED cited in OJ", "HSs EMC cited in OJ"].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ BibliographicItem

Constructor.

Parameters:

  • doctype (RelatonEtsi::DocumentType)

    document type

  • marker (String)

    current or superseded

  • frequency (Array<String>)

    list of frequencies

  • mandate (Array<String>)

    list of mandates

  • custom_collection (String, nil)

    custom collection



17
18
19
20
21
22
23
# File 'lib/relaton_etsi/bibliographic_item.rb', line 17

def initialize(**args)
  @marker = args.delete(:marker)
  @frequency = args.delete(:frequency) || []
  @mandate = args.delete(:mandate) || []
  @custom_collection = args.delete(:custom_collection)
  super(**args)
end

Instance Attribute Details

#custom_collectionObject (readonly)

Returns the value of attribute custom_collection.



6
7
8
# File 'lib/relaton_etsi/bibliographic_item.rb', line 6

def custom_collection
  @custom_collection
end

#frequencyObject (readonly)

Returns the value of attribute frequency.



6
7
8
# File 'lib/relaton_etsi/bibliographic_item.rb', line 6

def frequency
  @frequency
end

#mandateObject (readonly)

Returns the value of attribute mandate.



6
7
8
# File 'lib/relaton_etsi/bibliographic_item.rb', line 6

def mandate
  @mandate
end

#markerObject (readonly)

Returns the value of attribute marker.



6
7
8
# File 'lib/relaton_etsi/bibliographic_item.rb', line 6

def marker
  @marker
end

Class Method Details

.from_hash(hash) ⇒ Object



25
26
27
28
# File 'lib/relaton_etsi/bibliographic_item.rb', line 25

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

Instance Method Details

#ext_schemaString

Fetch flavour schema version

Returns:

  • (String)

    flavour schema versio



35
36
37
# File 'lib/relaton_etsi/bibliographic_item.rb', line 35

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

#to_asciibib(prefix = "") ⇒ Object

rubocop:disable Metrics/AbcSize



65
66
67
68
69
70
71
72
73
# File 'lib/relaton_etsi/bibliographic_item.rb', line 65

def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize
  out = super
  pref = prefix.empty? ? prefix : "#{prefix}."
  out += "#{pref}marker:: #{marker}\n" if marker
  out += frequency.map { |f| "#{pref}frequency:: #{f}\n" }.join
  out += mandate.map { |m| "#{pref}mandate:: #{m}\n" }.join
  out += "#{pref}custom_collection:: #{custom_collection}" if custom_collection
  out
end

#to_hashObject

rubocop:disable Metrics/AbcSize



56
57
58
59
60
61
62
63
# File 'lib/relaton_etsi/bibliographic_item.rb', line 56

def to_hash # rubocop:disable Metrics/AbcSize
  hash = super
  hash["marker"] = marker if marker
  hash["frequency"] = frequency if frequency.any?
  hash["mandate"] = mandate if mandate.any?
  hash["custom_collection"] = custom_collection if custom_collection
  hash
end

#to_xml(**opts) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/relaton_etsi/bibliographic_item.rb', line 39

def to_xml(**opts) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
  super(**opts) do |b|
    if opts[:bibdata] && (doctype || subdoctype || editorialgroup || marker || frequency.any? || mandate.any? || custom_collection)
      ext = b.ext do
        doctype&.to_xml b
        b.subdoctype subdoctype if subdoctype
        editorialgroup&.to_xml b
        b.marker marker if marker
        frequency.each { |f| b.frequency f }
        mandate.each { |m| b.mandate m }
        b.send("custom-collection", custom_collection) if custom_collection
      end
      ext["schema-version"] = ext_schema unless opts[:embedded]
    end
  end
end