<commit_before>directory-service
=================

A basic LDAP search service.<commit_msg>Added basic usage documentation<commit_after>directory-service
=================

A basic LDAP search service.

Initialize ...

```ruby
> require './lib/directory_service'
 => true 
```

... with hash config

```ruby
> ds = DirectoryService.new(host: "ldap.example.com", base: "dc=example,dc=com")
 => #<DirectoryService: @host=ldap.duke.edu @port= @base=ou=people,dc=duke,dc=edu @scope=1> 
# Other options - :username, :password, :port, :scope
```

... with ENV vars

```sh
$ export DIRECTORY_HOST="ldap.example.com"
$ export DIRECTORY_BASE="dc=example,dc=com"
# Optional - DIRECTORY_PORT, DIRECTORY_SCOPE, DIRECTORY_USER, DIRECTORY_PASS
```

Use with block

```ruby
> DirectoryService.new(host: "ldap.example.com", base: "dc=example,dc=com") do |ds|
>   # do stuff with ds
> end
```

Magic find_by_* methods corresponding to LDAP attribute names

```ruby
> ds.find_by_uid("foobar")
# Returns single result
 => #<DirectoryService::Result:0x007f91019a9a18 @ldap_entry=#<Net::LDAP::Entry:0x007f91019b1740 ...>> 
```

Search with Net::LDAP filters

```ruby
> ds.search(Net::LDAP::Filter.contains("cn", "foobar"))
 => [#<DirectoryService::Result:0x007f910190afa8 ...>, #<DirectoryService::Result:0x007f91018f1440 ...>, #<DirectoryService::Result:0x007f91018e8fc0 ...>, ...
```

Search with string filters (as supported by Net::LDAP)

```ruby
> ds.search("(cn=*coble*)")
 => [#<DirectoryService::Result:0x007f910190afa8 ...>, #<DirectoryService::Result:0x007f91018f1440 ...>, #<DirectoryService::Result:0x007f91018e8fc0 ...>, ...
```
{'fraction_non_alphanumeric': 0.19925971622455274, 'fraction_numerical': 0.05922270203578038, 'mean_word_length': 5.96137339055794, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 25, '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': '4164590', 'n_tokens_mistral': 649, 'n_tokens_neox': 563, 'n_words': 105}