ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ILIAS\Refinery\String\EstimatedReadingTime Class Reference
+ Inheritance diagram for ILIAS\Refinery\String\EstimatedReadingTime:
+ Collaboration diagram for ILIAS\Refinery\String\EstimatedReadingTime:

Public Member Functions

 __construct (bool $withImages)
 ReadingTime constructor. More...
 
 transform ($from)
 Perform the transformation.Please use this for transformations. It's more performant than calling invoke.
Exceptions

InvalidArgumentException if the argument could not be transformed

Parameters
mixed$from
Returns
mixed
More...
 
- Public Member Functions inherited from ILIAS\Refinery\Transformation
 transform ($from)
 Perform the transformation. More...
 
 applyTo (Result $data)
 Perform the transformation and reify possible failures. More...
 
 __invoke ($from)
 Transformations should be callable. More...
 

Private Member Functions

 calculateWordsForImages (int $numberOfImages)
 

Private Attributes

 $wordsPerMinute = 275
 
 $firstImageReadingTimeInSeconds = 12
 
 $withImages = false
 

Detailed Description

Definition at line 10 of file EstimatedReadingTime.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Refinery\String\EstimatedReadingTime::__construct ( bool  $withImages)

ReadingTime constructor.

Parameters
bool$withImages

Definition at line 28 of file EstimatedReadingTime.php.

References ILIAS\Refinery\String\EstimatedReadingTime\$withImages.

Member Function Documentation

◆ calculateWordsForImages()

ILIAS\Refinery\String\EstimatedReadingTime::calculateWordsForImages ( int  $numberOfImages)
private
See also
https://blog.medium.com/read-time-and-you-bc2048ab620c
Parameters
int$numberOfImages
Returns
float The calculated reading time for the passed number of images translated to words

Definition at line 98 of file EstimatedReadingTime.php.

98 : float
99 {
100 $time = 0.0;
101
102 for ($i = 1; $i <= $numberOfImages; $i++) {
103 if ($i >= 10) {
104 $time += 3 * ((int) $this->wordsPerMinute / 60);
105 } else {
106 $time += (12 - ($i - 1)) * ((int) $this->wordsPerMinute / 60);
107 }
108 }
109
110 return $time;
111 }
$i
Definition: metadata.php:24

References $i.

◆ transform()

ILIAS\Refinery\String\EstimatedReadingTime::transform (   $from)

Perform the transformation.Please use this for transformations. It's more performant than calling invoke.

Exceptions

InvalidArgumentException if the argument could not be transformed

Parameters
mixed$from
Returns
mixed

Implements ILIAS\Refinery\Transformation.

Definition at line 36 of file EstimatedReadingTime.php.

37 {
38 if (!is_string($from)) {
39 throw new \InvalidArgumentException(__METHOD__ . " the argument is not a string.");
40 }
41
42 return $this->calculate($from);
43 }

Field Documentation

◆ $firstImageReadingTimeInSeconds

ILIAS\Refinery\String\EstimatedReadingTime::$firstImageReadingTimeInSeconds = 12
private

Definition at line 19 of file EstimatedReadingTime.php.

◆ $withImages

ILIAS\Refinery\String\EstimatedReadingTime::$withImages = false
private

◆ $wordsPerMinute

ILIAS\Refinery\String\EstimatedReadingTime::$wordsPerMinute = 275
private

Definition at line 16 of file EstimatedReadingTime.php.


The documentation for this class was generated from the following file: