Class: RelatonBib::BiblioNote

Inherits:
FormattedString show all
Defined in:
lib/relaton_bib/biblio_note.rb

Constant Summary

Constants inherited from FormattedString

FormattedString::FORMATS

Constants included from RelatonBib

VERSION

Instance Attribute Summary collapse

Attributes inherited from FormattedString

#format

Attributes inherited from LocalizedString

#content, #language, #script

Instance Method Summary collapse

Methods inherited from LocalizedString

#empty?, #to_s

Methods included from RelatonBib

parse_date

Constructor Details

#initialize(content:, type: nil, language: nil, script: nil, format: nil) ⇒ BiblioNote

Returns a new instance of BiblioNote.

Parameters:

  • content (String)
  • type (String, NilClass) (defaults to: nil)
  • language (String, NilClass) (defaults to: nil)

    language code Iso639

  • script (String, NilClass) (defaults to: nil)

    script code Iso15924

  • format (String, NilClass) (defaults to: nil)

    the content format



11
12
13
14
# File 'lib/relaton_bib/biblio_note.rb', line 11

def initialize(content:, type: nil, language: nil, script: nil, format: nil)
  @type = type
  super content: content, language: language, script: script, format: format
end

Instance Attribute Details

#typeString, NilClass (readonly)

Returns:

  • (String, NilClass)


4
5
6
# File 'lib/relaton_bib/biblio_note.rb', line 4

def type
  @type
end

Instance Method Details

#to_asciibib(prefix = "", count = 1) ⇒ String

Parameters:

  • prefix (String) (defaults to: "")
  • count (Integer) (defaults to: 1)

    number of notes

Returns:

  • (String)


36
37
38
39
40
41
42
# File 'lib/relaton_bib/biblio_note.rb', line 36

def to_asciibib(prefix = "", count = 1)
  pref = prefix.empty? ? prefix : prefix + "."
  out = count > 1 ? "#{pref}biblionote::\n" : ""
  out + "#{pref}biblionote.type:: #{type}\n" if type
  out += super "#{pref}biblionote"
  out
end

#to_hashHash

Returns:

  • (Hash)


24
25
26
27
28
29
30
31
# File 'lib/relaton_bib/biblio_note.rb', line 24

def to_hash
  hash = super
  return hash unless type

  hash = { "content" => hash } if hash.is_a? String
  hash["type"] = type
  hash
end

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


17
18
19
20
21
# File 'lib/relaton_bib/biblio_note.rb', line 17

def to_xml(builder)
  xml = builder.note { super }
  xml[:type] = type if type
  xml
end