Class: Uniword::Wordprocessingml::Text
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Uniword::Wordprocessingml::Text
- Defined in:
- lib/uniword/wordprocessingml/text.rb
Overview
Text content with xml:space attribute support
Element: <w:t xml:space=“preserve”>
Class Method Summary collapse
-
.cast(value) ⇒ Text?
Handle type conversion for lutaml-model’s attribute system.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Allow comparison with strings for test compatibility.
-
#include?(substr) ⇒ Boolean
Support String#include? for test compatibility.
-
#space_preserve? ⇒ Boolean
Check if space should be preserved.
-
#text ⇒ Object
Get the actual text value.
-
#to_s ⇒ Object
String conversion for compatibility with code expecting plain strings.
Class Method Details
.cast(value) ⇒ Text?
Handle type conversion for lutaml-model’s attribute system. When used as an attribute type, lutaml-model calls cast() to convert incoming values to the proper type.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/uniword/wordprocessingml/text.rb', line 29 def self.cast(value) case value when Text value when nil nil else content_str = value.to_s text_obj = new(content: content_str) # Preserve whitespace for XML serialization text_obj.xml_space = "preserve" if content_str.start_with?(" ") || content_str.end_with?(" ") || content_str.include?("\t") text_obj end end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Allow comparison with strings for test compatibility
55 56 57 58 59 |
# File 'lib/uniword/wordprocessingml/text.rb', line 55 def ==(other) return super unless other.is_a?(String) content == other end |
#include?(substr) ⇒ Boolean
Support String#include? for test compatibility
64 65 66 |
# File 'lib/uniword/wordprocessingml/text.rb', line 64 def include?(substr) content.to_s.include?(substr) end |
#space_preserve? ⇒ Boolean
Check if space should be preserved
69 70 71 |
# File 'lib/uniword/wordprocessingml/text.rb', line 69 def space_preserve? xml_space == "preserve" end |
#text ⇒ Object
Get the actual text value
45 46 47 |
# File 'lib/uniword/wordprocessingml/text.rb', line 45 def text content end |
#to_s ⇒ Object
String conversion for compatibility with code expecting plain strings
50 51 52 |
# File 'lib/uniword/wordprocessingml/text.rb', line 50 def to_s content.to_s end |