Class: Uniword::Ooxml::Types::OoxmlBooleanOptional
- Inherits:
-
Lutaml::Model::Type::Boolean
- Object
- Lutaml::Model::Type::Boolean
- Uniword::Ooxml::Types::OoxmlBooleanOptional
- Defined in:
- lib/uniword/ooxml/types/ooxml_boolean_optional.rb
Overview
OOXML Boolean type for optional attributes (nil-omitting)
Key behavior:
- cast(nil) -> nil (doesn't convert to false like OoxmlBoolean)
- cast("1"/"true"/"on") -> true, cast("0"/"false"/"off") -> false
- cast of any other value raises Lutaml::Model::Type::InvalidValueError instead of passing through unchanged
- to_xml(true) -> "1"
- to_xml(false) -> "0" (explicit false in original)
- to_xml(nil) -> nil (attribute absent, omit from output)
This is the right type for attributes like w:locked, w:semiHidden on lsdException where absent = false = omit, but explicit "0" = render "0". Note: Due to cast(nil) = nil, absent attributes also serialize as omitted.
Class Method Summary collapse
Instance Method Summary collapse
-
#to_xml ⇒ Object
Override instance to_xml: - true -> "1" - false -> "0" - nil -> nil (omitted).
Class Method Details
.cast(value, _options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/uniword/ooxml/types/ooxml_boolean_optional.rb', line 26 def self.cast(value, = {}) return value if Lutaml::Model::Utils.uninitialized?(value) return nil if value.nil? return true if OoxmlBoolean::TRUE_VALUES.include?(value) return false if OoxmlBoolean::FALSE_VALUES.include?(value) raise Lutaml::Model::Type::InvalidValueError.new( value, OoxmlBoolean::ON_OFF_VALUES ) end |
.serialize(value) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/uniword/ooxml/types/ooxml_boolean_optional.rb', line 37 def self.serialize(value) return nil if value.nil? return "1" if OoxmlBoolean::TRUE_VALUES.include?(value) return "0" if OoxmlBoolean::FALSE_VALUES.include?(value) raise Lutaml::Model::Type::InvalidValueError.new( value, OoxmlBoolean::ON_OFF_VALUES ) end |
Instance Method Details
#to_xml ⇒ Object
Override instance to_xml:
- true -> "1"
- false -> "0"
- nil -> nil (omitted)
51 52 53 54 55 56 57 58 |
# File 'lib/uniword/ooxml/types/ooxml_boolean_optional.rb', line 51 def to_xml case @value when true "1" when false "0" end end |