Sha256: 9304b71591a484497b6ddd5cd00a0cb40a45b53911347a1cd9f1333b98c54fb0

Contents?: true

Size: 1.18 KB

Versions: 66

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Nokogiri
  module Decorators
    ###
    # The Slop decorator implements method missing such that a methods may be
    # used instead of XPath or CSS.  See Nokogiri.Slop
    module Slop
      # The default XPath search context for Slop
      XPATH_PREFIX = "./"

      ###
      # look for node with +name+.  See Nokogiri.Slop
      def method_missing(name, *args, &block)
        if args.empty?
          list = xpath("#{XPATH_PREFIX}#{name.to_s.sub(/^_/, "")}")
        elsif args.first.is_a?(Hash)
          hash = args.first
          if hash[:css]
            list = css("#{name}#{hash[:css]}")
          elsif hash[:xpath]
            conds = Array(hash[:xpath]).join(" and ")
            list = xpath("#{XPATH_PREFIX}#{name}[#{conds}]")
          end
        else
          list = xpath(
            *CSS.xpath_for("#{name}#{args.first}", prefix: XPATH_PREFIX, cache: false),
          )
        end

        super if list.empty?
        list.length == 1 ? list.first : list
      end

      def respond_to_missing?(name, include_private = false)
        list = xpath("#{XPATH_PREFIX}#{name.to_s.sub(/^_/, "")}")

        !list.empty?
      end
    end
  end
end

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
nokogiri-1.18.1-x86_64-linux-musl lib/nokogiri/decorators/slop.rb
nokogiri-1.18.1-x86_64-linux-gnu lib/nokogiri/decorators/slop.rb
nokogiri-1.18.1-x86_64-darwin lib/nokogiri/decorators/slop.rb
nokogiri-1.18.1-x64-mingw-ucrt lib/nokogiri/decorators/slop.rb
nokogiri-1.18.1-java lib/nokogiri/decorators/slop.rb
nokogiri-1.18.1 lib/nokogiri/decorators/slop.rb
nokogiri-1.18.1-arm-linux-musl lib/nokogiri/decorators/slop.rb
nokogiri-1.18.1-arm-linux-gnu lib/nokogiri/decorators/slop.rb
nokogiri-1.18.1-arm64-darwin lib/nokogiri/decorators/slop.rb
nokogiri-1.18.1-aarch64-linux-musl lib/nokogiri/decorators/slop.rb
nokogiri-1.18.1-aarch64-linux-gnu lib/nokogiri/decorators/slop.rb
nokogiri-1.18.0-x86_64-linux-musl lib/nokogiri/decorators/slop.rb
nokogiri-1.18.0-x86_64-linux-gnu lib/nokogiri/decorators/slop.rb
nokogiri-1.18.0-x86_64-darwin lib/nokogiri/decorators/slop.rb
nokogiri-1.18.0-x64-mingw-ucrt lib/nokogiri/decorators/slop.rb
nokogiri-1.18.0-java lib/nokogiri/decorators/slop.rb
nokogiri-1.18.0 lib/nokogiri/decorators/slop.rb
nokogiri-1.18.0-arm-linux-musl lib/nokogiri/decorators/slop.rb
nokogiri-1.18.0-arm-linux-gnu lib/nokogiri/decorators/slop.rb
nokogiri-1.18.0-arm64-darwin lib/nokogiri/decorators/slop.rb