<commit_before>FIND_PACKAGE(Ruby REQUIRED)

EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r narray -e "print 'true'" 
	OUTPUT_VARIABLE RUBY_HAS_NARRAY
	ERROR_QUIET)

# find vendor arch dir
EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['vendorarchdir']" 
	OUTPUT_VARIABLE RUBY_VENDOR_ARCH_DIR
	ERROR_QUIET)

FIND_PATH(RUBY_NARRAY_INCLUDE_DIR narray.h
	HINTS ${RUBY_VENDOR_ARCH_DIR} ${RUBY_LIBRARY} ${RUBY_POSSIBLE_LIB_DIR})

FIND_FILE(RUBY_NARRAY_LIBRARY NAMES narray.bundle narray.so
	HINTS ${RUBY_VENDOR_ARCH_DIR} ${RUBY_LIBRARY} ${RUBY_POSSIBLE_LIB_DIR})

INCLUDE (FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(RubyNArray DEFAULT_MSG 
	RUBY_HAS_NARRAY RUBY_NARRAY_INCLUDE_DIR RUBY_NARRAY_LIBRARY)

MARK_AS_ADVANCED(RUBY_NARRAY_INCLUDE_DIR RUBY_NARRAY_LIBRARY)
<commit_msg>Refactor RubyNarray package detector<commit_after>FIND_PACKAGE(Ruby REQUIRED)

EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r narray -e "print 'true'"
	OUTPUT_VARIABLE RUBY_HAS_NARRAY
	ERROR_QUIET)

# find vendor arch dir
EXECUTE_PROCESS(COMMAND ${RUBY_EXECUTABLE} -r rbconfig -e "print RbConfig::CONFIG['vendorarchdir']".
    OUTPUT_VARIABLE RUBY_VENDOR_ARCH_DIR
    ERROR_QUIET)

find_program(GEM_EXECUTABLE NAMES gem)

if (GEM_EXECUTABLE)
	EXECUTE_PROCESS(COMMAND ${GEM_EXECUTABLE} which narray
		OUTPUT_VARIABLE RUBY_NARRAY_PATH
		ERROR_QUIET)

	if(RUBY_NARRAY_PATH)
		SET(RUBY_HAS_NARRAY 1)
		STRING(REGEX REPLACE "(.*)/narray.*$" "\\1" RUBY_NARRAY_PATH ${RUBY_NARRAY_PATH})

		FIND_PATH(RUBY_NARRAY_INCLUDE_DIR narray.h
			HINTS ${RUBY_NARRAY_PATH})

		FIND_FILE(RUBY_NARRAY_LIBRARY NAMES narray.bundle narray.so
			HINTS ${RUBY_NARRAY_PATH})
	endif()
endif()

if (NOT RUBY_NARRAY_INCLUDE_DIR)
	FIND_PATH(RUBY_NARRAY_INCLUDE_DIR narray.h
		HINTS ${RUBY_VENDOR_ARCH_DIR} ${RUBY_LIBRARY} ${RUBY_POSSIBLE_LIB_DIR})
endif()

if (NOT RUBY_NARRAY_LIBRARY)
	FIND_FILE(RUBY_NARRAY_LIBRARY NAMES narray.bundle narray.so
		HINTS ${RUBY_VENDOR_ARCH_DIR} ${RUBY_LIBRARY} ${RUBY_POSSIBLE_LIB_DIR})
endif()

INCLUDE (FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(RubyNArray DEFAULT_MSG
	RUBY_HAS_NARRAY RUBY_NARRAY_INCLUDE_DIR RUBY_NARRAY_LIBRARY)

MARK_AS_ADVANCED(RUBY_NARRAY_INCLUDE_DIR RUBY_NARRAY_LIBRARY)

{'fraction_non_alphanumeric': 0.08185053380782918, 'fraction_numerical': 0.0008896797153024911, 'mean_word_length': 8.65236051502146, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2942723', 'n_tokens_mistral': 1041, 'n_tokens_neox': 938, 'n_words': 142}