\BookParser

Scans directories for book information and parses the information.

Summary

Methods
Properties
Constants
__construct()
scanDirectory()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
parseFile()
parseTitle()
parseDates()
parseTypes()
parseCategories()
parseContent()
updateStatistics()
$jsonReader
$bookData
$bookId
N/A

Properties

$jsonReader

$jsonReader : \JsonReader

JsonReader object to deal with json files.

Type

\JsonReader

$bookData

$bookData : array

Holds the information for the available books.

Type

normal

$bookId

$bookId : int

Holds the current id to assign a unique id to every book.

Type

normal

Methods

__construct()

__construct() : mixed

Initializes the json reader object.

Returns

mixed

scanDirectory()

scanDirectory(string  $dir = __DIR__ . '/../data/books') : void

Scans the data/books/ directory for available books and parses their information.

The information is stored in separate json files, available in the data/ directory.

Parameters

string $dir

The directory to scan.

parseFile()

parseFile(string  $file) : void

Parses a given markdown file and saves the book information to the $bookData variable.

Parameters

string $file

The file to parse.

parseTitle()

parseTitle(string  $fileContent) : string

Extracts the book title from a given book note file.

Parameters

string $fileContent

The content of a book note file.

Returns

string —

The corresponding book title.

parseDates()

parseDates(string  $fileContent) : array

Extracts the dates (when the book was read) from a given book note file.

Parameters

string $fileContent

The content of a book note file.

Returns

array —

The corresponding dates when the book was read.

parseTypes()

parseTypes(string  $fileContent) : array

Extracts the types (in which form the book was read, e.g. paperback or ebook) from a given book note file.

Parameters

string $fileContent

The content of a book note file.

Returns

array —

The corresponding types in which form the book was read.

parseCategories()

parseCategories(string  $fileContent) : array

Extracts the categories from a given book note file.

Parameters

string $fileContent

The content of a book note file.

Returns

array —

The corresponding categories.

parseContent()

parseContent(string  $fileContent) : string

Extracts the raw content from a given book note file.

Parameters

string $fileContent

The content of a book note file.

Returns

string —

The corresponding raw content (without title, dates, types, etc.).

updateStatistics()

updateStatistics() : void

Updates the statistical values (e.g. total number of books read).