Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' of https://github.com/abr4xas/utils
Browse files Browse the repository at this point in the history
  • Loading branch information
abr4xas committed Jul 20, 2017
2 parents 830be4e + 0d75b50 commit ea1463d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 26 deletions.
9 changes: 5 additions & 4 deletions README.md
Expand Up @@ -45,10 +45,11 @@ Debug::dieDump($var);

use Abr4xas\Utils\Money;

Money::generaFormato(200, 'USD$');
Money::generaFormato(200, 'USD$', 5); // 5 decimals
Money::generaFormato(200, ['s' => 'USD$']); // USD$ 200.00
Money::generaFormato(200, ['s' => 'USD$', 'd' => 4]); // USD$ 200.0000

Money::quitarFormato('USD$ 200', 'USD$');
Money::quitarFormato('USD$ 200', ['s' => 'USD$']); // 200.00
Money::quitarFormato('USD$ 200', ['s' => 'USD$', 'd' => 4]); // 200.0000

use Abr4xas\Utils\Gravatar;

Expand All @@ -58,4 +59,4 @@ use Abr4xas\Utils\TimeFormat;

TimeFormat::timeAgo('2017-07-11');

```
```
10 changes: 5 additions & 5 deletions src/Gravatar.php
Expand Up @@ -34,11 +34,11 @@ class Gravatar
const HTTPS_URL = 'https://secure.gravatar.com/avatar/';

/**
* Returns the user's gravatar url.
* @param string $email The email address
* @param array $options Optional, additional key/value attributes to include
* @return string Link to the user's gravatar image.
*/
* Returns the user's gravatar url.
* @param string $email The email address
* @param array $options Optional, additional key/value attributes to include
* @return string Link to the user's gravatar image.
*/
public static function getAvatarUrl($email, $options = [])
{
$size = isset($options['s']) ? $options['s'] : 80;
Expand Down
20 changes: 13 additions & 7 deletions src/Money.php
Expand Up @@ -35,30 +35,36 @@ class Money
* Genera el formato de moneda
*
* @param float $valor monto a transformar
* @param string $simbolo símbolo a mostrar por defecto BsF
* @param int $decimal cantidad de decimales a mostrar por defecto dos
* @param array $options additional key/value attributes to include
* @return string valor formateado según $simbolo y $decimal
* @throws Exception
*/

public static function generaFormato($valor = 0, $simbolo = 'BsF', $decimal = 2)
public static function generaFormato($valor = 0, $options = [])
{

$simbolo = isset($options['s']) ? $options['s'] : 'BsF';
$decimal = isset($options['d']) ? $options['d'] : 2;

if (!is_numeric($valor))
throw new Exception("{$valor} debe indicar un número que sea válido");
if (!is_int($decimal))
throw new Exception("El valor {$decimal} no es válido");
throw new Exception("El valor {$decimal} no es válido");

return $simbolo . ' ' . number_format($valor, $decimal, '.', '');
}
/**
* Retira el formato generado de moneda
*
* @param string $str monto a transformar
* @param string $simbolo
* @param array $options additional key/value attributes to include
* @return float
*/
public static function quitarFormato($str, $simbolo = 'BsF')
public static function quitarFormato($str, $options = [])
{
return floatval(str_replace('.', '', str_replace($simbolo, '', $str)));
$simbolo = isset($options['s']) ? $options['s'] : 'BsF';
$decimal = isset($options['d']) ? $options['d'] : 2;

return number_format(str_replace($simbolo, '', $str), $decimal, '.', '');
}
}
20 changes: 10 additions & 10 deletions src/SeoUrl.php
Expand Up @@ -31,11 +31,11 @@
class SeoUrl
{
/**
* Remove Accent
*
* @param string $str
* @return string
*/
* Remove Accent
*
* @param string $str
* @return string
*/
public static function removeAccent($str)
{
$first = [
Expand All @@ -48,11 +48,11 @@ public static function removeAccent($str)
}

/**
* Generate Slug
*
* @param string $str
* @return string
*/
* Generate Slug
*
* @param string $str
* @return string
*/
public static function generateSlug($str)
{
return strtolower(preg_replace(
Expand Down

0 comments on commit ea1463d

Please sign in to comment.