<commit_before>#
# @author - <NAME> <<EMAIL>>
#
# contains all entities of a given constructor
#
class EntityRepository

  constructor: (@entityClass)->
    @entityClassName = getClassName @entityClass
    @entityList = []

  canHandle: (entityCheck)->
    @entityClass is entityCheck or @entityClassName is entityCheck or entityCheck.constructor is @entityClass

  add: (entity)-> @entityList.push entity

  remove: (entity)-> @entityList.splice @entityList.indexOf(entity), 1

  find: (id)->
    return entity for entity in @entityList when entity.id is id
    null

  findAll: -> @entityList

  findBy: (criteria)-> (entity for entity in @entityList when isMatch(entity, criteria))

  findOneBy: (criteria)->
    return entity for entity in @entityList when isMatch(entity, criteria)
    null

  numEntities: -> @entityList.length

  # PRIVATE

  isMatch = (entity, criteria)->
    return false for prop, value of criteria when entity[prop] isnt value
    true

  getClassName = (entityClass)->
    funcNameRegex = /function (.{1,})\(/;
    results = (funcNameRegex).exec(entityClass.toString());
    if (results? and results.length > 1) then results[1] else ""
    
return EntityRepository<commit_msg>added EntityConstructorMap into EntityRepository for canHandle matching<commit_after>EntityConstructorMap = require 'scribe/repositories/entity_constructor_map'
#
# @author - <NAME> <<EMAIL>>
#
# contains all entities of a given constructor
#
class EntityRepository

  constructor: (@entityClass)->
    @entityList = []

  canHandle: (entityCheck)->
    @entityClass is entityCheck or EntityConstructorMap.match(entityCheck, @entityClass) or entityCheck.constructor is @entityClass

  add: (entity)-> @entityList.push entity

  remove: (entity)-> @entityList.splice @entityList.indexOf(entity), 1

  find: (id)->
    return entity for entity in @entityList when entity.id is id
    null

  findAll: -> @entityList

  findBy: (criteria)-> (entity for entity in @entityList when isMatch(entity, criteria))

  findOneBy: (criteria)->
    return entity for entity in @entityList when isMatch(entity, criteria)
    null

  numEntities: -> @entityList.length

  # PRIVATE

  isMatch = (entity, criteria)->
    return false for prop, value of criteria when entity[prop] isnt value
    true
    
return EntityRepository
{'fraction_non_alphanumeric': 0.1070811744386874, 'fraction_numerical': 0.002158894645941278, 'mean_word_length': 4.171875, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3522761', 'n_tokens_mistral': 667, 'n_tokens_neox': 638, 'n_words': 214}