monetico 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1,2 @@
1
+ rvm_gemset_create_on_use_flag=1
2
+ rvm gemset use monetico
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in monetico.gemspec
4
+ gemspec
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2011 Zaiste!
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ Monetico
2
+ ========
3
+
4
+ Basic calc for everything money related
5
+
6
+ Instalation
7
+ -----------
8
+
9
+ gem install monetico
10
+
11
+ Usage
12
+ -----
13
+
14
+ License
15
+ -------
16
+
17
+ Released under the MIT License. See the [LICENSE][license] file for further details.
18
+
19
+ [license]: https://github.com/zaiste/monetico/blob/master/LICENSE.md
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ require "bigdecimal"
2
+ require "monetico/loan"
3
+ require "monetico/version"
4
+
5
+ class Float
6
+ def big; BigDecimal(self.to_s); end
7
+
8
+ def round_to(x)
9
+ (self * 10**x).ceil.to_f / 10**x
10
+ end
11
+
12
+ def round_down(x)
13
+ if self >= 0
14
+ (self * 10**x).floor.to_f / 10**x
15
+ else
16
+ -((-self * 10**x).floor.to_f / 10**x)
17
+ end
18
+ end
19
+ end
20
+
21
+ module Monetico
22
+ # Your code goes here...
23
+ end
@@ -0,0 +1,57 @@
1
+ module Monetico
2
+ class Loan
3
+ CADENCE = {
4
+ monthly: 12,
5
+ weekly: 52,
6
+ }
7
+
8
+ def initialize(amount, interest_rate, no_installments, cadence=:monthly, kind=:desc)
9
+ @amount = amount.big
10
+ @interest_rate = interest_rate.big / CADENCE[cadence]
11
+ @no_installments = no_installments
12
+ @kind = kind
13
+ end
14
+
15
+ def capital
16
+ @amount / @no_installments
17
+ end
18
+
19
+ def total_interests
20
+ if const?
21
+ par = (1 + @interest_rate) ** @no_installments
22
+ payback_amount = @amount * @interest_rate * par / (par - 1)
23
+
24
+ payback_amount * @no_installments - @amount
25
+ else
26
+ 0.5.big * @interest_rate * @no_installments * (@amount + capital)
27
+ end
28
+ end
29
+
30
+ def interests(idx)
31
+ (@amount - (idx - 1) * capital) * @interest_rate
32
+ end
33
+
34
+ def payback(range)
35
+ from = range.begin
36
+ to = range.end
37
+
38
+ if const?
39
+ par = (1 + @interest_rate) ** @no_installments
40
+
41
+ range.map do |n|
42
+ { no: n, interests: interests(n), amount: @amount * @interest_rate * par / (par - 1) }
43
+ end
44
+ else
45
+ range.map do |n|
46
+ { no: n, interests: interests(n), amount: capital + interests(n) }
47
+ end
48
+ end
49
+ end
50
+
51
+ def const?
52
+ @kind == :const
53
+ end
54
+ private :const?
55
+
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module Monetico
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/monetico/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["zaiste"]
6
+ gem.email = ["oh@zaiste.net"]
7
+ gem.homepage = "http://dev.zaiste.net/monetico"
8
+ gem.description = %q{Your favourite money related calculations with Ruby}
9
+ gem.summary = %q{Basic calcz for everything money related}
10
+
11
+ gem.add_development_dependency("rake")
12
+ gem.add_development_dependency("bundler")
13
+
14
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ gem.files = `git ls-files`.split("\n")
16
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+
18
+ gem.name = "monetico"
19
+ gem.require_paths = ["lib"]
20
+ gem.version = Monetico::VERSION
21
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: monetico
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - zaiste
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-26 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &2193119460 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2193119460
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
27
+ requirement: &2193118980 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2193118980
36
+ description: Your favourite money related calculations with Ruby
37
+ email:
38
+ - oh@zaiste.net
39
+ executables: []
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - .rvmrc
45
+ - Gemfile
46
+ - LICENSE.md
47
+ - README.md
48
+ - Rakefile
49
+ - lib/monetico.rb
50
+ - lib/monetico/loan.rb
51
+ - lib/monetico/version.rb
52
+ - monetico.gemspec
53
+ homepage: http://dev.zaiste.net/monetico
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ segments:
66
+ - 0
67
+ hash: -810136211445472196
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ segments:
75
+ - 0
76
+ hash: -810136211445472196
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 1.8.11
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Basic calcz for everything money related
83
+ test_files: []