module RichText::Attributes

@api private

Public Class Methods

compose(a, b, keep_nil) click to toggle source
# File lib/rich-text/attributes.rb, line 5
def compose(a, b, keep_nil)
  return b if a.nil?
  return a if b.nil?
  result = b.merge(a) { |k,vb,va| vb }
  result.delete_if { |k,v| v.nil? } unless keep_nil
  result
end
diff(a, b) click to toggle source
# File lib/rich-text/attributes.rb, line 13
def diff(a, b)
  return b if a.nil?
  return a if b.nil?
  (a.keys | b.keys).each_with_object({}) do |key, memo|
    memo[key] = b[key] if a[key] != b[key]
  end
end
transform(a, b, priority) click to toggle source
# File lib/rich-text/attributes.rb, line 21
def transform(a, b, priority)
  return b if a.nil? || a.empty? || b.nil? || b.empty? || !priority
  (b.keys - a.keys).each_with_object({}) do |key, memo|
    memo[key] = b[key]
  end
end