Class: RelatonBib::FormattedString

Inherits:
LocalizedString show all
Defined in:
lib/relaton_bib/formatted_string.rb

Overview

Formatted string

Direct Known Subclasses

BiblioNote, FormattedRef

Constant Summary collapse

FORMATS =
%w[text/plain text/html application/docbook+xml
application/tei+xml text/x-asciidoc text/markdown
application/x-isodoc+xml].freeze

Constants included from RelatonBib

VERSION

Instance Attribute Summary collapse

Attributes inherited from LocalizedString

#content, #language, #script

Instance Method Summary collapse

Methods inherited from LocalizedString

#empty?, #to_s

Methods included from RelatonBib

parse_date

Constructor Details

#initialize(content:, language: nil, script: nil, format: "text/plain") ⇒ FormattedString

Returns a new instance of FormattedString.

Parameters:

  • content (String, Array<RelatonBib::LocalizedString>)
  • language (String, NilClass) (defaults to: nil)

    language code Iso639

  • script (String, NilClass) (defaults to: nil)

    script code Iso15924

  • format (String) (defaults to: "text/plain")

    the content type



19
20
21
22
23
24
25
26
# File 'lib/relaton_bib/formatted_string.rb', line 19

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

Instance Attribute Details

#formatString (readonly)

Returns:

  • (String)


13
14
15
# File 'lib/relaton_bib/formatted_string.rb', line 13

def format
  @format
end

Instance Method Details

#to_hashHash

Returns:

  • (Hash)


35
36
37
38
39
40
41
42
# File 'lib/relaton_bib/formatted_string.rb', line 35

def to_hash
  hash = super
  return hash unless format

  hash = { "content" => hash } unless hash.is_a? Hash
  hash["format"] = format
  hash
end

#to_xml(builder) ⇒ Object

Parameters:

  • builder (Nokogiri::XML::Builder)


29
30
31
32
# File 'lib/relaton_bib/formatted_string.rb', line 29

def to_xml(builder)
  builder.parent["format"] = format if format
  super
end