Class: RelatonBib::FormattedString
- Inherits:
-
LocalizedString
- Object
- LocalizedString
- RelatonBib::FormattedString
- Defined in:
- lib/relaton_bib/formatted_string.rb
Overview
Formatted string
Direct Known Subclasses
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
Instance Attribute Summary collapse
- #format ⇒ String readonly
Attributes inherited from LocalizedString
Instance Method Summary collapse
-
#initialize(content:, language: nil, script: nil, format: "text/plain") ⇒ FormattedString
constructor
A new instance of FormattedString.
- #to_hash ⇒ Hash
- #to_xml(builder) ⇒ Object
Methods inherited from LocalizedString
Methods included from RelatonBib
array, formattedref, hash_to_bib, localizedstring, localname, parse_date, symbolize, timestamp_hash
Constructor Details
#initialize(content:, language: nil, script: nil, format: "text/plain") ⇒ FormattedString
Returns a new instance of FormattedString.
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
#format ⇒ String (readonly)
13 14 15 |
# File 'lib/relaton_bib/formatted_string.rb', line 13 def format @format end |
Instance Method Details
#to_hash ⇒ 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 } if hash.is_a? String hash["format"] = format if format hash end |
#to_xml(builder) ⇒ Object
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 |