ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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
More...
 
- Public Member Functions inherited from ILIAS\Refinery\Transformation
 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.

29  {
30  $this->withImages = $withImages;
31  }

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.

References $i.

Referenced by ILIAS\Refinery\String\EstimatedReadingTime\transform().

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
+ Here is the caller graph for this function:

◆ transform()

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

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

Exceptions

Implements ILIAS\Refinery\Transformation.

Definition at line 36 of file EstimatedReadingTime.php.

References ILIAS\Refinery\String\EstimatedReadingTime\calculateWordsForImages().

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  }
+ Here is the call graph for this function:

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: