lib/polites/parser.rb
# Parse a unit into our AST. This will deal with anything passed in, but
# to parse multiple nodes successfully or to parse and entire sheet, see
# {parse_fragment} and {parse_sheet}.
#
# @param [Nokogiri::Node, String] source
# @raise [ParseError] when given a `source` we cannot deal with.
# @return [Node, Array<Node>]
Parse a unit into our AST. This will deal with anything passed in, but
to parse multiple nodes successfully or to parse and entire sheet, see
{parse_fragment} and {parse_sheet}.
Parse a unit into our AST . This will deal with anything passed in but to parse multiple nodes successfully or to parse and entire sheet see { parse_fragment } and { parse_sheet } .
def parse(source)
      case source
      when Nokogiri::XML::Element
        parse_element(source)
      when Nokogiri::XML::NodeSet
        source.map { |s| parse(s) }.compact
      when Nokogiri::XML::Text
        Text.new(source.text)
      when String
        doc = Nokogiri(source)
        if doc.children.any?
          parse(doc.children)
        else
          Text.new(source)
        end
      else
        raise ParseError, "unexpected #{source.inspect}"
      end
    end
def parse ( source ) case source when Nokogiri :: XML :: Element parse_element ( source ) when Nokogiri :: XML :: NodeSet source . map { | s | parse ( s ) } . compact when Nokogiri :: XML :: Text Text . new ( source . text ) when String doc = Nokogiri ( source ) if doc . children . any? parse ( doc . children ) else Text . new ( source ) end else raise ParseError , "unexpected #{source.inspect}" end end
Parse a unit into our AST.
Parse a unit into our AST .
None
Node, Array<Node>
[ParseError] when given a `source` we cannot deal with.
[ ParseError ] when given a ` source ` we cannot deal with .
source
<not_specific>
<not_specific>
None