extensobr 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/codeql-analysis.yml +70 -0
- data/.gitignore +12 -10
- data/README.md +93 -63
- data/SECURITY.md +21 -0
- data/extensobr.gemspec +29 -29
- data/lib/core_exts/float.rb +10 -0
- data/lib/core_exts/integer.rb +14 -0
- data/lib/core_exts/string.rb +41 -0
- data/lib/extensobr/version.rb +3 -3
- data/lib/extensobr.rb +479 -447
- data/lib/settings.rb +32 -0
- metadata +9 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c16a2759e6723989331737ab04867c31e50ca3275cefc8fde86652eb9b7a520
|
4
|
+
data.tar.gz: 2c66fa8ffd5355bf4f6bb708738a9e931e4e162a2fb95705fbe17510b0c62cc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cec73bb125afb3f8259a762c3448943735add98a341f565ec6a988a4f935ddb58abb04ac27e13b7a50cb99be848264211e1e7bc3696fd98734e7f93a19f5ce65
|
7
|
+
data.tar.gz: 731f65901ed947174eb506549eb16607994a4df289b47c1bc7f68794fd016a8ef0fa25ae227efdb140fa2a7e1bacc9bff9fac467759680451280c745962be8df
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# For most projects, this workflow file will not need changing; you simply need
|
2
|
+
# to commit it to your repository.
|
3
|
+
#
|
4
|
+
# You may wish to alter this file to override the set of languages analyzed,
|
5
|
+
# or to provide custom queries or build logic.
|
6
|
+
#
|
7
|
+
# ******** NOTE ********
|
8
|
+
# We have attempted to detect the languages in your repository. Please check
|
9
|
+
# the `language` matrix defined below to confirm you have the correct set of
|
10
|
+
# supported CodeQL languages.
|
11
|
+
#
|
12
|
+
name: "CodeQL"
|
13
|
+
|
14
|
+
on:
|
15
|
+
push:
|
16
|
+
branches: [ master ]
|
17
|
+
pull_request:
|
18
|
+
# The branches below must be a subset of the branches above
|
19
|
+
branches: [ master ]
|
20
|
+
schedule:
|
21
|
+
- cron: '15 7 * * 5'
|
22
|
+
|
23
|
+
jobs:
|
24
|
+
analyze:
|
25
|
+
name: Analyze
|
26
|
+
runs-on: ubuntu-latest
|
27
|
+
permissions:
|
28
|
+
actions: read
|
29
|
+
contents: read
|
30
|
+
security-events: write
|
31
|
+
|
32
|
+
strategy:
|
33
|
+
fail-fast: false
|
34
|
+
matrix:
|
35
|
+
language: [ 'ruby' ]
|
36
|
+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
37
|
+
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
38
|
+
|
39
|
+
steps:
|
40
|
+
- name: Checkout repository
|
41
|
+
uses: actions/checkout@v2
|
42
|
+
|
43
|
+
# Initializes the CodeQL tools for scanning.
|
44
|
+
- name: Initialize CodeQL
|
45
|
+
uses: github/codeql-action/init@v1
|
46
|
+
with:
|
47
|
+
languages: ${{ matrix.language }}
|
48
|
+
# If you wish to specify custom queries, you can do so here or in a config file.
|
49
|
+
# By default, queries listed here will override any specified in a config file.
|
50
|
+
# Prefix the list here with "+" to use these queries and those in the config file.
|
51
|
+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
52
|
+
|
53
|
+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
54
|
+
# If this step fails, then you should remove it and run the build manually (see below)
|
55
|
+
- name: Autobuild
|
56
|
+
uses: github/codeql-action/autobuild@v1
|
57
|
+
|
58
|
+
# ℹ️ Command-line programs to run using the OS shell.
|
59
|
+
# 📚 https://git.io/JvXDl
|
60
|
+
|
61
|
+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
62
|
+
# and modify them (or add more) to build your code if your project
|
63
|
+
# uses a compiled language
|
64
|
+
|
65
|
+
#- run: |
|
66
|
+
# make bootstrap
|
67
|
+
# make release
|
68
|
+
|
69
|
+
- name: Perform CodeQL Analysis
|
70
|
+
uses: github/codeql-action/analyze@v1
|
data/.gitignore
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/Gemfile.lock
|
4
|
-
/_yardoc/
|
5
|
-
/coverage/
|
6
|
-
/doc/
|
7
|
-
/pkg/
|
8
|
-
/spec/reports/
|
9
|
-
/tmp/
|
10
|
-
*.gem
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
*.gem
|
11
|
+
.DS_Store
|
12
|
+
.byebug_history
|
data/README.md
CHANGED
@@ -1,63 +1,93 @@
|
|
1
|
-
# Extensobr
|
2
|
-
|
3
|
-
Esta gem foi desenvolvida para auxiliar no desenvolvimento de aplicações onde é necessário escrever ou
|
4
|
-
|
5
|
-
|
6
|
-
## Instalação
|
7
|
-
|
8
|
-
Adicionando em sua Gemfile:
|
9
|
-
|
10
|
-
```ruby
|
11
|
-
gem 'extensobr'
|
12
|
-
```
|
13
|
-
|
14
|
-
Ou instale você mesmo:
|
15
|
-
|
16
|
-
$ gem install extensobr
|
17
|
-
|
18
|
-
## Exemplos de uso
|
19
|
-
|
20
|
-
Para obter o extenso de um número, utilize Extenso.numero() OBS: Ovalor deve ser do tipo "INTEGER".
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
puts Extenso.numero(832
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
Extenso.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
#
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
1
|
+
# Extensobr
|
2
|
+
|
3
|
+
Esta gem foi desenvolvida para auxiliar no desenvolvimento de aplicações onde é necessário escrever ou números ou moedas por extenso como por exemplo em recibos, contratos entre outros.
|
4
|
+
|
5
|
+
|
6
|
+
## Instalação
|
7
|
+
|
8
|
+
Adicionando em sua Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'extensobr'
|
12
|
+
```
|
13
|
+
|
14
|
+
Ou instale você mesmo:
|
15
|
+
|
16
|
+
$ gem install extensobr
|
17
|
+
|
18
|
+
## Exemplos de uso
|
19
|
+
### IMPORTANTE: este método recebe um valor inteiro(integer)
|
20
|
+
Para obter o extenso de um número, utilize Extenso.numero() OBS: Ovalor deve ser do tipo "INTEGER".
|
21
|
+
Padrão de genero da escrita é passado com um parâmetro do tipo integer, Masculino: 0, Feminino: 1, sendo que o padrão é masculino.
|
22
|
+
|
23
|
+
irb
|
24
|
+
|
25
|
+
require 'Extensobr.rb'
|
26
|
+
|
27
|
+
puts Extenso.numero(832); # oitocentos e trinta e dois
|
28
|
+
puts Extenso.numero(832, 1) # oitocentas e trinta e duas
|
29
|
+
|
30
|
+
# Novo método usando a classes do ruby a partir da versão 1.2 em diante.
|
31
|
+
puts 832.por_extenso; # oitocentos e trinta e dois
|
32
|
+
puts 832.por_extenso(1) # oitocentas e trinta e duas
|
33
|
+
puts "832".por_extenso; # oitocentos e trinta e dois
|
34
|
+
puts "832".por_extenso(1) # oitocentas e trinta e duas
|
35
|
+
|
36
|
+
### IMPORTANTE: este método recebe um valor decimal(float), para a contagem das casas decimais
|
37
|
+
|
38
|
+
Para obter o extenso de um valor monetário, utilize Extenso.moeda() OBS: Ovalor deve ser do tipo "FLOAT".
|
39
|
+
|
40
|
+
require 'Extenso.rb'
|
41
|
+
|
42
|
+
puts Extenso.moeda(154.02) # cento e cinquenta e quatro reais e dois centavos
|
43
|
+
puts Extenso.moeda(0.47) # quarenta e sete centavos
|
44
|
+
|
45
|
+
# Novos métodos usando a classes do ruby a partir da versão 1.2 em diante.
|
46
|
+
puts 154.02.por_extenso # cento e cinquenta e quatro reais e dois centavos
|
47
|
+
puts 0.47.por_extenso # quarenta e sete centavos
|
48
|
+
puts "154.02".por_extenso # cento e cinquenta e quatro reais e dois centavos
|
49
|
+
puts "0.47".por_extenso # quarenta e sete centavos
|
50
|
+
|
51
|
+
### Customize sua moéda passando como parâmetro
|
52
|
+
|
53
|
+
puts Extenso.moeda(3570.82, 2, ['peseta', 'pesetas', Extenso::GENERO_FEM], ['cêntimo', 'cêntimos', Extenso::GENERO_MASC])
|
54
|
+
# Três mil, Quinhentas e Setenta pesetas e Oitenta e Dois cêntimos
|
55
|
+
|
56
|
+
### Para obter o valor numérico em reais de um número decimal
|
57
|
+
|
58
|
+
Extenso.real_formatado(154.55) # R$ 154,55
|
59
|
+
Extenso.real_formatado(0) # R$ 0,00
|
60
|
+
Extenso.real_formatado(1) # R$ 1,00
|
61
|
+
|
62
|
+
### Configurando exeptions para valores nulos
|
63
|
+
É possivel que na sua regra de negócio ou caso de uso, seja passado um valor nulo ou vazio para tentar escrever por extenso, nesses casos por padrão será retornado "Zero" para inteiros e "Zero centavos" para decimais. No entanto você pode configurar para receber uma exceção caso seja necessário. Em suas váriáis de ambiente adicione a seguinte chave e valor:
|
64
|
+
|
65
|
+
EXTENSO_RAISE_FOR_NIL=true
|
66
|
+
|
67
|
+
E adicione um arquivo "config/extensobr.yml", com a seguinte configuração:
|
68
|
+
|
69
|
+
raise_for_nil: ENV['EXTENSO_RAISE_FOR_NIL'] || 'false'
|
70
|
+
|
71
|
+
Dessa forma, você pode esperar em seus testes a seguinte excessão:
|
72
|
+
|
73
|
+
RuntimeError: [Exceção em Extenso.numero] Parâmetro 'valor' é nulo
|
74
|
+
|
75
|
+
|
76
|
+
# Developers
|
77
|
+
|
78
|
+
[Henrique Max](https://github.com/rickmax),
|
79
|
+
[Renan Garcia](https://github.com/renan-garcia),
|
80
|
+
[Fausto G. Cintra](https://github.com/goncin),
|
81
|
+
[Victor Eduardo](https://github.com/victoreduardo)
|
82
|
+
|
83
|
+
## Como contribuir?
|
84
|
+
|
85
|
+
1. Faça um fork do projeto;
|
86
|
+
1. Adicione os devidos ajustes ou melhorias com os respectivos testes;
|
87
|
+
1. Envie pull request;
|
88
|
+
|
89
|
+
|
90
|
+
## Licença
|
91
|
+
|
92
|
+
Está Gem esta disponível sob os termos de licença [MIT License](http://opensource.org/licenses/MIT).
|
93
|
+
|
data/SECURITY.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Security Policy
|
2
|
+
|
3
|
+
## Supported Versions
|
4
|
+
|
5
|
+
Use this section to tell people about which versions of your project are
|
6
|
+
currently being supported with security updates.
|
7
|
+
|
8
|
+
| Version | Supported |
|
9
|
+
| ------- | ------------------ |
|
10
|
+
| 5.1.x | :white_check_mark: |
|
11
|
+
| 5.0.x | :x: |
|
12
|
+
| 4.0.x | :white_check_mark: |
|
13
|
+
| < 4.0 | :x: |
|
14
|
+
|
15
|
+
## Reporting a Vulnerability
|
16
|
+
|
17
|
+
Use this section to tell people how to report a vulnerability.
|
18
|
+
|
19
|
+
Tell them where to go, how often they can expect to get an update on a
|
20
|
+
reported vulnerability, what to expect if the vulnerability is accepted or
|
21
|
+
declined, etc.
|
data/extensobr.gemspec
CHANGED
@@ -1,29 +1,29 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'extensobr/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "extensobr"
|
8
|
-
spec.version = Extensobr::VERSION
|
9
|
-
spec.authors = ["Henrique Max"]
|
10
|
-
spec.email = ["rickmaxg3@hotmail.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{ExtendoBr escreve números e moeda por extenso.}
|
13
|
-
spec.description = %q{ExtensoBr é uma gem que foi desenvolvida para auxiliar na impressão de números e moedas por extenso em portugês do Brasil.}
|
14
|
-
spec.homepage = "https://github.com/rickmax/extensobr"
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
-
|
20
|
-
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
21
|
-
f.match(%r{^(test|spec|features)/})
|
22
|
-
end
|
23
|
-
spec.bindir = "exe"
|
24
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
-
spec.require_paths = ["lib"]
|
26
|
-
spec.add_development_dependency "bundler", "~> 2.2.15"
|
27
|
-
spec.add_development_dependency "rake", "~> 12.3.3"
|
28
|
-
spec.add_development_dependency "rspec"
|
29
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'extensobr/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "extensobr"
|
8
|
+
spec.version = Extensobr::VERSION
|
9
|
+
spec.authors = ["Henrique Max"]
|
10
|
+
spec.email = ["rickmaxg3@hotmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{ExtendoBr escreve números e moeda por extenso.}
|
13
|
+
spec.description = %q{ExtensoBr é uma gem que foi desenvolvida para auxiliar na impressão de números e moedas por extenso em portugês do Brasil.}
|
14
|
+
spec.homepage = "https://github.com/rickmax/extensobr"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
|
20
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
21
|
+
f.match(%r{^(test|spec|features)/})
|
22
|
+
end
|
23
|
+
spec.bindir = "exe"
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
spec.add_development_dependency "bundler", "~> 2.2.15"
|
27
|
+
spec.add_development_dependency "rake", "~> 12.3.3"
|
28
|
+
spec.add_development_dependency "rspec"
|
29
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'extensobr'
|
4
|
+
|
5
|
+
# Extende a classe Integer adicionando o metodo por_extenso e por_extenso_ordinal
|
6
|
+
Integer.class_eval do
|
7
|
+
def por_extenso(*args)
|
8
|
+
Extenso.numero(self, *args)
|
9
|
+
end
|
10
|
+
|
11
|
+
def por_extenso_ordinal(*args)
|
12
|
+
Extenso.ordinal(self, *args)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'extensobr'
|
4
|
+
|
5
|
+
# Extende a classe Integer adicionando o metodo por_extenso, por_extenso_moeda e por_extenso_numero
|
6
|
+
String.class_eval do
|
7
|
+
# Um wapper para o metodo Extenso.numero ou Extenso.moeda
|
8
|
+
# PARÂMETROS:
|
9
|
+
# type (Symbol) O tipo especifico que deseja gerar
|
10
|
+
#
|
11
|
+
# Caso o tipo não seja informado é inferido primeiro tentando encontrar um padrão de Float
|
12
|
+
# caso encontre ele supõe que o tipo é moeda. Caso contrario o tipo será numero.
|
13
|
+
def por_extenso(*args)
|
14
|
+
return por_extenso_numero(*args) if args.include? :numero
|
15
|
+
|
16
|
+
return por_extenso_moeda(*args) if args.include? :moeda
|
17
|
+
|
18
|
+
return por_extenso_ordinal(*args) if args.include? :ordinal
|
19
|
+
|
20
|
+
number = scan(/\d+[,.]\d+/).first
|
21
|
+
return por_extenso_moeda(*args) unless number.nil? || number.empty?
|
22
|
+
|
23
|
+
por_extenso_numero(*args)
|
24
|
+
end
|
25
|
+
|
26
|
+
def por_extenso_moeda(*args)
|
27
|
+
number = gsub('_', '').scan(/\d+[,.]\d+/).first
|
28
|
+
params = args - [:moeda]
|
29
|
+
Extenso.moeda(number.to_f, *params)
|
30
|
+
end
|
31
|
+
|
32
|
+
def por_extenso_numero(*args)
|
33
|
+
number = scan(/\d/)&.join('')
|
34
|
+
Extenso.numero(number&.to_i, *args)
|
35
|
+
end
|
36
|
+
|
37
|
+
def por_extenso_ordinal(*args)
|
38
|
+
number = scan(/\d/)&.join('')
|
39
|
+
Extenso.ordinal(number&.to_i, *args)
|
40
|
+
end
|
41
|
+
end
|
data/lib/extensobr/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Extensobr
|
2
|
-
VERSION = "1.
|
3
|
-
end
|
1
|
+
module Extensobr
|
2
|
+
VERSION = "1.2.0"
|
3
|
+
end
|