Sha256: 1e9e779953bc2774c4d846c3d8a1dbfd2372cda9dcdf9fa4341448eb7854e547
Contents?: true
Size: 882 Bytes
Versions: 4
Compression:
Stored size: 882 Bytes
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 def method_missing name, *args, &block if args.empty? list = xpath("./#{name}") elsif args.first.is_a? Hash hash = args.first if hash[:css] list = css("#{name}#{hash[:css]}") elsif hash[:xpath] conds = Array(hash[:xpath]).collect{|j| "[#{j}]"} list = xpath("./#{name}#{conds}") end else CSS::Parser.without_cache do list = xpath( *CSS.xpath_for("#{name}#{args.first}", :prefix => "./") ) end end super if list.empty? list.length == 1 ? list.first : list end end end end
Version data entries
4 entries across 4 versions & 1 rubygems