Class: RelatonBib::LocalizedString
- Inherits:
-
Object
- Object
- RelatonBib::LocalizedString
show all
- Includes:
- RelatonBib
- Defined in:
- lib/relaton_bib/localized_string.rb
Overview
Constant Summary
Constants included
from RelatonBib
VERSION
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from RelatonBib
array, formattedref, hash_to_bib, localizedstring, localname, symbolize, timestamp_hash
Constructor Details
#initialize(content, language = nil, script = nil) ⇒ LocalizedString
20
21
22
23
24
|
# File 'lib/relaton_bib/localized_string.rb', line 20
def initialize(content, language = nil, script = nil)
@language = language.is_a?(String) ? [language] : language
@script = script.is_a?(String) ? [script] : script
@content = content
end
|
Instance Attribute Details
#content ⇒ String
15
16
17
|
# File 'lib/relaton_bib/localized_string.rb', line 15
def content
@content
end
|
#language ⇒ Array<String>
9
10
11
|
# File 'lib/relaton_bib/localized_string.rb', line 9
def language
@language
end
|
#script ⇒ Array<String>
12
13
14
|
# File 'lib/relaton_bib/localized_string.rb', line 12
def script
@script
end
|
Instance Method Details
#empty? ⇒ TrueClass, FalseClass
32
33
34
|
# File 'lib/relaton_bib/localized_string.rb', line 32
def empty?
content.empty?
end
|
#to_hash ⇒ Hash
46
47
48
49
50
51
52
53
|
# File 'lib/relaton_bib/localized_string.rb', line 46
def to_hash
return content unless language || script
hash = { "content" => content }
hash["language"] = single_element_array(language) if language&.any?
hash["script"] = single_element_array(script) if script&.any?
hash
end
|
#to_s ⇒ String
27
28
29
|
# File 'lib/relaton_bib/localized_string.rb', line 27
def to_s
content
end
|
#to_xml(builder) ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/relaton_bib/localized_string.rb', line 37
def to_xml(builder)
return unless content
builder.parent["language"] = language.join(",") if language&.any?
builder.parent["script"] = script.join(",") if script&.any?
builder.text content
end
|