Class: RelatonIetf::IetfBibliographicItem

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

Constant Summary collapse

DOCTYPES =
%w[rfc internet-draft].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ IetfBibliographicItem

Returns a new instance of IetfBibliographicItem.

Parameters:

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


14
15
16
17
18
19
20
# File 'lib/relaton_ietf/ietf_bibliographic_item.rb', line 14

def initialize(**args)
  if args[:doctype] && !DOCTYPES.include?(args[:doctype])
    Util.warn "WARNING: Invalid doctype: `#{args[:doctype]}`"
  end
  @stream = args.delete(:stream)
  super
end

Instance Attribute Details

#doctypeString? (readonly)

Returns:

  • (String, nil)


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

def doctype
  @doctype
end

#keywordArray<String> (readonly)

Returns:

  • (Array<String>)


9
10
11
# File 'lib/relaton_ietf/ietf_bibliographic_item.rb', line 9

def keyword
  @keyword
end

#streamString? (readonly)

Returns:

  • (String, nil)


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

def stream
  @stream
end

Class Method Details

.from_hash(hash) ⇒ RelatonIetf::IetfBibliographicItem

Parameters:

  • hash (Hash)

Returns:



33
34
35
36
# File 'lib/relaton_ietf/ietf_bibliographic_item.rb', line 33

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



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

def ext_schema
  @ext_schema ||= schema_versions["relaton-model-ietf"]
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



84
85
86
# File 'lib/relaton_ietf/ietf_bibliographic_item.rb', line 84

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



67
68
69
70
71
72
73
74
# File 'lib/relaton_ietf/ietf_bibliographic_item.rb', line 67

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



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/relaton_ietf/ietf_bibliographic_item.rb', line 44

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|
        b.doctype doctype if doctype
        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