Class: RelatonIetf::IetfBibliographicItem

Inherits:
RelatonBib::BibliographicItem
  • Object
show all
Defined in:
lib/relaton_ietf/ietf_bibliographic_item.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ IetfBibliographicItem

Returns a new instance of IetfBibliographicItem.

Parameters:

  • keyword (Array<String>)
  • stream (String, nil)


11
12
13
14
# File 'lib/relaton_ietf/ietf_bibliographic_item.rb', line 11

def initialize(**args)
  @stream = args.delete(:stream)
  super
end

Instance Attribute Details

#keywordArray<String> (readonly)

Returns:

  • (Array<String>)


7
8
9
# File 'lib/relaton_ietf/ietf_bibliographic_item.rb', line 7

def keyword
  @keyword
end

#streamString? (readonly)

Returns:

  • (String, nil)


4
5
6
# File 'lib/relaton_ietf/ietf_bibliographic_item.rb', line 4

def stream
  @stream
end

Class Method Details

.from_hash(hash) ⇒ RelatonIetf::IetfBibliographicItem

Parameters:

  • hash (Hash)

Returns:



27
28
29
30
# File 'lib/relaton_ietf/ietf_bibliographic_item.rb', line 27

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

Instance Method Details

#ext_schemaString

Fetch flavor schema version

Returns:

  • (String)

    schema version



21
22
23
# File 'lib/relaton_ietf/ietf_bibliographic_item.rb', line 21

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

#has_ext?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/relaton_ietf/ietf_bibliographic_item.rb', line 70

def has_ext?
  super || stream
end

#to_bibxml(builder = nil, include_keywords: false) ⇒ String, Nokogiri::XML::Builder::NodeBuilder

Render BibXML (RFC)

Parameters:

  • builder (Nokogiri::XML::Builder, nil) (defaults to: nil)
  • include_keywords (Boolean) (defaults to: false)

    (false)

Returns:

  • (String, Nokogiri::XML::Builder::NodeBuilder)

    XML



82
83
84
# File 'lib/relaton_ietf/ietf_bibliographic_item.rb', line 82

def to_bibxml(builder = nil, include_keywords: false)
  Renderer::BibXML.new(self).render builder: builder, include_keywords: include_keywords
end

#to_hash(embedded: false) ⇒ Hash

Render hash

Returns:

  • (Hash)

    docunent hash representation



61
62
63
64
65
66
67
68
# File 'lib/relaton_ietf/ietf_bibliographic_item.rb', line 61

def to_hash(embedded: false)
  hash = super
  return hash unless stream

  hash["ext"] ||= {}
  hash["ext"]["stream"] = stream
  hash
end

#to_xml(**opts) ⇒ String

Returns XML.

Parameters:

  • opts (Hash)

Options Hash (**opts):

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

    XML builder

  • :bibdata (Boolean)
  • :date_format (Symbol, nil) — default: :short

    , :full

  • :lang (String, Symbol)

    language

Returns:

  • (String)

    XML



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

def to_xml(**opts) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/MethodLength
  opts[:date_format] ||= :short
  super(**opts) do |builder|
    if opts[:bibdata] && (doctype || editorialgroup || ics&.any? ||
      structuredidentifier&.presence? || stream)
      ext = builder.ext do |b|
        doctype&.to_xml b
        b.subdoctype subdoctype if subdoctype
        editorialgroup&.to_xml b
        ics.each { |i| i.to_xml b }
        b.stream stream if stream
        structuredidentifier&.to_xml b
      end
      ext["schema-version"] = ext_schema if !opts[:embedded] && respond_to?(:ext_schema)
    end
  end
end