Class: RelatonBib::LocalizedString
- Inherits:
-
Object
- Object
- RelatonBib::LocalizedString
- Includes:
- RelatonBib
- Defined in:
- lib/relaton_bib/localized_string.rb
Overview
Localized string.
Direct Known Subclasses
Constant Summary
Constants included from RelatonBib
Instance Attribute Summary collapse
- #content ⇒ String
-
#language ⇒ Array<String>
readonly
Language Iso639 code.
-
#script ⇒ Array<String>
readonly
Script Iso15924 code.
Instance Method Summary collapse
- #empty? ⇒ TrueClass, FalseClass
-
#initialize(content, language = nil, script = nil) ⇒ LocalizedString
constructor
A new instance of LocalizedString.
- #to_hash ⇒ Hash
- #to_s ⇒ String
- #to_xml(builder) ⇒ Object
Methods included from RelatonBib
array, formattedref, hash_to_bib, localizedstring, localname, parse_date, symbolize, timestamp_hash
Constructor Details
#initialize(content, language = nil, script = nil) ⇒ LocalizedString
Returns a new instance of 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> (readonly)
Returns language Iso639 code.
9 10 11 |
# File 'lib/relaton_bib/localized_string.rb', line 9 def language @language end |
#script ⇒ Array<String> (readonly)
Returns script Iso15924 code.
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 |