Sha256: 4279e4c805721d695207097d62a55c88df20117f1d655547454264cea6042519

Contents?: true

Size: 983 Bytes

Versions: 10

Compression:

Stored size: 983 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: "text/plain")
      # 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

10 entries across 10 versions & 1 rubygems

Version Path
relaton-bib-0.3.3 lib/relaton_bib/formatted_string.rb
relaton-bib-0.3.2 lib/relaton_bib/formatted_string.rb
relaton-bib-0.3.1 lib/relaton_bib/formatted_string.rb
relaton-bib-0.3.0 lib/relaton_bib/formatted_string.rb
relaton-bib-0.2.5 lib/relaton_bib/formatted_string.rb
relaton-bib-0.2.4 lib/relaton_bib/formatted_string.rb
relaton-bib-0.2.3 lib/relaton_bib/formatted_string.rb
relaton-bib-0.2.2 lib/relaton_bib/formatted_string.rb
relaton-bib-0.2.1 lib/relaton_bib/formatted_string.rb
relaton-bib-0.2.0 lib/relaton_bib/formatted_string.rb