Sha256: 08f02eaa9f9b32ff68a554b6ff2dc379540d0ba9c3c47c6541cb42bfbfe35b7e

Contents?: true

Size: 806 Bytes

Versions: 1

Compression:

Stored size: 806 Bytes

Contents

require 'json'
require 'cogitate/client/data_to_object_coercer'
require 'cogitate/models/identifier'

module Cogitate
  module Client
    module ResponseParsers
      # When you want an agent that omits identifiers associated with a group
      module AgentsWithoutGroupMembershipExtractor
        def self.call(response:)
          identifier_guard = method(:identifier_is_not_a_group?)
          JSON.parse(response).fetch('data').map { |datum| DataToObjectCoercer.call(datum, identifier_guard: identifier_guard) }
        end

        # @api private
        # Perhaps a weird place to put this code, but it appears to work
        def self.identifier_is_not_a_group?(identifier:)
          identifier.strategy != Cogitate::Models::Identifier::GROUP_STRATEGY_NAME
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cogitate-0.0.2 lib/cogitate/client/response_parsers/agents_without_group_membership_extractor.rb