module Xlsxrb::Elements::MetadataRecord
Shared mixin for metadata Data value objects.
Public Class Methods
(Module base) → void
Source
# File lib/xlsxrb/elements/metadata.rb, line 72 def self.included(base) base.singleton_class.prepend(StrictKeywords) end
Public Instance Methods
() → bool
Source
# File lib/xlsxrb/elements/metadata.rb, line 81 def empty? to_h.values.all? { |v| v.nil? || (v.respond_to?(:empty?) && v.empty?) } end
Returns whether all attributes are nil or empty.
@return [Boolean] @api public
() → Hash[Symbol, untyped]
Source
# File lib/xlsxrb/elements/metadata.rb, line 90 def to_h res = super.compact.transform_values do |val| if val.is_a?(Array) # Nested Arrays, such as the [name, count] pairs of AppProperties#heading_pairs, # respond to to_h but are not key-value pairs, so they stay as they are. val.map { |v| v.respond_to?(:to_h) && !v.is_a?(String) && !v.is_a?(Array) ? v.to_h : v } elsif val.respond_to?(:to_h) && !val.is_a?(String) && !val.is_a?(Hash) && !val.is_a?(RichText) # RichText is Enumerable over its runs, so Enumerable#to_h would treat each run as a # key-value pair. It stays a value object, which the writers accept as cell and comment text. val.to_h else val end end if members.include?(:options) && res[:options].is_a?(Hash) opts = res.delete(:options) opts.each { |ok, ov| res[ok] ||= ov } end res end
Converts the value object to a Hash of non-nil attributes.
@return [Hash{Symbol => Object}] @api public
Calls superclass method
Also aliased as: to_hash