Sha256: a224601fc07964fcaed06e52db7a347f59090461873cf217ef7ca557045db8e4

Contents?: true

Size: 1.1 KB

Versions: 5

Compression:

Stored size: 1.1 KB

Contents

module RelatonBib
  class TypedTitleString
    TITLE_TYPES = %w[alternative original unofficial subtitle main].freeze

    # @return [String]
    attr_reader :type

    # @return [RelatonBib::FormattedString]
    attr_reader :title

    # @param type [String]
    # @param title [RelatonBib::FormattedString, Hash]
    # @param content [String]
    # @param language [String]
    # @param script [String]
    def initialize(**args)
      if args[:type] && !TITLE_TYPES.include?(args[:type])
        raise ArgumentError, %{The type #{args[:type]} is invalid.}
      end

      unless args[:title] || args[:content]
        raise ArgumentError, %{Keyword "title" or "content" should be passed.}
      end

      @type = args[:type]

      # if args[:title]
      #   @title = args[:title]
      # else
      fsargs = args.select { |k, _v| %i[content language script format].include? k }
      @title = args.fetch :title, FormattedString.new(fsargs)
      # end
    end

    # @param builder [Nokogiri::XML::Builder]
    def to_xml(builder)
      builder.parent[:type] = type if type
      title.to_xml builder
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
relaton-bib-0.1.5 lib/relaton_bib/typed_title_string.rb
relaton-bib-0.1.3 lib/relaton_bib/typed_title_string.rb
relaton-bib-0.1.2 lib/relaton_bib/typed_title_string.rb
relaton-bib-0.1.1 lib/relaton_bib/typed_title_string.rb
relaton-bib-0.1.0 lib/relaton_bib/typed_title_string.rb