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 FormattedString

#cleanup, #encode, #scan_xml

Methods inherited from LocalizedString

#cleanup, #empty?, #encode, #escp, #to_s

Methods included from RelatonBib

array, format_date, grammar_hash, parse_date, parse_yaml

Methods included from Config

#configuration, #configure

Constructor Details

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

Returns a new instance of BiblioNote.

Parameters:

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

    language code Iso639

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

    script code Iso15924

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

    the content format



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

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? (readonly)

Returns:

  • (String, nil)


31
32
33
# File 'lib/relaton_bib/biblio_note.rb', line 31

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)


63
64
65
66
67
68
69
70
# File 'lib/relaton_bib/biblio_note.rb', line 63

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

#to_hashHash

Returns:

  • (Hash)


51
52
53
54
55
56
57
58
# File 'lib/relaton_bib/biblio_note.rb', line 51

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)


44
45
46
47
48
# File 'lib/relaton_bib/biblio_note.rb', line 44

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