Nokogiri::Decorators::Slop

module Nokogiri::Decorators::Slop

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

Constants

XPATH_PREFIX

The default XPath search context for Slop

Public Instance Methods

method_missing(name, *args, &block) Show source

look for node with name. See Nokogiri.Slop

Calls superclass method
# File lib/nokogiri/decorators/slop.rb, line 12
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
respond_to_missing?(name, include_private = false) Show source
# File lib/nokogiri/decorators/slop.rb, line 35
def respond_to_missing? name, include_private = false
  list = xpath("#{XPATH_PREFIX}#{name.to_s.sub(/^_/, '')}")

  !list.empty?
end

© 2008–2016 Aaron Patterson, Mike Dalessio, Charles Nutter, Sergio Arbeo
Patrick Mahoney, Yoko Harada, Akinori Musha, John Shahid
Licensed under the MIT License.

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部