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