Sha256: cd57879ae8adf20526b2c636631033d7935326368434ead1fc3bc941ce8d6f4a
Contents?: true
Size: 1.17 KB
Versions: 4
Compression:
Stored size: 1.17 KB
Contents
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 ### # look for node with +name+. See Nokogiri.Slop def method_missing name, *args, &block prefix = implied_xpath_context if args.empty? list = 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("#{prefix}#{name}[#{conds}]") end else CSS::Parser.without_cache do list = xpath( *CSS.xpath_for("#{name}#{args.first}", :prefix => prefix) ) end end super if list.empty? list.length == 1 ? list.first : list end def respond_to_missing? name, include_private = false prefix = implied_xpath_context list = xpath("#{prefix}#{name.to_s.sub(/^_/, '')}") !list.empty? end end end end
Version data entries
4 entries across 4 versions & 1 rubygems