Class: RelatonBib::FormattedString
Overview
Constant Summary
collapse
- FORMATS =
%w[text/plain text/html application/docbook+xml
application/tei+xml text/x-asciidoc text/markdown
application/x-metanorma+xml].freeze
Constants included
from RelatonBib
VERSION
Instance Attribute Summary collapse
#content, #language, #script
Instance Method Summary
collapse
#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.
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")
super(content, language, script)
@format = format
end
|
Instance Attribute Details
13
14
15
|
# File 'lib/relaton_bib/formatted_string.rb', line 13
def format
@format
end
|
Instance Method Details
#to_asciibib(prefix = "", count = 1, has_attrs = false) ⇒ String
47
48
49
50
51
52
53
54
|
# File 'lib/relaton_bib/formatted_string.rb', line 47
def to_asciibib(prefix = "", count = 1, has_attrs = false)
has_attrs ||= !(format.nil? || format.empty?)
pref = prefix.empty? ? prefix : prefix + "."
out = super
out += "#{pref}format:: #{format}\n" if format
out
end
|
#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 } unless hash.is_a? Hash
hash["format"] = 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
|