Skip to content

Commit

Permalink
Merge pull request #2 from jr-cologne/jr_trailing-zeros
Browse files Browse the repository at this point in the history
Remove trailing zeros from numbers
  • Loading branch information
jr-cologne authored Jan 23, 2018
2 parents b2f9a49 + 856e8f2 commit b88f37f
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.1
* @version v0.1.2
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
Expand Down
2 changes: 1 addition & 1 deletion app/classes/CryptoClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.1
* @version v0.1.2
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
Expand Down
35 changes: 31 additions & 4 deletions app/classes/CryptoStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.1
* @version v0.1.2
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
Expand Down Expand Up @@ -108,14 +108,41 @@ protected function getDataset() : array {
protected function formatData() {
$this->dataset = array_map(function (array $data) {
if (isset($data['rank'], $data['symbol'], $data['name'], $data['price_usd'], $data['price_btc'], $data['percent_change_1h'])) {
$data['price_usd'] = number_format($data['price_usd'], 2);
$data['price_btc'] = number_format($data['price_btc'], 6);
return "#{$data['rank']} {$data['symbol']} ({$data['name']}): {$data['price_usd']} USD | {$data['price_btc']} BTC | {$data['percent_change_1h']}% 1h";
$data['price_usd'] = $this->removeTrailingZeros(number_format($data['price_usd'], 2));
$data['price_btc'] = $this->removeTrailingZeros(number_format($data['price_btc'], 6));

return "#{$data['rank']} #{$data['symbol']} (#{$data['name']}): {$data['price_usd']} USD | {$data['price_btc']} BTC | {$data['percent_change_1h']}% 1h";
}

throw new CryptoStatusException('Crypto data is missing', 1);
}, $this->dataset);
}

/**
* Remove trailing zeros after decimal point from number
*
* @param string $number
* @return string
*/
protected function removeTrailingZeros(string $number) : string {
$number_arr = array_reverse(str_split($number));

foreach ($number_arr as $key => $value) {
if (is_numeric($value) && $value == 0) {
unset($number_arr[$key]);
} else {
if (!is_numeric($value)) {
unset($number_arr[$key]);
}

break;
}
}

$number = implode(array_reverse($number_arr));

return $number;
}

/**
* Create the Tweets with Crypto data and return them as an array
Expand Down
2 changes: 1 addition & 1 deletion app/classes/CurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.1
* @version v0.1.2
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
Expand Down
2 changes: 1 addition & 1 deletion app/classes/Exceptions/CryptoClientException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.1
* @version v0.1.2
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
Expand Down
2 changes: 1 addition & 1 deletion app/classes/Exceptions/CryptoStatusException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.1
* @version v0.1.2
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
Expand Down
2 changes: 1 addition & 1 deletion app/classes/Exceptions/CurlClientException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.1
* @version v0.1.2
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
Expand Down
2 changes: 1 addition & 1 deletion app/classes/Exceptions/TwitterClientException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.1
* @version v0.1.2
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
Expand Down
2 changes: 1 addition & 1 deletion app/classes/TwitterClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.1
* @version v0.1.2
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
Expand Down
2 changes: 1 addition & 1 deletion app/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @author JR Cologne <[email protected]>
* @copyright 2018 JR Cologne
* @license https://github.com/jr-cologne/CryptoStatus/blob/master/LICENSE MIT
* @version v0.1
* @version v0.1.2
* @link https://github.com/jr-cologne/CryptoStatus GitHub Repository
*
* ________________________________________________________________________________
Expand Down

0 comments on commit b88f37f

Please sign in to comment.