More tests, filtering iterator, cleanup
This commit is contained in:
@ -2,9 +2,15 @@
|
||||
|
||||
namespace NoccyLabs\Dataset;
|
||||
|
||||
use Iterator;
|
||||
use NoccyLabs\Dataset\Readers\CsvReader;
|
||||
use NoccyLabs\Dataset\Readers\JsonReader;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
class Dataset
|
||||
{
|
||||
protected string $packageName;
|
||||
@ -15,48 +21,83 @@ class Dataset
|
||||
|
||||
protected array $options;
|
||||
|
||||
protected ?string $version;
|
||||
protected string $version;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $identifier The identifier for the dataset (vendor/package#dataset)
|
||||
* @param array $options Configured options for the dataset
|
||||
* @param string|null $version The package version
|
||||
*/
|
||||
public function __construct(string $identifier, array $options, ?string $version=null)
|
||||
{
|
||||
$this->identifier = $identifier;
|
||||
$this->options = $options;
|
||||
$this->version = $version;
|
||||
$this->version = $version??"0.0.0.0";
|
||||
|
||||
[$this->packageName, $this->datasetName] = explode("#", $identifier, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getIdentifier(): string
|
||||
{
|
||||
return $this->identifier;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPackageName(): string
|
||||
{
|
||||
return $this->packageName;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDatasetName(): string
|
||||
{
|
||||
return $this->datasetName;
|
||||
}
|
||||
|
||||
public function getVersion(): ?string
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getVersion(): string
|
||||
{
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getComment(): ?string
|
||||
{
|
||||
return array_key_exists('comment', $this->options) ? $this->options['comment'] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getLicense(): ?string
|
||||
{
|
||||
return array_key_exists('license', $this->options) ? $this->options['license'] : null;
|
||||
}
|
||||
|
||||
public function open(): ReaderInterface
|
||||
/**
|
||||
*
|
||||
* @return Iterator
|
||||
*/
|
||||
public function open(): Iterator
|
||||
{
|
||||
$filename = $this->options['filename'];
|
||||
$reader = $this->determineReaderForFile($filename);
|
||||
@ -64,6 +105,11 @@ class Dataset
|
||||
return $inst;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $filename
|
||||
* @return string
|
||||
*/
|
||||
private function determineReaderForFile(string $filename): string
|
||||
{
|
||||
if ($reader = $this->options['reader']??null) {
|
||||
|
Reference in New Issue
Block a user