123456789_123456789_123456789_123456789_123456789_

Module: Nokogiri::Decorators::Slop

Relationships & Source Files
Defined in: lib/nokogiri/decorators/slop.rb

Overview

The Slop decorator implements method missing such that a methods may be used instead of XPath or ::Nokogiri::CSS. See Nokogiri.Slop

Constant Summary

Instance Method Summary

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block)

look for node with name. See Nokogiri.Slop

[ GitHub ]

  
# File 'lib/nokogiri/decorators/slop.rb', line 14

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

Instance Method Details

#respond_to_missing?(name, include_private = false) ⇒ Boolean

[ GitHub ]

  
# File 'lib/nokogiri/decorators/slop.rb', line 37

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

  !list.empty?
end