Sha256: 31ce3112ddbf2fd61e16eda0d67d87463c24c6d77bd49888f122f306f1931677
Contents?: true
Size: 1.18 KB
Versions: 22
Compression:
Stored size: 1.18 KB
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, NilClass] language code Iso639 # @param script [String, NilClass] 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 # @return [Hash] def to_hash hash = super return hash unless format hash = { "content" => hash } if hash.is_a? String hash["format"] = format if format hash end end end
Version data entries
22 entries across 22 versions & 1 rubygems