extenso_pt 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f39adffd9c131f6f607c749e797abd09d736d4a36a494d88512b9cb4014ce6f0
4
+ data.tar.gz: 591aa7d4261cdd004bed3ffc3da14fd08cbaf5ec5fd60f6a8399725636e43e8c
5
+ SHA512:
6
+ metadata.gz: 35b87b7553c50e17aad3a03f3a6060fa635c371efc9ec20e88478a09766a192369971556299edff4b8514399741660d8356e50d78b9a545e596a903aaefb5ce4
7
+ data.tar.gz: 45e46683469f4fc4d597f8aedccbfe4b16a78ff9b967f75f4e00aa71da3dbc93aa8ff82ccafb4ddfb05b952cce0a5f889a6f13d54f5cc3222b8e884e878baeac
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in extenso_pt.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Hernâni Rodrigues Vaz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # ExtensoPt
2
+
3
+ Produz valores monetários por extenso e em portugês de portugal. Os valores monetários podem ser um numerico ou uma string de digitos. O extenso será produzido na escala curta podendo escolher a moeda.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'extenso_pt'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install extenso_pt
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ "1234.10".extenso => "MIL DUZENTOS E TRINTA E QUATRO EUROS E DEZ CÊNTIMOS"
25
+ 120000.12.extenso => "CENTO E VINTE MIL EUROS E DOZE CÊNTIMOS"
26
+ 1.extenso("REAL") => "UM REAL"
27
+ ```
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/extenso_pt.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "extenso_pt"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "extenso_pt/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "extenso_pt"
7
+ spec.version = ExtensoPt::VERSION
8
+ spec.authors = ["Hernâni Rodrigues Vaz"]
9
+ spec.email = ["hernanirvaz@gmail.com"]
10
+
11
+ spec.summary = %q{Produz valores monetários por extenso e em portugês de portugal.}
12
+ spec.description = %q{Os valores monetários podem ser um numerico ou uma string de digitos. O extenso será produzido na escala curta podendo escolher a moeda.}
13
+ spec.homepage = "https://github.com/hernanilr/extenso_pt"
14
+ spec.license = "MIT"
15
+
16
+ #spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ #spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
19
+ #spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 2.0"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "minitest", "~> 5.0"
33
+ end
@@ -0,0 +1,3 @@
1
+ module ExtensoPt
2
+ VERSION = "0.1.0"
3
+ end
data/lib/extenso_pt.rb ADDED
@@ -0,0 +1,42 @@
1
+ require "extenso_pt/version"
2
+
3
+ module ExtensoPt
4
+ class Error < StandardError; end
5
+
6
+ def self.o(a)[""," "," E "," DE","ZERO "+@@mp," "+@@ms," "+@@mp," "+@@cs," "+@@cp][a]end
7
+ def self.z(a)["","UM","DOIS","TRÊS","QUATRO","CINCO","SEIS","SETE","OITO","NOVE","DEZ","ONZE",
8
+ "DOZE","TREZE","CATORZE","QUINZE","DEZASSEIS","DEZASSETE","DEZOITO","DEZANOVE"][a]end
9
+ def self.c(a)["","","VINTE","TRINTA","QUARENTA","CINQUENTA","SESSENTA","SETENTA","OITENTA","NOVENTA"][a]end
10
+ def self.l(a)["","CEM","CENTO","DUZENTOS","TREZENTOS","QUATROCENTOS","QUINHENTOS",
11
+ "SEISCENTOS","SETECENTOS","OITOCENTOS","NOVECENTOS"][a]end
12
+ def self.h(a)["","MIL"," MILHÃO"," MIL MILHÃO"," BILIÃO"," MIL BILIÃO"," TRILIÃO"," MIL TRILIÃO","",
13
+ " MIL"," MILHÕES"," MIL MILHÕES"," BILIÕES"," MIL BILIÕES"," TRILIÕES"," MIL TRILIÕES"][a]end
14
+ def self.f1(k)o(k>100&&k%100>0?2:0)end
15
+ def self.f2(k)o(k>20&&k%10>0?2:0)end
16
+ def self.f3(k)o(k>100?1:k>0?2:0)end
17
+ def self.f4(k)o(k>0?k>1?6:5:0)end
18
+ def self.f5(k)o(k>0?k>1?8:7:0)end
19
+ def self.f6(k,b)o(k>0&&b>0?2:0)end
20
+ def self.f7(u,b)o(u[2..-1].to_a.find{|v|v>0}.to_i>0&&u[0..1].inject(:+).to_i==0?3:u.count>0&&b==0?4:0)end
21
+ def self.i(n,p)s=n%100;l((n>100?1:0)+n/100)+f1(n)+c(s/10)+f2(s)+z(p==1&&n==1?0:s<20?s:s%10)end
22
+ def self.w(u,d)t=u.find{|v|v>0}.to_i+u[1..-1].to_a.find{|v|v>0}.to_i;f7(u,t+d)+f4(t)+f6(t,d)+i(d,0)+f5(d)end
23
+ def self.r(g,j,p)t=j[p];p>=j.count*1?g:r(i(t,p)+h(t>0?t>1?8+p:p:0)+f3(p>0?j[p-1]:0)+g,j,p+1)end
24
+ def extenso(ms="EURO",cs="CÊNTIMO",mp=(a2=true;"EUROS"),cp=(a4=true;"CÊNTIMOS"))
25
+ n=(self.is_a?String)?self:'%.2f'%self
26
+ @@ms=ms;@@cs=cs
27
+ @@mp=(a2)?ms+"S":mp
28
+ @@cp=(a4)?cs+"S":cp
29
+ q=n[/^\d+/].to_s.reverse.scan(/\d{1,3}/).map{|i|i.reverse.to_i}
30
+ ExtensoPt.r("",q,0)+ExtensoPt.w(q,(n[/\.\d*/].to_f*100).round)
31
+ end
32
+ end
33
+ class String
34
+ include ExtensoPt
35
+ end
36
+ class Float
37
+ include ExtensoPt
38
+ end
39
+ class Integer
40
+ include ExtensoPt
41
+ end
42
+
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: extenso_pt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Hernâni Rodrigues Vaz
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ description: Os valores monetários podem ser um numerico ou uma string de digitos.
56
+ O extenso será produzido na escala curta podendo escolher a moeda.
57
+ email:
58
+ - hernanirvaz@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".travis.yml"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - extenso_pt.gemspec
72
+ - lib/extenso_pt.rb
73
+ - lib/extenso_pt/version.rb
74
+ homepage: https://github.com/hernanilr/extenso_pt
75
+ licenses:
76
+ - MIT
77
+ metadata:
78
+ homepage_uri: https://github.com/hernanilr/extenso_pt
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubygems_version: 3.0.6
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Produz valores monetários por extenso e em portugês de portugal.
98
+ test_files: []