Sha256: 17cc37e0df741cd66d52e0e801f69a4e26046fc08ef245da49f27d8ac8413911

Contents?: true

Size: 1.22 KB

Versions: 163

Compression:

Stored size: 1.22 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
          CSS::Parser.without_cache do
            list = xpath(
              *CSS.xpath_for("#{name}#{args.first}", :prefix => XPATH_PREFIX)
            )
          end
        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

163 entries across 156 versions & 6 rubygems

Version Path
nokogiri-backport-1.11.0 lib/nokogiri/decorators/slop.rb
tdiary-5.2.0 vendor/bundle/ruby/3.0.0/gems/nokogiri-1.12.5-x86_64-linux/lib/nokogiri/decorators/slop.rb
tdiary-5.2.0 vendor/bundle/ruby/2.7.0/gems/nokogiri-1.11.6-x86_64-linux/lib/nokogiri/decorators/slop.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/nokogiri-1.12.5-x86_64-linux/lib/nokogiri/decorators/slop.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/nokogiri-1.12.5-x86_64-linux/lib/nokogiri/decorators/slop.rb
nokogiri-1.12.5 lib/nokogiri/decorators/slop.rb
nokogiri-1.12.5-x86_64-linux lib/nokogiri/decorators/slop.rb
nokogiri-1.12.5-x86_64-darwin lib/nokogiri/decorators/slop.rb
nokogiri-1.12.5-x86-mingw32 lib/nokogiri/decorators/slop.rb
nokogiri-1.12.5-x86-linux lib/nokogiri/decorators/slop.rb
nokogiri-1.12.5-x64-mingw32 lib/nokogiri/decorators/slop.rb
nokogiri-1.12.5-java lib/nokogiri/decorators/slop.rb
nokogiri-1.12.5-arm64-darwin lib/nokogiri/decorators/slop.rb
nokogiri-1.12.4 lib/nokogiri/decorators/slop.rb
nokogiri-1.12.4-x86_64-linux lib/nokogiri/decorators/slop.rb
nokogiri-1.12.4-x86_64-darwin lib/nokogiri/decorators/slop.rb
nokogiri-1.12.4-x86-mingw32 lib/nokogiri/decorators/slop.rb
nokogiri-1.12.4-x86-linux lib/nokogiri/decorators/slop.rb
nokogiri-1.12.4-x64-mingw32 lib/nokogiri/decorators/slop.rb
nokogiri-1.12.4-java lib/nokogiri/decorators/slop.rb