Sha256: 6fbea59ec8e130775ad3cee21751f13925c94586f0864cfd057e661e8d8c1dd8

Contents?: true

Size: 974 Bytes

Versions: 2

Compression:

Stored size: 974 Bytes

Contents

# frozen_string_literal: true

require "relaton_bib/localized_string"

module RelatonBib
  # Formatted string
  class FormattedString < LocalizedString
    FORMATS = %w[text/plain text/html application/docbook+xml
                 application/tei+xml text/x-asciidoc text/markdown
                 application/x-isodoc+xml].freeze

    # @return [String]
    attr_reader :format

    # @param content [String]
    # @param language [String] language code Iso639
    # @param script [String] script code Iso15924
    # @param format [String] the content type
    def initialize(content:, language: nil, script: nil, format: nil)
      # if format && !FORMATS.include?(format)
        # raise ArgumentError, %{Format "#{format}" is invalid.}
      # end

      super(content, language, script)
      @format = format
    end

    # @param builder [Nokogiri::XML::Builder]
    def to_xml(builder)
      builder.parent["format"] = format if format
      super
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
relaton-bib-0.1.6 lib/relaton_bib/formatted_string.rb
relaton-bib-0.1.5 lib/relaton_bib/formatted_string.rb