<commit_before><?php
namespace LazyRecord\Exporter;
use LazyRecord\BaseModel;
use LazyRecord\BaseCollection;
use LazyRecord\Schema\SchemaBase;
use LazyRecord\Schema\Relationship;
use LazyRecord\Schema\RuntimeSchema;
use LazyRecord\Schema\RuntimeColumn;
use LazyRecord\Schema\DeclareSchema;
use LazyRecord\Schema\SchemaInterface;

class CSVExporter
{
    protected $fd;

    public function __construct($fd)
    {
        $this->fd = $fd;
    }


    /**
     *
     * int fputcsv ( resource $handle , array $fields [, string $delimiter = "," [, string $enclosure = '"' [, string $escape_char = "\" ]]] )
     */
    public function exportCollection(BaseCollection $collection)
    {
        $schema = $collection->getSchema();

        $keys = $schema->getColumnNames();
        fputcsv($this->fd, $keys);
        foreach ($collection as $record) {
            // $array = $record->toInflatedArray();
            $array = $record->toArray();

            $fields = [];
            foreach ($keys as $key) {
                $fields[] = $array[$key];
            }
            fputcsv($this->fd, $fields);
        }
    }

}



<commit_msg>Provide csv options to csv exporter<commit_after><?php
namespace LazyRecord\Exporter;
use LazyRecord\BaseModel;
use LazyRecord\BaseCollection;
use LazyRecord\Schema\SchemaBase;
use LazyRecord\Schema\Relationship;
use LazyRecord\Schema\RuntimeSchema;
use LazyRecord\Schema\RuntimeColumn;
use LazyRecord\Schema\DeclareSchema;
use LazyRecord\Schema\SchemaInterface;

class CSVExporter
{
    protected $fd;

    protected $delimiter = ','; // default to ',';

    protected $enclosure = '"'; // default to '"'

    protected $escapeChar = "\\"; // default to "\";

    public function __construct($fd, $delimiter = ',', $enclosure = '"', $escapeChar = "\\")
    {
        $this->fd = $fd;
        $this->delimiter = $delimiter;
        $this->enclosure = $enclosure;
        $this->escapeChar = $escapeChar;
    }

    public function setDelimiter($delimiter)
    {
        $this->delimiter = $delimiter;
    }

    public function setEnclosure($enclosure)
    {
        $this->enclosure = $enclosure;
    }

    public function setEscapeChar($char)
    {
        $this->escapeChar = $char;
    }

    /**
     * Export collection object into CSV file.
     *
     * int fputcsv ( resource $handle , array $fields [, string $delimiter = "," [, string $enclosure = '"' [, string $escape_char = "\" ]]] )
     */
    public function exportCollection(BaseCollection $collection)
    {
        $schema = $collection->getSchema();
        $keys = $schema->getColumnNames();
        fputcsv($this->fd, $keys, $this->delimiter, $this->enclosure, $this->escapeChar);
        foreach ($collection as $record) {
            // $array = $record->toInflatedArray();
            $array = $record->toArray();

            $fields = [];
            foreach ($keys as $key) {
                $fields[] = $array[$key];
            }
            fputcsv($this->fd, $fields, $this->delimiter, $this->enclosure, $this->escapeChar);
        }
    }

}




{'fraction_non_alphanumeric': 0.14797913950456323, 'fraction_numerical': 0.0, 'mean_word_length': 2.568604651162791, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, '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': '237077', 'n_tokens_mistral': 938, 'n_tokens_neox': 911, 'n_words': 187}