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

#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



53
54
55
56
57
58
59
# File 'lib/relaton_bib/forename.rb', line 53

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



38
39
40
41
42
43
# File 'lib/relaton_bib/forename.rb', line 38

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

#to_sObject



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

def to_s
  content.nil? ? initial : super
end

#to_xml(builder) ⇒ Object

Render forename to XML

Parameters:

  • builder (Nokogiri::XML::Builder)

    XML builder



28
29
30
31
# File 'lib/relaton_bib/forename.rb', line 28

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