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.
-
.preserve_whitespace?(content) ⇒ Boolean
Whether the content requires xml:space="preserve" per OOXML spec.
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 |
# 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) text_obj.xml_space = "preserve" if preserve_whitespace?(content_str) text_obj end end |
.preserve_whitespace?(content) ⇒ Boolean
Whether the content requires xml:space="preserve" per OOXML spec. Leading/trailing spaces, tabs, and newlines all need preservation.
45 46 47 48 |
# File 'lib/uniword/wordprocessingml/text.rb', line 45 def self.preserve_whitespace?(content) content.start_with?(" ") || content.end_with?(" ") || content.include?("\t") || content.include?("\n") end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Allow comparison with strings for test compatibility
61 62 63 64 65 |
# File 'lib/uniword/wordprocessingml/text.rb', line 61 def ==(other) return super unless other.is_a?(String) content == other end |
#include?(substr) ⇒ Boolean
Support String#include? for test compatibility
70 71 72 |
# File 'lib/uniword/wordprocessingml/text.rb', line 70 def include?(substr) content.to_s.include?(substr) end |
#space_preserve? ⇒ Boolean
Check if space should be preserved
75 76 77 |
# File 'lib/uniword/wordprocessingml/text.rb', line 75 def space_preserve? xml_space == "preserve" end |
#text ⇒ Object
Get the actual text value
51 52 53 |
# File 'lib/uniword/wordprocessingml/text.rb', line 51 def text content end |
#to_s ⇒ Object
String conversion for compatibility with code expecting plain strings
56 57 58 |
# File 'lib/uniword/wordprocessingml/text.rb', line 56 def to_s content.to_s end |