Sha256: 36ba17f69d9b6cd8182abfc683971518d46efe18575cbc8316c8a6e4886ab1a6

Contents?: true

Size: 987 Bytes

Versions: 2

Compression:

Stored size: 987 Bytes

Contents

# frozen_string_literal: true

require 'nokogiri'

# FIXME: Temporarily here to provider syntactic sugar
module Nokogiri
  module XML
    class Document
      def tag_name
        root.tag_name
      end
    end

    class Node
      def <<(node_or_tags)
        # FIXME: Add this line to transform element implicitly
        node_or_tags = node_or_tags.public_send(:to_element, parent: self) if node_or_tags.respond_to?(:to_element)

        add_child(node_or_tags)
        self
      end

      def adapt?(klass)
        adaptable_classes = [String, Integer, Time]
        is_a?(Nokogiri::XML::Text) && adaptable_classes.include?(klass)
      end

      def tag_name
        [namespace&.prefix, name].compact.join(':')
      end

      def unparsed_children
        @unparsed_children ||= children.dup
      end

      def attributes_hash
        attribute_nodes.reject { |node| node.tag_name == 'mc:Ignorable' }.to_h { |node| [node.tag_name, node.value] }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
goldendocx-0.3.0 lib/extensions/nokogiri_extensions.rb
goldendocx-0.2.3 lib/extensions/nokogiri_extensions.rb