Sha256: eb8604a4c3c3adc4c4523559f8b1f413216769ad16cb54a9f5435efdf3d7dae9

Contents?: true

Size: 1.69 KB

Versions: 180

Compression:

Stored size: 1.69 KB

Contents

module Eco
  module API
    module Common
      module People

        # @example Example of usage:
        #  class ExampleParser < Eco::API::Common::People::BaseParser
        #    def process
        #      @parsers.define_attribute("example") do |parser|
        #        parser.def_parser  do |str, deps|
        #          i = value.to_i rescue 0
        #          i +=5 if deps.dig(:sum_5)
        #          i
        #        end.def_serializer do |value|
        #          value.to_s
        #        end
        #      end
        #    end
        #  end
        #  pparser = Eco::API::Common::People::PersonParser.new
        #  ExampleParser.new(pparser)
        #  pparser.parse("example","3") # out: 3
        #  pparser.parse("example","3", deps: {sum_5: true}) # out: 8
        #  pparser.serialise("example, 8) # out: "8"
        #
        # Helper class to inherit from to ease the definition of attribute parsers in a `PersonParser` object,
        # mostly used in for configuration loading.
        class BaseParser

          # @param parsers [Eco::API::Common::People::PersonParser] set of attribute parsers/serialisers.
          # @param options [Hash] keyword arguments to be used in the `process` method of the child class.
          def initialize(parsers, **options)
            @parsers = parsers
            @options = options
          end

          # Method to be overriden by the child class.
          # @note this method is called to load the definition of the attribute parser/serializer.
          def process
            raise "Method needs to be overriden in the child class #{self.class}"
          end
        end
      end
    end
  end
end

Version data entries

180 entries across 180 versions & 1 rubygems

Version Path
eco-helpers-2.0.30 lib/eco/api/common/people/base_parser.rb
eco-helpers-2.0.29 lib/eco/api/common/people/base_parser.rb
eco-helpers-2.0.28 lib/eco/api/common/people/base_parser.rb
eco-helpers-2.0.27 lib/eco/api/common/people/base_parser.rb
eco-helpers-2.0.26 lib/eco/api/common/people/base_parser.rb
eco-helpers-2.0.25 lib/eco/api/common/people/base_parser.rb
eco-helpers-2.0.24 lib/eco/api/common/people/base_parser.rb
eco-helpers-2.0.23 lib/eco/api/common/people/base_parser.rb
eco-helpers-2.0.22 lib/eco/api/common/people/base_parser.rb
eco-helpers-2.0.21 lib/eco/api/common/people/base_parser.rb
eco-helpers-2.0.19 lib/eco/api/common/people/base_parser.rb
eco-helpers-2.0.18 lib/eco/api/common/people/base_parser.rb
eco-helpers-2.0.17 lib/eco/api/common/people/base_parser.rb
eco-helpers-2.0.16 lib/eco/api/common/people/base_parser.rb
eco-helpers-2.0.15 lib/eco/api/common/people/base_parser.rb
eco-helpers-2.0.14 lib/eco/api/common/people/base_parser.rb
eco-helpers-2.0.13 lib/eco/api/common/people/base_parser.rb
eco-helpers-2.0.12 lib/eco/api/common/people/base_parser.rb
eco-helpers-2.0.11 lib/eco/api/common/people/base_parser.rb
eco-helpers-2.0.10 lib/eco/api/common/people/base_parser.rb