Sha256: 9adcc53e8e733d4a6561efdf86b3f4f98010bb6c82667be1e803e8ce8ce196de

Contents?: true

Size: 707 Bytes

Versions: 19

Compression:

Stored size: 707 Bytes

Contents

require_relative 'core'

# A parser that composes the results of multiple parsers.
# Intended for internal use only.
module Decanter
  module Parser
    class ComposeParser < Base

      def self._parse(name, value, options={})
        raise Decanter::ParseError.new('Must have parsers') unless @parsers
        # Call each parser on the result of the previous one.
        initial_result = { name => value }
        @parsers.reduce(initial_result) do |result, parser|
          result.keys.reduce({}) do |acc, key| 
            acc.merge(parser.parse(key, result[key], options)) 
          end
        end
      end

      def self.parsers(parsers)
        @parsers = parsers
      end

    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
decanter-4.0.4 lib/decanter/parser/compose_parser.rb
decanter-4.0.3 lib/decanter/parser/compose_parser.rb
decanter-4.0.2 lib/decanter/parser/compose_parser.rb
decanter-4.0.1 lib/decanter/parser/compose_parser.rb
decanter-4.0.0 lib/decanter/parser/compose_parser.rb
decanter-3.6.0 lib/decanter/parser/compose_parser.rb
decanter-3.5.1 lib/decanter/parser/compose_parser.rb
decanter-3.5.0 lib/decanter/parser/compose_parser.rb
decanter-3.4.2 lib/decanter/parser/compose_parser.rb
decanter-3.4.1 lib/decanter/parser/compose_parser.rb
decanter-3.4.0 lib/decanter/parser/compose_parser.rb
decanter-3.3.0 lib/decanter/parser/compose_parser.rb
decanter-3.2.1 lib/decanter/parser/compose_parser.rb
decanter-3.2.0 lib/decanter/parser/compose_parser.rb
decanter-3.1.2 lib/decanter/parser/compose_parser.rb
decanter-3.1.1 lib/decanter/parser/compose_parser.rb
decanter-3.1.0 lib/decanter/parser/compose_parser.rb
decanter-3.0.1 lib/decanter/parser/compose_parser.rb
decanter-3.0.0 lib/decanter/parser/compose_parser.rb