<commit_before>![Clamby Logo](https://raw.github.com/kobaltz/clamby/master/clamby_logo.png)

[![GemVersion](https://badge.fury.io/rb/clamby.png)](https://badge.fury.io/rb/clamby.png)
[![Build Status](https://travis-ci.org/kobaltz/clamby.svg?branch=master)](https://travis-ci.org/kobaltz/clamby)

This gem depends on the [clamscan](http://www.clamav.net/) and `freshclam` daemons to be installed already.

If you have a file upload on your site and you do not scan the files for viruses then you not only compromise your software, but also the users of the software and their files. This gem's function is to simply scan a given file.

# Usage

[Drifting Ruby Screencast](https://www.driftingruby.com/episodes/antivirus-uploads-with-clamby?utm_source=github&utm_medium=social&utm_campaign=github)

Be sure to check the CHANGELOG as recent changes may affect functionality.

Just add `gem 'clamby'` to your `Gemfile` and run `bundle install`.

You can use two methods to scan a file for a virus:

If you use `safe?` to scan a file, it will return true if no viruses were found, false if a virus was found, and nil if there was a problem finding the file or if there was a problem using `clamscan`

`safe?(path_to_file)`

If you use `virus?` to scan a file, it will return true if a virus was found, false if no virus was found, and nil if there was a problem finding the file or if there was a problem using `clamscan`


`virus?(path_to_file)`

In your model with the uploader, you can add the scanner to a before method to scan the file. When a file is scanned, a successful scan will return `true`. An unsuccessful scan will return `false`. A scan may be unsuccessful for a number of reasons; `clamscan` could not be found, `clamscan` returned a virus, or the file which you were trying to scan could not be found.

```ruby<commit_msg>Use `Clamby` and format return values. (#30)<commit_after>![Clamby Logo](https://raw.github.com/kobaltz/clamby/master/clamby_logo.png)

[![GemVersion](https://badge.fury.io/rb/clamby.png)](https://badge.fury.io/rb/clamby.png)
[![Build Status](https://travis-ci.org/kobaltz/clamby.svg?branch=master)](https://travis-ci.org/kobaltz/clamby)

This gem depends on the [clamscan](http://www.clamav.net/) and `freshclam` daemons to be installed already.

If you have a file upload on your site and you do not scan the files for viruses then you not only compromise your software, but also the users of the software and their files. This gem's function is to simply scan a given file.

# Usage

[Drifting Ruby Screencast](https://www.driftingruby.com/episodes/antivirus-uploads-with-clamby?utm_source=github&utm_medium=social&utm_campaign=github)

Be sure to check the CHANGELOG as recent changes may affect functionality.

Just add `gem 'clamby'` to your `Gemfile` and run `bundle install`.

You can use two methods to scan a file for a virus:

If you use `safe?` to scan a file, it will return `true` if no viruses were found, `false` if a virus was found, and `nil` if there was a problem finding the file or if there was a problem using `clamscan`

`Clamby.safe?(path_to_file)`

If you use `virus?` to scan a file, it will return `true` if a virus was found, `false` if no virus was found, and `nil` if there was a problem finding the file or if there was a problem using `clamscan`


`Clamby.virus?(path_to_file)`

In your model with the uploader, you can add the scanner to a before method to scan the file. When a file is scanned, a successful scan will return `true`. An unsuccessful scan will return `false`. A scan may be unsuccessful for a number of reasons; `clamscan` could not be found, `clamscan` returned a virus, or the file which you were trying to scan could not be found.

```ruby
{'fraction_non_alphanumeric': 0.09337268580627851, 'fraction_numerical': 0.0005366246310705661, 'mean_word_length': 4.580838323353293, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 12, 'lorem ipsum': 0, 'www.': 4, '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': '3124151', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1168, 'n_words': 515}