Skip to content

Commit

Permalink
Refatoração para publicação
Browse files Browse the repository at this point in the history
- Adiciona nova classe "NumericoParaExtenso" para conversão de números para sua forma por extenso.
- Altera visibilidade das classes "ExtensoParaNumero" e "NumeroParaExtenso" para protegido (protected).
- Transforma a classe "Extenso" em uma fachada para expor os métodos "descrever" e "converter".
- Atualiza o arquivo Readme com informações relevantes.
- Atualiza o arquivo Changelog com as alterações realizadas.
- Aperfeiçoa os testes existentes e adiciona novos testes para garantir a qualidade do código.
- Atualiza o exemplo de uso para refletir as mudanças feitas na biblioteca.
  • Loading branch information
leogouveia committed Jun 13, 2023
1 parent 0b58b8c commit 0048a43
Show file tree
Hide file tree
Showing 12 changed files with 385 additions and 192 deletions.
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
## 0.0.1

* TODO: Describe initial release.
- TODO: Describe initial release.

## 0.0.3

* Correção de nomenclatura
- Correção de nomenclatura

## 0.0.4

* Adicionado exemplo
* Corrigida formatação do código
- Adicionado exemplo
- Corrigida formatação do código

## 0.0.5

- Adiciona opção de converter extenso para numero
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
<!--
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/developing-packages).
[developing packages and plugins](https://flutter.dev/developing-packages).
-->

Um método para converter números para valor monetário por extenso, para português brasileiro
Uma classe com métodos para converter números em valor monetário por extenso, e para converter números por extenso em sua forma numérica correspondente, seguindo o idioma português brasileiro.

## Features

Exemplo:
`Extenso.descrever(14051234567890.63)`

Apresentará o retorno (String):
`quatorze trilhões, cinquenta e um bilhões, duzentos e trinta e quatro milhões, quinhentos e sessenta e sete mil, oitocentos e noventa reais e sessenta e três centavos`

## Getting started
Exemplo:

`Extenso.converter('duzentos e trinta e quatro milhões, quinhentos e sessenta e sete mil, oitocentos e setenta centavos');`

TODO: List prerequisites and provide or point to information on how to
start using the package.
Apresentará o retorno (double):
`234567800.70`

## Usage

First, add this package to your project:
`dart pub add dart_numero_extenso_br`

Then, at your code import the library and use:

```dart
import 'package:dart_numero_extenso_br/dart_numero_extenso_br.dart';
...
Extenso.descrever(14051234567890.63)
Extenso.descrever(14051234567890.63);
Extenso.converter('Dois milhoes e um');
```

## Additional information
Expand Down
138 changes: 138 additions & 0 deletions coverage/lcov.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
SF:lib\dart_extenso_numero.dart
DA:9,1
DA:10,1
DA:11,2
DA:14,1
DA:15,2
DA:18,1
DA:19,1
DA:60,1
DA:71,1
DA:72,1
DA:74,1
DA:79,1
DA:83,0
DA:86,0
DA:90,0
DA:96,0
DA:97,0
DA:99,1
DA:100,2
DA:101,1
DA:102,2
DA:106,1
DA:107,1
DA:108,2
DA:109,1
DA:113,1
DA:114,1
DA:115,2
DA:116,1
DA:117,2
DA:119,1
DA:123,1
LF:32
LH:27
end_of_record
SF:lib\dart_remover_acentos.dart
DA:5,3
DA:6,1
DA:11,1
DA:12,1
DA:13,1
DA:14,1
DA:15,1
DA:16,1
DA:17,1
DA:21,1
DA:26,1
DA:31,1
DA:32,1
DA:33,1
DA:38,1
DA:39,1
DA:44,1
DA:49,1
DA:54,1
DA:55,1
DA:60,1
DA:65,1
DA:66,1
DA:67,1
DA:71,1
DA:76,1
DA:77,1
DA:78,1
DA:83,1
DA:84,1
DA:85,1
DA:86,1
DA:87,1
DA:88,1
DA:92,1
DA:93,1
DA:98,1
DA:103,1
DA:108,1
DA:109,1
DA:114,1
DA:118,1
DA:119,1
DA:123,1
DA:124,1
DA:129,1
DA:134,1
DA:139,1
DA:140,1
DA:141,1
DA:142,1
DA:143,1
DA:144,1
DA:145,1
DA:149,1
DA:154,1
DA:159,1
DA:160,1
DA:165,1
DA:166,1
DA:171,1
DA:176,1
DA:177,1
DA:182,1
DA:183,1
DA:188,1
DA:193,1
DA:194,1
DA:198,1
DA:203,1
DA:204,1
DA:209,1
DA:210,1
DA:211,1
DA:212,1
DA:216,1
DA:217,1
DA:222,1
DA:227,1
DA:232,1
DA:233,1
DA:238,1
DA:242,1
DA:243,1
DA:248,1
DA:249,1
DA:254,1
DA:261,3
DA:263,3
DA:265,1
DA:266,2
DA:267,4
DA:268,3
DA:269,1
DA:270,2
DA:271,6
DA:276,3
DA:277,3
LF:98
LH:98
end_of_record
6 changes: 4 additions & 2 deletions example/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ First, add this package to your project:
`dart pub add dart_numero_extenso_br`

Then, at your code import the library and use:

```dart
import 'package:dart_numero_extenso_br/dart_numero_extenso_br.dart';
...
Extenso.descrever(14051234567890.63)
```
Extenso.descrever(14051234567890.63);
Extenso.converter('Dois milhoes e um');
```
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
library numero_extenso;

import 'package:flutter/foundation.dart';

import 'dart_remover_acentos.dart';

class ConverterExtenso {
static String limparString(String str) {
@protected
class ExtensoParaNumero {
static String _stringLimpar(String str) {
str = RemoverAcentos.remover(str);
return str.replaceAll(RegExp(r'[.,!?\;\|\{\}\[\]]'), '');
}

static bool hasDigits(String text) {
static bool _temDigitos(String text) {
return text.contains(RegExp(r'\d'));
}

Expand Down Expand Up @@ -68,27 +71,26 @@ class ConverterExtenso {
final RegExp regexValor = RegExp(r'[\d,.]+');
final RegExp regexNotacao = RegExp(r'[a-z]');

final palavras = limparString(numeroExtenso);
final palavras = _stringLimpar(numeroExtenso);
var numero = 0.0;
var valor = 0.0;
var valorStr = '';
final bool hasDigitsInPalavras = hasDigits(palavras);

final bool hasDigitsInPalavras = _temDigitos(palavras);
if (hasDigitsInPalavras) {
var notacaoCientifica = '';

final String? valorMatch = regexValor.firstMatch(palavras)?.group(0);

if (valorMatch != null) {
valorStr = valorMatch.replaceAll(',', '.');
print(valorStr); // Output: 1.000.50
valorStr = valorMatch.replaceAll(',', '.'); // Output: 1.000.50
}

final notacaoCientificaMatch =
regexNotacao.firstMatch(palavras)?.group(0);

if (notacaoCientificaMatch != null) {
notacaoCientifica = notacaoCientificaMatch;
print(notacaoCientifica); // Output: a
notacaoCientifica = notacaoCientificaMatch; // Output: a
}

final multiplicador = multiplicadores[notacaoCientifica] ?? 1;
Expand Down
Loading

0 comments on commit 0048a43

Please sign in to comment.