Sha256: 3fc43f2589435ffeb5c1c885e5af1aed2d680eaf786ed16cb373202d8602b4b0
Contents?: true
Size: 1018 Bytes
Versions: 1
Compression:
Stored size: 1018 Bytes
Contents
module Flexparser # # A Parser similar to the TagParser but intendet for a collection # of properties. # @param sub_parser [Wrench] all CollectionParsers need a subparser to # deal with the content of the nodes parsed. This should ideally be # a class that includes Spigots::Wrench and can parse the fragment it # is dealt. # class CollectionParser < TagParser # # @param doc [Nokogiri::Node] a node that can be accessed through xpath # @return [Array<Object>] An array of String if no type was specified, # otherwise the type will try to parse the string using ::parse # def parse(doc) content(doc).map do |n| next sub_parser.parse(n) if sub_parser next type.parse(n.text) if type n.text end end protected def content(doc) content = doc.xpath(xpaths.valid_paths(doc).reduce(&:union).to_s) return content unless content.empty? options[:required] ? raise_required_error(doc) : content end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
flexparser-1.0.3 | lib/flexparser/collection_parser.rb |