Sha256: c984c2489309cd1d1a8b6f2310d6bdb4720ed3b295d167ef855413668fe608c2

Contents?: true

Size: 1.46 KB

Versions: 24

Compression:

Stored size: 1.46 KB

Contents

module RelatonBib
  class Forename < LocalizedString
    # @return [String, nil]
    attr_accessor :initial

    #
    # Initialize Forename instance
    #
    # @param [String] content content of forename, can be empty
    # @param [Array<String>] language languages, `en`, `fr`, `de` etc.
    # @param [Array<String>] script scripts `Latn`, `Cyrl` etc.
    # @param [String, nil] initial initial of forename
    #
    def initialize(content: nil, language: [], script: [], initial: nil)
      @initial = initial
      super content, language, script
    end

    def to_s
      content.nil? ? initial : super
    end

    #
    # Render forename to XML
    #
    # @param [Nokogiri::XML::Builder] builder XML builder
    #
    def to_xml(builder)
      node = builder.forename { super }
      node[:initial] = initial if initial
    end

    #
    # Render forename to hash
    #
    # @return [Hash, String] forename hash or string representation
    #
    def to_hash
      ls = super
      hash = ls.is_a?(Hash) ? ls : { "content" => ls }
      hash["initial"] = initial if initial
      hash
    end

    #
    # Render forename to asciibib
    #
    # @param [String] pref prefix
    # @param [Integer] count size of array
    #
    # @return [String] asciibib string
    #
    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
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
relaton-bib-1.19.0 lib/relaton_bib/forename.rb
relaton-bib-1.18.5 lib/relaton_bib/forename.rb
relaton-bib-1.18.3 lib/relaton_bib/forename.rb
relaton-bib-1.18.2 lib/relaton_bib/forename.rb
relaton-bib-1.18.1 lib/relaton_bib/forename.rb
relaton-bib-1.18.0 lib/relaton_bib/forename.rb
relaton-bib-1.17.2 lib/relaton_bib/forename.rb
relaton-bib-1.17.1 lib/relaton_bib/forename.rb
relaton-bib-1.17.0 lib/relaton_bib/forename.rb
relaton-bib-1.16.5 lib/relaton_bib/forename.rb
relaton-bib-1.16.4 lib/relaton_bib/forename.rb
relaton-bib-1.16.3 lib/relaton_bib/forename.rb
relaton-bib-1.16.2 lib/relaton_bib/forename.rb
relaton-bib-1.16.1 lib/relaton_bib/forename.rb
relaton-bib-1.16.0 lib/relaton_bib/forename.rb
relaton-bib-1.14.14 lib/relaton_bib/forename.rb
relaton-bib-1.14.13 lib/relaton_bib/forename.rb
relaton-bib-1.14.12 lib/relaton_bib/forename.rb
relaton-bib-1.14.11 lib/relaton_bib/forename.rb
relaton-bib-1.14.10 lib/relaton_bib/forename.rb