Class: RelatonBib::Forename

Inherits:
LocalizedString show all
Defined in:
lib/relaton_bib/forename.rb

Constant Summary

Constants included from RelatonBib

VERSION

Instance Attribute Summary collapse

Attributes inherited from LocalizedString

#content, #language, #script

Instance Method Summary collapse

Methods inherited from LocalizedString

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

Methods included from RelatonBib

array, format_date, grammar_hash, parse_date, parse_yaml

Methods included from Config

#configuration, #configure

Constructor Details

#initialize(content: nil, language: [], script: [], initial: nil) ⇒ Forename

Initialize Forename instance

Parameters:

  • content (String) (defaults to: nil)

    content of forename, can be empty

  • language (Array<String>) (defaults to: [])

    languages, ‘en`, `fr`, `de` etc.

  • script (Array<String>) (defaults to: [])

    scripts ‘Latn`, `Cyrl` etc.

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

    initial of forename



14
15
16
17
# File 'lib/relaton_bib/forename.rb', line 14

def initialize(content: nil, language: [], script: [], initial: nil)
  @initial = initial
  super content, language, script
end

Instance Attribute Details

#initialString?

Returns:

  • (String, nil)


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

def initial
  @initial
end

Instance Method Details

#==(other) ⇒ Object



19
20
21
# File 'lib/relaton_bib/forename.rb', line 19

def ==(other)
  super && initial == other.initial
end

#to_asciibib(pref, count = 1) ⇒ String

Render forename to asciibib

Parameters:

  • pref (String)

    prefix

  • count (Integer) (defaults to: 1)

    size of array

Returns:

  • (String)

    asciibib string



57
58
59
60
61
62
63
# File 'lib/relaton_bib/forename.rb', line 57

def to_asciibib(pref, count = 1)
  prf = pref.empty? ? pref : "#{pref}."
  prf += "forename"
  out = super prf, count
  out += "#{prf}.initial:: #{initial}\n" if initial
  out
end

#to_hashHash, String

Render forename to hash

Returns:

  • (Hash, String)

    forename hash or string representation



42
43
44
45
46
47
# File 'lib/relaton_bib/forename.rb', line 42

def to_hash
  ls = super
  hash = ls.is_a?(Hash) ? ls : { "content" => ls }
  hash["initial"] = initial if initial
  hash
end

#to_sObject



23
24
25
# File 'lib/relaton_bib/forename.rb', line 23

def to_s
  content.nil? ? initial : super
end

#to_xml(builder) ⇒ Object

Render forename to XML

Parameters:

  • builder (Nokogiri::XML::Builder)

    XML builder



32
33
34
35
# File 'lib/relaton_bib/forename.rb', line 32

def to_xml(builder)
  node = builder.forename { super }
  node[:initial] = initial if initial
end