ReadingTime
in package
implements
Stringable
Calculate the estimated reading time for a text.
Table of Contents
Interfaces
- Stringable
Properties
- $seconds : int
- $text : string
- $wordCount : int
- $wordsPerMinute : int
Methods
- __construct() : mixed
- __toString() : mixed
- formatUsingClosure() : string
- fromFile() : static
- fromString() : static
- getFormatted() : string
- getMinutes() : int
- getSeconds() : int
- getSecondsOver() : int
- getWordCount() : int
- generate() : void
- getMinutesAsFloat() : float
Properties
$seconds
protected
int
$seconds
The number of seconds it takes to read the text.
$text read-only
protected
string
$text
The text to calculate the reading time for.
$wordCount
protected
int
$wordCount
The number of words in the text.
$wordsPerMinute
protected
static int
$wordsPerMinute
= 240
How many words per minute is read. Inversely proportional. Increase for a shorter reading time.
Methods
__construct()
public
__construct(string $text) : mixed
Parameters
- $text : string
__toString()
public
__toString() : mixed
formatUsingClosure()
public
formatUsingClosure(callable(int, int): string $closure) : string
Parameters
- $closure : callable(int, int): string
-
The closure will receive the minutes and seconds as integers and should return a string.
Return values
stringfromFile()
public
static fromFile(string $path) : static
Parameters
- $path : string
Return values
staticfromString()
public
static fromString(string $text) : static
Parameters
- $text : string
Return values
staticgetFormatted()
public
getFormatted([string $format = '%dmin, %dsec' ]) : string
Parameters
- $format : string = '%dmin, %dsec'
Return values
stringgetMinutes()
public
getMinutes() : int
Return values
intgetSeconds()
public
getSeconds() : int
Return values
intgetSecondsOver()
public
getSecondsOver() : int
Return values
intgetWordCount()
public
getWordCount() : int
Return values
intgenerate()
protected
generate() : void
getMinutesAsFloat()
protected
getMinutesAsFloat() : float