financier 0.1.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 +7 -0
 - data/.gitignore +16 -0
 - data/.travis.yml +7 -0
 - data/Gemfile +3 -0
 - data/LICENSE.txt +21 -0
 - data/README.md +39 -0
 - data/Rakefile +10 -0
 - data/bin/console +14 -0
 - data/bin/setup +8 -0
 - data/exe/financier +3 -0
 - data/financier.gemspec +48 -0
 - data/lib/financier/amortization.rb +138 -0
 - data/lib/financier/date.rb +13 -0
 - data/lib/financier/ledger.rb +50 -0
 - data/lib/financier/rate.rb +148 -0
 - data/lib/financier/transaction.rb +47 -0
 - data/lib/financier/version.rb +3 -0
 - data/lib/financier.rb +15 -0
 - data/spec/financier/amortization_spec.rb +11 -0
 - data/spec/financier/date_spec.rb +28 -0
 - data/spec/financier/ledger_spec.rb +86 -0
 - data/spec/financier/rate_spec.rb +188 -0
 - data/spec/financier/transaction_spec.rb +118 -0
 - data/spec/financier_spec.rb +7 -0
 - data/spec/spec_helper.rb +1 -0
 - metadata +176 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 4acef944cf6ffbdc5c777c207d0a240728b4294f241604e2a27e1b54b4da49c7
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 78d3272877b1ea47b9ef04c62d61cd8920f41c2a2a36f56764a161cb48045e69
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: d44ff1f921631eb820a2c8a594c1c1dc85ceb81876f96b143a88611ba213c081bffb341d4e7ce84f976d9c669b22f7202d84e772e98d7cead012e4a3fca26271
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 4bbd19def0055a54d7fb67ad4eabbe5c5e37ec1cd4d7bdf632578b821ea2187b5de01122f753e3a57c5dfd77c0ad8bbaaf48cc774fef0469976d7767ae397c89
         
     | 
    
        data/.gitignore
    ADDED
    
    
    
        data/.travis.yml
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/LICENSE.txt
    ADDED
    
    | 
         @@ -0,0 +1,21 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            The MIT License (MIT)
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            Copyright (c) 2019 Ethan Barron
         
     | 
| 
      
 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,39 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # Financier
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/financier`. To experiment with that code, run `bin/console` for an interactive prompt.
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            TODO: Delete this and the text above, and describe your gem
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            ## Installation
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            Add this line to your application's Gemfile:
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            ```ruby
         
     | 
| 
      
 12 
     | 
    
         
            +
            gem 'financier'
         
     | 
| 
      
 13 
     | 
    
         
            +
            ```
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
            And then execute:
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                $ bundle
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            Or install it yourself as:
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                $ gem install financier
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            ## Usage
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            TODO: Write usage instructions here
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            ## Development
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rpsec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            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).
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            ## Contributing
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
            Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/financier.
         
     | 
| 
      
 36 
     | 
    
         
            +
             
     | 
| 
      
 37 
     | 
    
         
            +
            ## License
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
            The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
         
     | 
    
        data/Rakefile
    ADDED
    
    
    
        data/bin/console
    ADDED
    
    | 
         @@ -0,0 +1,14 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require "bundler/setup"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require "financier"
         
     | 
| 
      
 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
    
    
    
        data/exe/financier
    ADDED
    
    
    
        data/financier.gemspec
    ADDED
    
    | 
         @@ -0,0 +1,48 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
             
     | 
| 
      
 2 
     | 
    
         
            +
            lib = File.expand_path("../lib", __FILE__)
         
     | 
| 
      
 3 
     | 
    
         
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            require 'financier/version'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            Gem::Specification.new do |spec|
         
     | 
| 
      
 8 
     | 
    
         
            +
              spec.name          = 'financier'
         
     | 
| 
      
 9 
     | 
    
         
            +
              spec.version       = Financier::VERSION
         
     | 
| 
      
 10 
     | 
    
         
            +
              spec.authors       = ['Ethan Barron']
         
     | 
| 
      
 11 
     | 
    
         
            +
              spec.email         = ['ethan.barron@kalidy.com']
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              spec.summary       = 'Provides handy financial calculators.'
         
     | 
| 
      
 14 
     | 
    
         
            +
              spec.description   = 'Ruby gem to deal with financial calculations.'
         
     | 
| 
      
 15 
     | 
    
         
            +
              spec.homepage      = 'https://rubygems.org/gems/financier'
         
     | 
| 
      
 16 
     | 
    
         
            +
              spec.license       = 'MIT'
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
              # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
         
     | 
| 
      
 19 
     | 
    
         
            +
              # to allow pushing to a single host or delete this section to allow pushing to any host.
         
     | 
| 
      
 20 
     | 
    
         
            +
              if spec.respond_to?(:metadata)
         
     | 
| 
      
 21 
     | 
    
         
            +
                spec.metadata["allowed_push_host"] = "https://rubygems.org"
         
     | 
| 
      
 22 
     | 
    
         
            +
                spec.metadata["homepage_uri"] = spec.homepage
         
     | 
| 
      
 23 
     | 
    
         
            +
                spec.metadata["source_code_uri"] = 'https://github.com/Inkybro/financier'
         
     | 
| 
      
 24 
     | 
    
         
            +
                # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
         
     | 
| 
      
 25 
     | 
    
         
            +
              else
         
     | 
| 
      
 26 
     | 
    
         
            +
                raise "RubyGems 2.0 or newer is required to protect against " \
         
     | 
| 
      
 27 
     | 
    
         
            +
                  "public gem pushes."
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
              # Specify which files should be added to the gem when it is released.
         
     | 
| 
      
 31 
     | 
    
         
            +
              # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
         
     | 
| 
      
 32 
     | 
    
         
            +
              spec.files         = Dir.chdir(File.expand_path('..', __FILE__)) do
         
     | 
| 
      
 33 
     | 
    
         
            +
                `git ls-files -z`.split("\x0")
         
     | 
| 
      
 34 
     | 
    
         
            +
              end
         
     | 
| 
      
 35 
     | 
    
         
            +
              spec.test_files    = spec.files.grep(%r{^(test|spec|features)/})
         
     | 
| 
      
 36 
     | 
    
         
            +
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         
     | 
| 
      
 37 
     | 
    
         
            +
              spec.require_paths = ['lib']
         
     | 
| 
      
 38 
     | 
    
         
            +
              spec.bindir        = 'exe'
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
              spec.add_dependency 'activesupport', '>= 5.2.3'
         
     | 
| 
      
 41 
     | 
    
         
            +
              spec.add_dependency 'chronic', '>= 0.10.2'
         
     | 
| 
      
 42 
     | 
    
         
            +
              spec.add_dependency 'flt', '>= 1.5.0'
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
              spec.add_development_dependency 'bundler', '~> 2.0.1'
         
     | 
| 
      
 45 
     | 
    
         
            +
              spec.add_development_dependency 'rake', '~> 10.0'
         
     | 
| 
      
 46 
     | 
    
         
            +
              spec.add_development_dependency 'rspec', '>= 3.8.0'
         
     | 
| 
      
 47 
     | 
    
         
            +
              spec.add_development_dependency 'rubocop', '~> 0.67.2'
         
     | 
| 
      
 48 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,138 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Financier
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Amortization
         
     | 
| 
      
 3 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 4 
     | 
    
         
            +
                  def payment(principal, rate, periods)
         
     | 
| 
      
 5 
     | 
    
         
            +
                    principal, rate, periods = [D(principal.to_s), D(rate.to_s), D(periods.to_s)]
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                    return -(principal / periods).round(2) if rate.zero?
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                    -(principal * (rate + (rate / ((1 + rate) ** periods - 1)))).round(2)
         
     | 
| 
      
 10 
     | 
    
         
            +
                  end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  def interest(principal, rate)
         
     | 
| 
      
 13 
     | 
    
         
            +
                    (D(principal.to_s) * D(rate.to_s))
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                #attr_reader :principal, :rate, :closing_date, :first_payment_due
         
     | 
| 
      
 18 
     | 
    
         
            +
                attr_reader :payment, :closing_date, :first_payment_due, :ledger
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                def initialize(principal, rate, closing_date: nil, first_payment_due: nil)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  @principal = Flt::DecNum.new(principal.to_s)
         
     | 
| 
      
 22 
     | 
    
         
            +
                  @rate = rate
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                  self.closing_date = closing_date || Time.now
         
     | 
| 
      
 25 
     | 
    
         
            +
                  self.first_payment_due = first_payment_due || (@closing_date + 30.days)
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                  #@periods = rate.duration
         
     | 
| 
      
 28 
     | 
    
         
            +
                  #@period = 0
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                  compute
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                def balance
         
     | 
| 
      
 34 
     | 
    
         
            +
                  return unless @ledger
         
     | 
| 
      
 35 
     | 
    
         
            +
                  @ledger.balance
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                def payments
         
     | 
| 
      
 39 
     | 
    
         
            +
                  return unless @ledger
         
     | 
| 
      
 40 
     | 
    
         
            +
                  @ledger.debits
         
     | 
| 
      
 41 
     | 
    
         
            +
                end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                def interest
         
     | 
| 
      
 44 
     | 
    
         
            +
                  return unless @ledger
         
     | 
| 
      
 45 
     | 
    
         
            +
                  @ledger.credits[1..(@ledger.credits.length - 1)]
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                def closing_date=(value)
         
     | 
| 
      
 49 
     | 
    
         
            +
                  @closing_date = Date[value]
         
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                def first_payment_due=(value)
         
     | 
| 
      
 53 
     | 
    
         
            +
                  @first_payment_due = Date[value]
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                def amortize
         
     | 
| 
      
 57 
     | 
    
         
            +
                  @payment = Amortization.payment(@principal + interim_interest, @rate.monthly, @rate.duration)
         
     | 
| 
      
 58 
     | 
    
         
            +
                  @ledger = Ledger.new(@principal)
         
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
      
 60 
     | 
    
         
            +
                  current_date = @first_payment_due
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                  @rate.duration.to_i.times do |period|
         
     | 
| 
      
 63 
     | 
    
         
            +
                    break if @ledger.balance.zero?
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                    int = @ledger.balance * @rate.monthly
         
     | 
| 
      
 66 
     | 
    
         
            +
                    int += interim_interest * (1 + @rate.monthly) if period === 0
         
     | 
| 
      
 67 
     | 
    
         
            +
                    @ledger << Transaction.new(int.round(2), current_date)
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                    pmt = @payment.abs <= @ledger.balance ? @payment : -@ledger.balance
         
     | 
| 
      
 70 
     | 
    
         
            +
                    @ledger << Transaction.new(pmt, current_date)
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                    current_date += 1.month
         
     | 
| 
      
 73 
     | 
    
         
            +
                  end
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                  @ledger.debits.last.amount -= @ledger.balance unless @ledger.balance.zero?
         
     | 
| 
      
 76 
     | 
    
         
            +
                end
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
      
 78 
     | 
    
         
            +
                def compute
         
     | 
| 
      
 79 
     | 
    
         
            +
                  amortize
         
     | 
| 
      
 80 
     | 
    
         
            +
                end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
                def schedule
         
     | 
| 
      
 83 
     | 
    
         
            +
                  @schedule = {}
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                  @schedule[closing_date] = {
         
     | 
| 
      
 86 
     | 
    
         
            +
                    payment: 0.0,
         
     | 
| 
      
 87 
     | 
    
         
            +
                    interest: 0.0,
         
     | 
| 
      
 88 
     | 
    
         
            +
                    principal: 0.0,
         
     | 
| 
      
 89 
     | 
    
         
            +
                    balance: @principal.round(2).to_f
         
     | 
| 
      
 90 
     | 
    
         
            +
                  }
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
                  payments.each_with_index do |payment, index|
         
     | 
| 
      
 93 
     | 
    
         
            +
                    interest = self.interest[index]
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
                    pmt = payment.amount.abs.round(2).to_f
         
     | 
| 
      
 96 
     | 
    
         
            +
                    int = interest.amount.abs.round(2).to_f
         
     | 
| 
      
 97 
     | 
    
         
            +
                    princ = (pmt - int).round(2).to_f
         
     | 
| 
      
 98 
     | 
    
         
            +
                    bal = @ledger.balance(before: payment.date + 1.day).round(2).to_f
         
     | 
| 
      
 99 
     | 
    
         
            +
             
     | 
| 
      
 100 
     | 
    
         
            +
                    @schedule[payment.date] = {
         
     | 
| 
      
 101 
     | 
    
         
            +
                      payment: pmt,
         
     | 
| 
      
 102 
     | 
    
         
            +
                      interest: int,
         
     | 
| 
      
 103 
     | 
    
         
            +
                      principal: princ,
         
     | 
| 
      
 104 
     | 
    
         
            +
                      balance: bal
         
     | 
| 
      
 105 
     | 
    
         
            +
                    }
         
     | 
| 
      
 106 
     | 
    
         
            +
                  end
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
                  @schedule
         
     | 
| 
      
 109 
     | 
    
         
            +
                end
         
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
                private
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
                def interim_interest
         
     | 
| 
      
 114 
     | 
    
         
            +
                  return D('0') if @closing_date == @first_payment_due
         
     | 
| 
      
 115 
     | 
    
         
            +
                  return D('0') if @closing_date == (@first_payment_due - 30.days)
         
     | 
| 
      
 116 
     | 
    
         
            +
             
     | 
| 
      
 117 
     | 
    
         
            +
                  Amortization.interest(@principal, @rate.daily) * interim_days
         
     | 
| 
      
 118 
     | 
    
         
            +
                end
         
     | 
| 
      
 119 
     | 
    
         
            +
             
     | 
| 
      
 120 
     | 
    
         
            +
                def interim_days
         
     | 
| 
      
 121 
     | 
    
         
            +
                  return D('0') if @first_payment_due == @closing_date
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
                  odd_days = (@first_payment_due - 30.days - @closing_date).to_i
         
     | 
| 
      
 124 
     | 
    
         
            +
             
     | 
| 
      
 125 
     | 
    
         
            +
                  raise NotImplementedError, "Short periods are not yet implemented!" unless odd_days >= 0
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
                  odd_days.positive? ? odd_days : (30 + odd_days) - 30
         
     | 
| 
      
 128 
     | 
    
         
            +
                end
         
     | 
| 
      
 129 
     | 
    
         
            +
              end
         
     | 
| 
      
 130 
     | 
    
         
            +
            end
         
     | 
| 
      
 131 
     | 
    
         
            +
             
     | 
| 
      
 132 
     | 
    
         
            +
            class Numeric
         
     | 
| 
      
 133 
     | 
    
         
            +
              # @see Amortization#new
         
     | 
| 
      
 134 
     | 
    
         
            +
              # @api public
         
     | 
| 
      
 135 
     | 
    
         
            +
              def amortize(rate, opt = {})
         
     | 
| 
      
 136 
     | 
    
         
            +
                Financier::Amortization.new(self, opt)
         
     | 
| 
      
 137 
     | 
    
         
            +
              end
         
     | 
| 
      
 138 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,50 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Financier
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Ledger
         
     | 
| 
      
 3 
     | 
    
         
            +
                attr_reader :transactions
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                def initialize(*transactions)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  send(:transactions=, *transactions)
         
     | 
| 
      
 7 
     | 
    
         
            +
                end
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                def transactions=(*transactions)
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @transactions = []
         
     | 
| 
      
 11 
     | 
    
         
            +
                  transactions.flatten.each do |transaction|
         
     | 
| 
      
 12 
     | 
    
         
            +
                    send(:<<, transaction)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  end
         
     | 
| 
      
 14 
     | 
    
         
            +
                  @transactions
         
     | 
| 
      
 15 
     | 
    
         
            +
                end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                def <<(transaction)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  transaction = Transaction.new(transaction.to_s) unless
         
     | 
| 
      
 19 
     | 
    
         
            +
                    transaction.is_a?(Transaction)
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                  @transactions << transaction
         
     | 
| 
      
 22 
     | 
    
         
            +
                  @transactions.sort {|a, b| a.date <=> b.date }
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                  transaction
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
                alias_method :push, :<<
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                def credits
         
     | 
| 
      
 29 
     | 
    
         
            +
                  transactions.select(&:credit?)
         
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                def debits
         
     | 
| 
      
 33 
     | 
    
         
            +
                  transactions.select(&:debit?)
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                def balance(before: nil, after: nil, between: nil, within: nil)
         
     | 
| 
      
 37 
     | 
    
         
            +
                  transactions_to_sum = transactions.dup
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                  between = (within.first - 1.day)..(within.last + 1.day) if within
         
     | 
| 
      
 40 
     | 
    
         
            +
                  after, before = [between.first, between.last] if between
         
     | 
| 
      
 41 
     | 
    
         
            +
                  transactions_to_sum.select! { |t| t.before?(before) } if before
         
     | 
| 
      
 42 
     | 
    
         
            +
                  transactions_to_sum.select! { |t| t.after?(after) } if after
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                  transactions_to_sum
         
     | 
| 
      
 45 
     | 
    
         
            +
                    .collect(&:amount)
         
     | 
| 
      
 46 
     | 
    
         
            +
                    .sum
         
     | 
| 
      
 47 
     | 
    
         
            +
                    .round(2)
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,148 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Financier
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Rate
         
     | 
| 
      
 3 
     | 
    
         
            +
                class << self
         
     | 
| 
      
 4 
     | 
    
         
            +
                  def to_effective(rate, periods)
         
     | 
| 
      
 5 
     | 
    
         
            +
                    rate, periods = Flt::DecNum.new(rate.to_s), Flt::DecNum.new(periods.to_s)
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                    return rate.exp - 1 if periods.infinite?
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                    (1 + rate / periods) ** periods - 1
         
     | 
| 
      
 10 
     | 
    
         
            +
                  end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  def to_nominal(rate, periods)
         
     | 
| 
      
 13 
     | 
    
         
            +
                    rate, periods = Flt::DecNum.new(rate.to_s), Flt::DecNum.new(periods.to_s)
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                    return (rate + 1).log if periods.infinite?
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                    periods * ((1 + rate) ** (1 / periods) - 1)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  end
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                include Comparable
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                # Accepted rate types
         
     | 
| 
      
 24 
     | 
    
         
            +
                TYPES = { :apr       => "effective",
         
     | 
| 
      
 25 
     | 
    
         
            +
                          :apy       => "effective",
         
     | 
| 
      
 26 
     | 
    
         
            +
                          :effective => "effective",
         
     | 
| 
      
 27 
     | 
    
         
            +
                          :nominal   => "nominal"
         
     | 
| 
      
 28 
     | 
    
         
            +
                        }
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                # @return [Integer] the duration for which the rate is valid, in months
         
     | 
| 
      
 31 
     | 
    
         
            +
                # @api public
         
     | 
| 
      
 32 
     | 
    
         
            +
                attr_accessor :duration
         
     | 
| 
      
 33 
     | 
    
         
            +
                # @return [DecNum] the effective interest rate
         
     | 
| 
      
 34 
     | 
    
         
            +
                # @api public
         
     | 
| 
      
 35 
     | 
    
         
            +
                attr_reader :effective
         
     | 
| 
      
 36 
     | 
    
         
            +
                # @return [DecNum] the nominal interest rate
         
     | 
| 
      
 37 
     | 
    
         
            +
                # @api public
         
     | 
| 
      
 38 
     | 
    
         
            +
                attr_reader :nominal
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                # compare two Rates, using the effective rate
         
     | 
| 
      
 41 
     | 
    
         
            +
                # @return [Numeric] one of -1, 0, +1
         
     | 
| 
      
 42 
     | 
    
         
            +
                # @param [Rate] rate the comparison Rate
         
     | 
| 
      
 43 
     | 
    
         
            +
                # @example Which is better, a nominal rate of 15% compounded monthly, or 15.5% compounded semiannually?
         
     | 
| 
      
 44 
     | 
    
         
            +
                #   r1 = Rate.new(0.15, :nominal) #=> Rate.new(0.160755, :apr)
         
     | 
| 
      
 45 
     | 
    
         
            +
                #   r2 = Rate.new(0.155, :nominal, :compounds => :semiannually) #=> Rate.new(0.161006, :apr)
         
     | 
| 
      
 46 
     | 
    
         
            +
                #   r1 <=> r2 #=> -1
         
     | 
| 
      
 47 
     | 
    
         
            +
                # @api public
         
     | 
| 
      
 48 
     | 
    
         
            +
                def <=>(rate)
         
     | 
| 
      
 49 
     | 
    
         
            +
                  @effective <=> rate.effective
         
     | 
| 
      
 50 
     | 
    
         
            +
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                # (see #effective)
         
     | 
| 
      
 53 
     | 
    
         
            +
                # @api public
         
     | 
| 
      
 54 
     | 
    
         
            +
                def apr
         
     | 
| 
      
 55 
     | 
    
         
            +
                  self.effective
         
     | 
| 
      
 56 
     | 
    
         
            +
                end
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
                # (see #effective)
         
     | 
| 
      
 59 
     | 
    
         
            +
                # @api public
         
     | 
| 
      
 60 
     | 
    
         
            +
                def apy
         
     | 
| 
      
 61 
     | 
    
         
            +
                  self.effective
         
     | 
| 
      
 62 
     | 
    
         
            +
                end
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
                # a convenience method which sets the value of @periods
         
     | 
| 
      
 65 
     | 
    
         
            +
                # @return none
         
     | 
| 
      
 66 
     | 
    
         
            +
                # @param [Symbol, Numeric] input the compounding frequency
         
     | 
| 
      
 67 
     | 
    
         
            +
                # @raise [ArgumentError] if input is not an accepted keyword or Numeric
         
     | 
| 
      
 68 
     | 
    
         
            +
                # @api private
         
     | 
| 
      
 69 
     | 
    
         
            +
                def compounds=(input)
         
     | 
| 
      
 70 
     | 
    
         
            +
                  @periods = case input
         
     | 
| 
      
 71 
     | 
    
         
            +
                             when :annually     then Flt::DecNum.new(1)
         
     | 
| 
      
 72 
     | 
    
         
            +
                             when :continuously then Flt::DecNum.infinity
         
     | 
| 
      
 73 
     | 
    
         
            +
                             when :daily        then Flt::DecNum.new(365)
         
     | 
| 
      
 74 
     | 
    
         
            +
                             when :monthly      then Flt::DecNum.new(12)
         
     | 
| 
      
 75 
     | 
    
         
            +
                             when :quarterly    then Flt::DecNum.new(4)
         
     | 
| 
      
 76 
     | 
    
         
            +
                             when :semiannually then Flt::DecNum.new(2)
         
     | 
| 
      
 77 
     | 
    
         
            +
                             when Numeric       then Flt::DecNum.new(input.to_s)
         
     | 
| 
      
 78 
     | 
    
         
            +
                             else raise ArgumentError
         
     | 
| 
      
 79 
     | 
    
         
            +
                             end
         
     | 
| 
      
 80 
     | 
    
         
            +
                end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
                # set the effective interest rate
         
     | 
| 
      
 83 
     | 
    
         
            +
                # @return none
         
     | 
| 
      
 84 
     | 
    
         
            +
                # @param [DecNum] rate the effective interest rate
         
     | 
| 
      
 85 
     | 
    
         
            +
                # @api private
         
     | 
| 
      
 86 
     | 
    
         
            +
                def effective=(rate)
         
     | 
| 
      
 87 
     | 
    
         
            +
                  @effective = Flt::DecNum.new(rate.to_s)
         
     | 
| 
      
 88 
     | 
    
         
            +
                  @nominal = Rate.to_nominal(rate, @periods)
         
     | 
| 
      
 89 
     | 
    
         
            +
                end
         
     | 
| 
      
 90 
     | 
    
         
            +
             
     | 
| 
      
 91 
     | 
    
         
            +
                # create a new Rate instance
         
     | 
| 
      
 92 
     | 
    
         
            +
                # @return [Rate]
         
     | 
| 
      
 93 
     | 
    
         
            +
                # @param [Numeric] rate the decimal value of the interest rate
         
     | 
| 
      
 94 
     | 
    
         
            +
                # @param [Symbol] type a valid {TYPES rate type}
         
     | 
| 
      
 95 
     | 
    
         
            +
                # @param [optional, Hash] opts set optional attributes
         
     | 
| 
      
 96 
     | 
    
         
            +
                # @option opts [String] :duration a time interval for which the rate is valid
         
     | 
| 
      
 97 
     | 
    
         
            +
                # @option opts [String] :compounds (:monthly) the number of compounding periods per year
         
     | 
| 
      
 98 
     | 
    
         
            +
                # @example create a 3.5% APR rate
         
     | 
| 
      
 99 
     | 
    
         
            +
                #   Rate.new(0.035, :apr) #=> Rate(0.035, :apr)
         
     | 
| 
      
 100 
     | 
    
         
            +
                # @see http://en.wikipedia.org/wiki/Effective_interest_rate
         
     | 
| 
      
 101 
     | 
    
         
            +
                # @see http://en.wikipedia.org/wiki/Nominal_interest_rate
         
     | 
| 
      
 102 
     | 
    
         
            +
                # @api public
         
     | 
| 
      
 103 
     | 
    
         
            +
                def initialize(rate, type, opts={})
         
     | 
| 
      
 104 
     | 
    
         
            +
                  # Default monthly compounding.
         
     | 
| 
      
 105 
     | 
    
         
            +
                  opts = { :compounds => :monthly }.merge opts
         
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
      
 107 
     | 
    
         
            +
                  # Set optional attributes..
         
     | 
| 
      
 108 
     | 
    
         
            +
                  opts.each do |key, value|
         
     | 
| 
      
 109 
     | 
    
         
            +
                    send("#{key}=", value)
         
     | 
| 
      
 110 
     | 
    
         
            +
                  end
         
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
                  # Set the rate in the proper way, based on the value of type.
         
     | 
| 
      
 113 
     | 
    
         
            +
                  begin
         
     | 
| 
      
 114 
     | 
    
         
            +
                    send("#{TYPES.fetch(type)}=", Flt::DecNum.new(rate.to_s))
         
     | 
| 
      
 115 
     | 
    
         
            +
                  rescue KeyError
         
     | 
| 
      
 116 
     | 
    
         
            +
                    raise ArgumentError, "type must be one of #{TYPES.keys.join(', ')}", caller
         
     | 
| 
      
 117 
     | 
    
         
            +
                  end
         
     | 
| 
      
 118 
     | 
    
         
            +
                end
         
     | 
| 
      
 119 
     | 
    
         
            +
             
     | 
| 
      
 120 
     | 
    
         
            +
                def inspect
         
     | 
| 
      
 121 
     | 
    
         
            +
                  "Rate.new(#{self.apr.round(6)}, :apr)"
         
     | 
| 
      
 122 
     | 
    
         
            +
                end
         
     | 
| 
      
 123 
     | 
    
         
            +
             
     | 
| 
      
 124 
     | 
    
         
            +
                # @return [DecNum] the monthly effective interest rate
         
     | 
| 
      
 125 
     | 
    
         
            +
                # @example
         
     | 
| 
      
 126 
     | 
    
         
            +
                #   rate = Rate.new(0.15, :nominal)
         
     | 
| 
      
 127 
     | 
    
         
            +
                #   rate.apr.round(6) #=> DecNum('0.160755')
         
     | 
| 
      
 128 
     | 
    
         
            +
                #   rate.monthly.round(6) #=> DecNum('0.013396')
         
     | 
| 
      
 129 
     | 
    
         
            +
                # @api public
         
     | 
| 
      
 130 
     | 
    
         
            +
                def monthly
         
     | 
| 
      
 131 
     | 
    
         
            +
                  (self.effective / 12).round(15)
         
     | 
| 
      
 132 
     | 
    
         
            +
                end
         
     | 
| 
      
 133 
     | 
    
         
            +
             
     | 
| 
      
 134 
     | 
    
         
            +
                def daily
         
     | 
| 
      
 135 
     | 
    
         
            +
                  # TODO - Add spec
         
     | 
| 
      
 136 
     | 
    
         
            +
                  (self.effective / 360).round(15)
         
     | 
| 
      
 137 
     | 
    
         
            +
                end
         
     | 
| 
      
 138 
     | 
    
         
            +
             
     | 
| 
      
 139 
     | 
    
         
            +
                # set the nominal interest rate
         
     | 
| 
      
 140 
     | 
    
         
            +
                # @return none
         
     | 
| 
      
 141 
     | 
    
         
            +
                # @param [DecNum] rate the nominal interest rate
         
     | 
| 
      
 142 
     | 
    
         
            +
                # @api private
         
     | 
| 
      
 143 
     | 
    
         
            +
                def nominal=(rate)
         
     | 
| 
      
 144 
     | 
    
         
            +
                  @nominal = Flt::DecNum.new(rate.to_s)
         
     | 
| 
      
 145 
     | 
    
         
            +
                  @effective = Rate.to_effective(rate, @periods)
         
     | 
| 
      
 146 
     | 
    
         
            +
                end
         
     | 
| 
      
 147 
     | 
    
         
            +
              end
         
     | 
| 
      
 148 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,47 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module Financier
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Transaction
         
     | 
| 
      
 3 
     | 
    
         
            +
                attr_reader :amount
         
     | 
| 
      
 4 
     | 
    
         
            +
                attr_reader :date
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                def initialize(amount, date = Date[Time.now])
         
     | 
| 
      
 7 
     | 
    
         
            +
                  send(:amount=, amount)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  send(:date=, date)
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                def amount=(value)
         
     | 
| 
      
 12 
     | 
    
         
            +
                  @amount = Flt::DecNum.new(value.to_s).round(2)
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                def credit?
         
     | 
| 
      
 16 
     | 
    
         
            +
                  amount.positive?
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                def date=(value)
         
     | 
| 
      
 20 
     | 
    
         
            +
                  @date = value.to_date
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                def on?(other_date)
         
     | 
| 
      
 24 
     | 
    
         
            +
                  date === other_date.to_date
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                def before?(other_date)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  date < other_date.to_date
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                def after?(other_date)
         
     | 
| 
      
 32 
     | 
    
         
            +
                  date > other_date.to_date
         
     | 
| 
      
 33 
     | 
    
         
            +
                end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                def debit?
         
     | 
| 
      
 36 
     | 
    
         
            +
                  amount.negative?
         
     | 
| 
      
 37 
     | 
    
         
            +
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                def zero?
         
     | 
| 
      
 40 
     | 
    
         
            +
                  amount.zero?
         
     | 
| 
      
 41 
     | 
    
         
            +
                end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                def to_s
         
     | 
| 
      
 44 
     | 
    
         
            +
                  amount.to_s
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
              end
         
     | 
| 
      
 47 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/financier.rb
    ADDED
    
    | 
         @@ -0,0 +1,15 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'active_support/all'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'chronic'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'flt'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require 'flt/d'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            require 'financier/amortization'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'financier/date'
         
     | 
| 
      
 8 
     | 
    
         
            +
            require 'financier/ledger'
         
     | 
| 
      
 9 
     | 
    
         
            +
            require 'financier/rate'
         
     | 
| 
      
 10 
     | 
    
         
            +
            require 'financier/transaction'
         
     | 
| 
      
 11 
     | 
    
         
            +
            require 'financier/version'
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            module Financier
         
     | 
| 
      
 14 
     | 
    
         
            +
              class Error < StandardError; end
         
     | 
| 
      
 15 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,11 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative '../spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe Financier::Amortization do
         
     | 
| 
      
 4 
     | 
    
         
            +
              describe 'payments' do
         
     | 
| 
      
 5 
     | 
    
         
            +
                context 'no odd days' do
         
     | 
| 
      
 6 
     | 
    
         
            +
                  it 'calculates the monthly payment' do
         
     | 
| 
      
 7 
     | 
    
         
            +
                    expect(Financier::Amortization.payment(10000, (0.1499 / 12), 84)).to eq(-192.91)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  end
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
              end
         
     | 
| 
      
 11 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,28 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative '../spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe Financier::Date do
         
     | 
| 
      
 4 
     | 
    
         
            +
              let(:date_string) { Time.now.strftime('%Y-%m-%d') }
         
     | 
| 
      
 5 
     | 
    
         
            +
              let(:date) { ::Date.today }
         
     | 
| 
      
 6 
     | 
    
         
            +
              let(:time) { Time.now }
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              it 'parses dates from strings' do
         
     | 
| 
      
 9 
     | 
    
         
            +
                expect(Financier::Date[date_string]).to be_a(::Date)
         
     | 
| 
      
 10 
     | 
    
         
            +
                expect(Financier::Date[date_string]).to eq(::Date.today)
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
              it 'parses dates from dates' do
         
     | 
| 
      
 14 
     | 
    
         
            +
                expect(Financier::Date[date]).to be_a(::Date)
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              it 'parses dates from times' do
         
     | 
| 
      
 18 
     | 
    
         
            +
                expect(Financier::Date[time]).to be_a(::Date)
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              it 'returns nil for nil values by default' do
         
     | 
| 
      
 22 
     | 
    
         
            +
                expect(Financier::Date[nil]).to be(nil)
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
              it 'returns specified default for nil values' do
         
     | 
| 
      
 26 
     | 
    
         
            +
                expect(Financier::Date[time]).to be_a(::Date)
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,86 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative '../spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe Financier::Ledger do
         
     | 
| 
      
 4 
     | 
    
         
            +
              let(:transaction) { Financier::Transaction }
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              subject do
         
     | 
| 
      
 7 
     | 
    
         
            +
                Financier::Ledger.new(
         
     | 
| 
      
 8 
     | 
    
         
            +
                  transaction.new(500, 1.year.ago),
         
     | 
| 
      
 9 
     | 
    
         
            +
                  transaction.new(-150, 6.months.ago),
         
     | 
| 
      
 10 
     | 
    
         
            +
                  transaction.new(-250, 2.weeks.ago)
         
     | 
| 
      
 11 
     | 
    
         
            +
                )
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
              describe 'transactions' do
         
     | 
| 
      
 15 
     | 
    
         
            +
                describe '#<<' do
         
     | 
| 
      
 16 
     | 
    
         
            +
                  before { subject << transaction.new(2) }
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                  it 'adds a transaction' do
         
     | 
| 
      
 19 
     | 
    
         
            +
                    expect(subject.transactions.length).to eq(4)        
         
     | 
| 
      
 20 
     | 
    
         
            +
                  end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                  it 'is aliased as push' do
         
     | 
| 
      
 23 
     | 
    
         
            +
                    expect(subject).to respond_to(:push)
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                  it 'coerces non-transactions' do
         
     | 
| 
      
 27 
     | 
    
         
            +
                    subject << 120
         
     | 
| 
      
 28 
     | 
    
         
            +
                    expect(subject.transactions.last).to be_a(transaction)
         
     | 
| 
      
 29 
     | 
    
         
            +
                    expect(subject.transactions.last.amount).to eq(120)
         
     | 
| 
      
 30 
     | 
    
         
            +
                  end
         
     | 
| 
      
 31 
     | 
    
         
            +
                end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                describe '#transactions' do
         
     | 
| 
      
 34 
     | 
    
         
            +
                  it 'returns the transactions' do
         
     | 
| 
      
 35 
     | 
    
         
            +
                    expect(subject.transactions.length).to eq(3)
         
     | 
| 
      
 36 
     | 
    
         
            +
                  end
         
     | 
| 
      
 37 
     | 
    
         
            +
                end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                describe '#credits' do
         
     | 
| 
      
 40 
     | 
    
         
            +
                  it 'returns the credit transactions' do
         
     | 
| 
      
 41 
     | 
    
         
            +
                    expect(subject.credits.length).to eq(1)
         
     | 
| 
      
 42 
     | 
    
         
            +
                  end
         
     | 
| 
      
 43 
     | 
    
         
            +
                end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
                describe '#debits' do
         
     | 
| 
      
 46 
     | 
    
         
            +
                  it 'returns the debit transactions' do
         
     | 
| 
      
 47 
     | 
    
         
            +
                    expect(subject.debits.length).to eq(2)
         
     | 
| 
      
 48 
     | 
    
         
            +
                  end
         
     | 
| 
      
 49 
     | 
    
         
            +
                end
         
     | 
| 
      
 50 
     | 
    
         
            +
              end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
              describe 'coercion' do
         
     | 
| 
      
 53 
     | 
    
         
            +
              end
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
              describe 'calculation' do
         
     | 
| 
      
 56 
     | 
    
         
            +
                describe '#balance' do
         
     | 
| 
      
 57 
     | 
    
         
            +
                  it 'sums all transactions' do
         
     | 
| 
      
 58 
     | 
    
         
            +
                    expect(subject.balance).to eq(100)
         
     | 
| 
      
 59 
     | 
    
         
            +
                  end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                  describe 'before' do
         
     | 
| 
      
 62 
     | 
    
         
            +
                    it 'sums transactions before date' do
         
     | 
| 
      
 63 
     | 
    
         
            +
                      expect(subject.balance(before: 4.weeks.ago)).to eq(350)
         
     | 
| 
      
 64 
     | 
    
         
            +
                    end
         
     | 
| 
      
 65 
     | 
    
         
            +
                  end
         
     | 
| 
      
 66 
     | 
    
         
            +
             
     | 
| 
      
 67 
     | 
    
         
            +
                  describe 'after' do
         
     | 
| 
      
 68 
     | 
    
         
            +
                    it 'sums transactions after date' do
         
     | 
| 
      
 69 
     | 
    
         
            +
                      expect(subject.balance(after: 7.months.ago)).to eq(-400)
         
     | 
| 
      
 70 
     | 
    
         
            +
                    end
         
     | 
| 
      
 71 
     | 
    
         
            +
                  end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                  describe 'between' do
         
     | 
| 
      
 74 
     | 
    
         
            +
                    it 'sums transactions between dates' do
         
     | 
| 
      
 75 
     | 
    
         
            +
                      expect(subject.balance(between: 7.months.ago..4.weeks.ago)).to eq(-150)
         
     | 
| 
      
 76 
     | 
    
         
            +
                    end
         
     | 
| 
      
 77 
     | 
    
         
            +
                  end
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                  describe 'within' do
         
     | 
| 
      
 80 
     | 
    
         
            +
                    it 'sums transactions within dates' do
         
     | 
| 
      
 81 
     | 
    
         
            +
                      expect(subject.balance(within: subject.transactions.first.date..subject.transactions[1].date)).to eq(350)
         
     | 
| 
      
 82 
     | 
    
         
            +
                    end
         
     | 
| 
      
 83 
     | 
    
         
            +
                  end
         
     | 
| 
      
 84 
     | 
    
         
            +
                end
         
     | 
| 
      
 85 
     | 
    
         
            +
              end
         
     | 
| 
      
 86 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,188 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative '../spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            shared_examples_for 'does not raise error' do
         
     | 
| 
      
 4 
     | 
    
         
            +
              it 'does not raise an error' do
         
     | 
| 
      
 5 
     | 
    
         
            +
                expect { subject }.to_not raise_error
         
     | 
| 
      
 6 
     | 
    
         
            +
              end
         
     | 
| 
      
 7 
     | 
    
         
            +
            end
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            describe Financier::Rate do
         
     | 
| 
      
 10 
     | 
    
         
            +
              let(:test_rate)  { 0.15 }
         
     | 
| 
      
 11 
     | 
    
         
            +
              let(:compounding_Period) { :monthly }
         
     | 
| 
      
 12 
     | 
    
         
            +
              let(:type) { :nominal }
         
     | 
| 
      
 13 
     | 
    
         
            +
              let(:opts) { nil }
         
     | 
| 
      
 14 
     | 
    
         
            +
              let(:rate) { Financier::Rate.new(test_rate, type) }
         
     | 
| 
      
 15 
     | 
    
         
            +
              
         
     | 
| 
      
 16 
     | 
    
         
            +
              subject { rate }
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
              context 'when given a duration' do
         
     | 
| 
      
 19 
     | 
    
         
            +
                let(:type) { :effective }
         
     | 
| 
      
 20 
     | 
    
         
            +
                let(:rate) { Financier::Rate.new(test_rate, type, duration: 360) }
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                subject { rate.duration }
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                it { is_expected.to eql 360 }
         
     | 
| 
      
 25 
     | 
    
         
            +
              end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
              describe 'when compared to another interest rate' do
         
     | 
| 
      
 28 
     | 
    
         
            +
                let(:r1) { rate }
         
     | 
| 
      
 29 
     | 
    
         
            +
                let(:r2) { Financier::Rate.new(compared_rate, type) }
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                subject { r1 <=> r2 }
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                context 'when the other rate is smaller' do
         
     | 
| 
      
 34 
     | 
    
         
            +
                  let(:compared_rate) { test_rate - 0.01}
         
     | 
| 
      
 35 
     | 
    
         
            +
                  it { is_expected.to eql 1 }
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                context 'when the other rate is the same' do
         
     | 
| 
      
 39 
     | 
    
         
            +
                  let(:compared_rate) { test_rate }
         
     | 
| 
      
 40 
     | 
    
         
            +
                  it { is_expected.to eql 0 }
         
     | 
| 
      
 41 
     | 
    
         
            +
                end
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
                context 'when the other rate is bigger' do
         
     | 
| 
      
 44 
     | 
    
         
            +
                  let(:compared_rate) { test_rate + 0.01 }
         
     | 
| 
      
 45 
     | 
    
         
            +
                  it { is_expected.to eql -1 }
         
     | 
| 
      
 46 
     | 
    
         
            +
                  
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
              end
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
              describe "should convert to a monthly value" do
         
     | 
| 
      
 51 
     | 
    
         
            +
                let(:type) { :effective }
         
     | 
| 
      
 52 
     | 
    
         
            +
                let(:test_rate) { 0.0375 }
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                subject { rate.monthly }
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                it { is_expected.to eql D('0.003125') }
         
     | 
| 
      
 57 
     | 
    
         
            +
              end
         
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
              describe 'converts effective interest rates to nominal' do
         
     | 
| 
      
 60 
     | 
    
         
            +
                context 'when the rates compounding period is finite' do
         
     | 
| 
      
 61 
     | 
    
         
            +
                  subject { Financier::Rate.to_nominal(D('0.0375'), 12).round(5) }
         
     | 
| 
      
 62 
     | 
    
         
            +
             
     | 
| 
      
 63 
     | 
    
         
            +
                  it { is_expected.to eql D('0.03687') }
         
     | 
| 
      
 64 
     | 
    
         
            +
                end
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
                context 'when the rate is continuously compounding' do
         
     | 
| 
      
 67 
     | 
    
         
            +
                  subject { Financier::Rate.to_nominal(D('0.0375'), Flt::DecNum.infinity).round(5) }
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                  it { is_expected.to eql D('0.03681') }
         
     | 
| 
      
 70 
     | 
    
         
            +
                end
         
     | 
| 
      
 71 
     | 
    
         
            +
              end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
              context 'type is an unknown value' do
         
     | 
| 
      
 74 
     | 
    
         
            +
                let(:type) { :foo }
         
     | 
| 
      
 75 
     | 
    
         
            +
             
     | 
| 
      
 76 
     | 
    
         
            +
                it 'should raise an ArgumentError' do
         
     | 
| 
      
 77 
     | 
    
         
            +
                  expect { subject }.to raise_error ArgumentError
         
     | 
| 
      
 78 
     | 
    
         
            +
                end
         
     | 
| 
      
 79 
     | 
    
         
            +
              end
         
     | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
      
 81 
     | 
    
         
            +
              context 'with compounding period' do
         
     | 
| 
      
 82 
     | 
    
         
            +
                let(:rate) { Financier::Rate.new(test_rate, type, compounds: compounding_period) }
         
     | 
| 
      
 83 
     | 
    
         
            +
                
         
     | 
| 
      
 84 
     | 
    
         
            +
                describe 'anually' do
         
     | 
| 
      
 85 
     | 
    
         
            +
                  let(:compounding_period) { :annually }
         
     | 
| 
      
 86 
     | 
    
         
            +
                  it_behaves_like 'does not raise error'
         
     | 
| 
      
 87 
     | 
    
         
            +
                end
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
                describe 'continuously' do
         
     | 
| 
      
 90 
     | 
    
         
            +
                  let(:compounding_period) { :continuously }
         
     | 
| 
      
 91 
     | 
    
         
            +
                  it_behaves_like 'does not raise error'
         
     | 
| 
      
 92 
     | 
    
         
            +
                end
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
                describe 'daily' do
         
     | 
| 
      
 95 
     | 
    
         
            +
                  let(:compounding_period) { :daily }
         
     | 
| 
      
 96 
     | 
    
         
            +
                  it_behaves_like 'does not raise error'
         
     | 
| 
      
 97 
     | 
    
         
            +
                end
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
                describe 'monthly' do
         
     | 
| 
      
 100 
     | 
    
         
            +
                  let(:compounding_period) { :monthly }
         
     | 
| 
      
 101 
     | 
    
         
            +
                  it_behaves_like 'does not raise error'
         
     | 
| 
      
 102 
     | 
    
         
            +
                end
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                describe 'quarterly' do
         
     | 
| 
      
 105 
     | 
    
         
            +
                  let(:compounding_period) { :quarterly }
         
     | 
| 
      
 106 
     | 
    
         
            +
                  it_behaves_like 'does not raise error'
         
     | 
| 
      
 107 
     | 
    
         
            +
                end
         
     | 
| 
      
 108 
     | 
    
         
            +
             
     | 
| 
      
 109 
     | 
    
         
            +
                describe 'semiannually' do
         
     | 
| 
      
 110 
     | 
    
         
            +
                  let(:compounding_period) { :semiannually }
         
     | 
| 
      
 111 
     | 
    
         
            +
                  it_behaves_like 'does not raise error'
         
     | 
| 
      
 112 
     | 
    
         
            +
                end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                describe 'Numeric' do
         
     | 
| 
      
 115 
     | 
    
         
            +
                  let(:compounding_period) { 7 }
         
     | 
| 
      
 116 
     | 
    
         
            +
                  it_behaves_like 'does not raise error'
         
     | 
| 
      
 117 
     | 
    
         
            +
                end
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
                describe 'unknown string' do
         
     | 
| 
      
 120 
     | 
    
         
            +
                  let(:compounding_period) { :foo }
         
     | 
| 
      
 121 
     | 
    
         
            +
                  it 'raises an error' do
         
     | 
| 
      
 122 
     | 
    
         
            +
                    expect { subject }.to raise_error ArgumentError
         
     | 
| 
      
 123 
     | 
    
         
            +
                  end
         
     | 
| 
      
 124 
     | 
    
         
            +
                end
         
     | 
| 
      
 125 
     | 
    
         
            +
              end
         
     | 
| 
      
 126 
     | 
    
         
            +
             
     | 
| 
      
 127 
     | 
    
         
            +
              describe '#inspect' do
         
     | 
| 
      
 128 
     | 
    
         
            +
                subject { rate.inspect }
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
      
 130 
     | 
    
         
            +
                it { is_expected.to be_a String }
         
     | 
| 
      
 131 
     | 
    
         
            +
                it { is_expected.to include ':apr' }
         
     | 
| 
      
 132 
     | 
    
         
            +
              end
         
     | 
| 
      
 133 
     | 
    
         
            +
             
     | 
| 
      
 134 
     | 
    
         
            +
              describe '#apr' do
         
     | 
| 
      
 135 
     | 
    
         
            +
                subject { rate.apr }
         
     | 
| 
      
 136 
     | 
    
         
            +
             
     | 
| 
      
 137 
     | 
    
         
            +
                it { is_expected.to eql rate.effective }
         
     | 
| 
      
 138 
     | 
    
         
            +
              end
         
     | 
| 
      
 139 
     | 
    
         
            +
             
     | 
| 
      
 140 
     | 
    
         
            +
              describe '#apy' do
         
     | 
| 
      
 141 
     | 
    
         
            +
                subject { rate.apy }
         
     | 
| 
      
 142 
     | 
    
         
            +
             
     | 
| 
      
 143 
     | 
    
         
            +
                it { is_expected.to eql rate.effective }
         
     | 
| 
      
 144 
     | 
    
         
            +
              end
         
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
      
 146 
     | 
    
         
            +
              describe "#effective" do
         
     | 
| 
      
 147 
     | 
    
         
            +
                context 'with compounding period' do
         
     | 
| 
      
 148 
     | 
    
         
            +
                  let(:rate) { Financier::Rate.new(test_rate, :nominal, compounds: compounding_period) }
         
     | 
| 
      
 149 
     | 
    
         
            +
             
     | 
| 
      
 150 
     | 
    
         
            +
                  subject { rate.effective.round(5) }
         
     | 
| 
      
 151 
     | 
    
         
            +
             
     | 
| 
      
 152 
     | 
    
         
            +
                  describe 'monthly' do
         
     | 
| 
      
 153 
     | 
    
         
            +
                    let(:compounding_period) { :monthly }
         
     | 
| 
      
 154 
     | 
    
         
            +
                    it { should == D('0.16075') }
         
     | 
| 
      
 155 
     | 
    
         
            +
                  end
         
     | 
| 
      
 156 
     | 
    
         
            +
             
     | 
| 
      
 157 
     | 
    
         
            +
                  describe 'annually' do
         
     | 
| 
      
 158 
     | 
    
         
            +
                    let(:compounding_period) { :annually }
         
     | 
| 
      
 159 
     | 
    
         
            +
                    it { should == D('0.15000') }
         
     | 
| 
      
 160 
     | 
    
         
            +
                  end
         
     | 
| 
      
 161 
     | 
    
         
            +
             
     | 
| 
      
 162 
     | 
    
         
            +
                  describe 'continuously' do
         
     | 
| 
      
 163 
     | 
    
         
            +
                    let(:compounding_period) { :continuously }
         
     | 
| 
      
 164 
     | 
    
         
            +
                    it { should == D('0.16183') }
         
     | 
| 
      
 165 
     | 
    
         
            +
                  end
         
     | 
| 
      
 166 
     | 
    
         
            +
             
     | 
| 
      
 167 
     | 
    
         
            +
                  describe 'daily' do
         
     | 
| 
      
 168 
     | 
    
         
            +
                    let(:compounding_period) { :daily }
         
     | 
| 
      
 169 
     | 
    
         
            +
                    it { should == D('0.16180') }
         
     | 
| 
      
 170 
     | 
    
         
            +
                  end
         
     | 
| 
      
 171 
     | 
    
         
            +
             
     | 
| 
      
 172 
     | 
    
         
            +
                  describe 'quarterly' do
         
     | 
| 
      
 173 
     | 
    
         
            +
                    let(:compounding_period) { :quarterly }
         
     | 
| 
      
 174 
     | 
    
         
            +
                    it { should == D('0.15865') }
         
     | 
| 
      
 175 
     | 
    
         
            +
                  end
         
     | 
| 
      
 176 
     | 
    
         
            +
             
     | 
| 
      
 177 
     | 
    
         
            +
                  describe 'semi-annually' do
         
     | 
| 
      
 178 
     | 
    
         
            +
                    let(:compounding_period) { :semiannually }
         
     | 
| 
      
 179 
     | 
    
         
            +
                    it { should == D('0.15563') }
         
     | 
| 
      
 180 
     | 
    
         
            +
                  end
         
     | 
| 
      
 181 
     | 
    
         
            +
             
     | 
| 
      
 182 
     | 
    
         
            +
                  describe 'Numeric' do
         
     | 
| 
      
 183 
     | 
    
         
            +
                    let(:compounding_period) { 7 }
         
     | 
| 
      
 184 
     | 
    
         
            +
                    it { should == D('0.15999') }
         
     | 
| 
      
 185 
     | 
    
         
            +
                  end
         
     | 
| 
      
 186 
     | 
    
         
            +
                end
         
     | 
| 
      
 187 
     | 
    
         
            +
              end
         
     | 
| 
      
 188 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,118 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative '../spec_helper'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe Financier::Transaction do
         
     | 
| 
      
 4 
     | 
    
         
            +
              subject { Financier::Transaction }
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              let(:transaction) { subject.new(1) }
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
              describe 'amount' do
         
     | 
| 
      
 9 
     | 
    
         
            +
                it 'is gettable' do
         
     | 
| 
      
 10 
     | 
    
         
            +
                  expect(transaction).to respond_to(:amount)
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                describe 'setting' do
         
     | 
| 
      
 14 
     | 
    
         
            +
                  let!(:old_amt) { transaction.instance_variable_get('@amount') }
         
     | 
| 
      
 15 
     | 
    
         
            +
                  let(:new_amt) { transaction.instance_variable_get('@amount') }
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  before { transaction.amount = 2 }
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
                  it 'sets the amount' do
         
     | 
| 
      
 20 
     | 
    
         
            +
                    expect(new_amt).to_not eq(old_amt)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                  it 'converts the amount to DecNum' do
         
     | 
| 
      
 24 
     | 
    
         
            +
                    expect(new_amt).to be_a(Flt::DecNum)
         
     | 
| 
      
 25 
     | 
    
         
            +
                  end
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
              describe 'date' do
         
     | 
| 
      
 30 
     | 
    
         
            +
                it 'is gettable' do
         
     | 
| 
      
 31 
     | 
    
         
            +
                  expect(transaction).to respond_to(:date)
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                describe 'setting' do
         
     | 
| 
      
 35 
     | 
    
         
            +
                  let!(:old_date) { transaction.instance_variable_get('@date') }
         
     | 
| 
      
 36 
     | 
    
         
            +
                  let(:new_date) { transaction.instance_variable_get('@date') }
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                  before { transaction.date = 1.day.ago }
         
     | 
| 
      
 39 
     | 
    
         
            +
             
     | 
| 
      
 40 
     | 
    
         
            +
                  it 'sets the date' do
         
     | 
| 
      
 41 
     | 
    
         
            +
                    expect(new_date).to_not eq(old_date)
         
     | 
| 
      
 42 
     | 
    
         
            +
                  end
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
                  it 'converts the date to a Date' do
         
     | 
| 
      
 45 
     | 
    
         
            +
                    expect(new_date).to be_a(Date)
         
     | 
| 
      
 46 
     | 
    
         
            +
                  end
         
     | 
| 
      
 47 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                describe '#on?' do
         
     | 
| 
      
 50 
     | 
    
         
            +
                  it 'returns appropriate responses' do
         
     | 
| 
      
 51 
     | 
    
         
            +
                    expect(transaction.on?(1.day.ago)).to be false
         
     | 
| 
      
 52 
     | 
    
         
            +
                    expect(transaction.on?(Date.today)).to be true
         
     | 
| 
      
 53 
     | 
    
         
            +
                    expect(transaction.on?(1.day.from_now)).to be false
         
     | 
| 
      
 54 
     | 
    
         
            +
                  end
         
     | 
| 
      
 55 
     | 
    
         
            +
                end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                describe '#before?' do
         
     | 
| 
      
 58 
     | 
    
         
            +
                  it 'returns appropriate responses' do
         
     | 
| 
      
 59 
     | 
    
         
            +
                    expect(transaction.before?(1.day.ago)).to be false
         
     | 
| 
      
 60 
     | 
    
         
            +
                    expect(transaction.before?(Date.today)).to be false
         
     | 
| 
      
 61 
     | 
    
         
            +
                    expect(transaction.before?(1.day.from_now)).to be true
         
     | 
| 
      
 62 
     | 
    
         
            +
                  end
         
     | 
| 
      
 63 
     | 
    
         
            +
                end
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
                describe '#after?' do
         
     | 
| 
      
 66 
     | 
    
         
            +
                  it 'returns appropriate responses' do
         
     | 
| 
      
 67 
     | 
    
         
            +
                    expect(transaction.after?(1.day.ago)).to be true
         
     | 
| 
      
 68 
     | 
    
         
            +
                    expect(transaction.after?(Date.today)).to be false
         
     | 
| 
      
 69 
     | 
    
         
            +
                    expect(transaction.after?(1.day.from_now)).to be false
         
     | 
| 
      
 70 
     | 
    
         
            +
                  end
         
     | 
| 
      
 71 
     | 
    
         
            +
                end
         
     | 
| 
      
 72 
     | 
    
         
            +
              end
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
              describe 'credit/debit/zero' do
         
     | 
| 
      
 75 
     | 
    
         
            +
                let(:credit) { subject.new(123) }
         
     | 
| 
      
 76 
     | 
    
         
            +
                let(:debit) { subject.new(-123) }
         
     | 
| 
      
 77 
     | 
    
         
            +
                let(:zero) { subject.new(0) }
         
     | 
| 
      
 78 
     | 
    
         
            +
                let(:non_zero) { credit }
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
                describe '#credit?' do
         
     | 
| 
      
 81 
     | 
    
         
            +
                  it 'is true for positive amounts' do
         
     | 
| 
      
 82 
     | 
    
         
            +
                    expect(credit.credit?).to be true
         
     | 
| 
      
 83 
     | 
    
         
            +
                  end
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                  it 'is false for negative amounts' do
         
     | 
| 
      
 86 
     | 
    
         
            +
                    expect(debit.credit?).to be false
         
     | 
| 
      
 87 
     | 
    
         
            +
                  end
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
                  it 'is false for zero amounts' do
         
     | 
| 
      
 90 
     | 
    
         
            +
                    expect(zero.credit?).to be false
         
     | 
| 
      
 91 
     | 
    
         
            +
                  end
         
     | 
| 
      
 92 
     | 
    
         
            +
                end
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
                describe '#debit?' do
         
     | 
| 
      
 95 
     | 
    
         
            +
                  it 'is true for negative amounts' do
         
     | 
| 
      
 96 
     | 
    
         
            +
                    expect(debit.debit?).to be true
         
     | 
| 
      
 97 
     | 
    
         
            +
                  end
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
                  it 'is false for positive amounts' do
         
     | 
| 
      
 100 
     | 
    
         
            +
                    expect(credit.debit?).to be false
         
     | 
| 
      
 101 
     | 
    
         
            +
                  end
         
     | 
| 
      
 102 
     | 
    
         
            +
             
     | 
| 
      
 103 
     | 
    
         
            +
                  it 'is false for zero amounts' do
         
     | 
| 
      
 104 
     | 
    
         
            +
                    expect(zero.debit?).to be false
         
     | 
| 
      
 105 
     | 
    
         
            +
                  end
         
     | 
| 
      
 106 
     | 
    
         
            +
                end
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
                describe '#zero?' do
         
     | 
| 
      
 109 
     | 
    
         
            +
                  it 'is true for zero amounts' do
         
     | 
| 
      
 110 
     | 
    
         
            +
                    expect(zero.zero?).to be true
         
     | 
| 
      
 111 
     | 
    
         
            +
                  end
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
                  it 'is false for non-zero amounts' do
         
     | 
| 
      
 114 
     | 
    
         
            +
                    expect(non_zero.zero?).to be false
         
     | 
| 
      
 115 
     | 
    
         
            +
                  end
         
     | 
| 
      
 116 
     | 
    
         
            +
                end
         
     | 
| 
      
 117 
     | 
    
         
            +
              end
         
     | 
| 
      
 118 
     | 
    
         
            +
            end
         
     | 
    
        data/spec/spec_helper.rb
    ADDED
    
    | 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative '../lib/financier'
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,176 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: financier
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 0.1.0
         
     | 
| 
      
 5 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 6 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 7 
     | 
    
         
            +
            - Ethan Barron
         
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 9 
     | 
    
         
            +
            bindir: exe
         
     | 
| 
      
 10 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2019-04-29 00:00:00.000000000 Z
         
     | 
| 
      
 12 
     | 
    
         
            +
            dependencies:
         
     | 
| 
      
 13 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 14 
     | 
    
         
            +
              name: activesupport
         
     | 
| 
      
 15 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 16 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 17 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 18 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 19 
     | 
    
         
            +
                    version: 5.2.3
         
     | 
| 
      
 20 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 21 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 22 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 23 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 24 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 25 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 26 
     | 
    
         
            +
                    version: 5.2.3
         
     | 
| 
      
 27 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 28 
     | 
    
         
            +
              name: chronic
         
     | 
| 
      
 29 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 30 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 31 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 32 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 33 
     | 
    
         
            +
                    version: 0.10.2
         
     | 
| 
      
 34 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 35 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 36 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 37 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 38 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 39 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 40 
     | 
    
         
            +
                    version: 0.10.2
         
     | 
| 
      
 41 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 42 
     | 
    
         
            +
              name: flt
         
     | 
| 
      
 43 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 44 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 45 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 46 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 47 
     | 
    
         
            +
                    version: 1.5.0
         
     | 
| 
      
 48 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 49 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 50 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 51 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 52 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 53 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 54 
     | 
    
         
            +
                    version: 1.5.0
         
     | 
| 
      
 55 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 56 
     | 
    
         
            +
              name: bundler
         
     | 
| 
      
 57 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 58 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 59 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 60 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 61 
     | 
    
         
            +
                    version: 2.0.1
         
     | 
| 
      
 62 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 63 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 64 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 65 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 66 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 67 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 68 
     | 
    
         
            +
                    version: 2.0.1
         
     | 
| 
      
 69 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 70 
     | 
    
         
            +
              name: rake
         
     | 
| 
      
 71 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 72 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 73 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 74 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 75 
     | 
    
         
            +
                    version: '10.0'
         
     | 
| 
      
 76 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 77 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 78 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 79 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 80 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 81 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 82 
     | 
    
         
            +
                    version: '10.0'
         
     | 
| 
      
 83 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 84 
     | 
    
         
            +
              name: rspec
         
     | 
| 
      
 85 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 86 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 87 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 88 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 89 
     | 
    
         
            +
                    version: 3.8.0
         
     | 
| 
      
 90 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 91 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 92 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 93 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 94 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 95 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 96 
     | 
    
         
            +
                    version: 3.8.0
         
     | 
| 
      
 97 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 98 
     | 
    
         
            +
              name: rubocop
         
     | 
| 
      
 99 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 100 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 101 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 102 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 103 
     | 
    
         
            +
                    version: 0.67.2
         
     | 
| 
      
 104 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 105 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 106 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 107 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 108 
     | 
    
         
            +
                - - "~>"
         
     | 
| 
      
 109 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 110 
     | 
    
         
            +
                    version: 0.67.2
         
     | 
| 
      
 111 
     | 
    
         
            +
            description: Ruby gem to deal with financial calculations.
         
     | 
| 
      
 112 
     | 
    
         
            +
            email:
         
     | 
| 
      
 113 
     | 
    
         
            +
            - ethan.barron@kalidy.com
         
     | 
| 
      
 114 
     | 
    
         
            +
            executables:
         
     | 
| 
      
 115 
     | 
    
         
            +
            - financier
         
     | 
| 
      
 116 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 117 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 118 
     | 
    
         
            +
            files:
         
     | 
| 
      
 119 
     | 
    
         
            +
            - ".gitignore"
         
     | 
| 
      
 120 
     | 
    
         
            +
            - ".travis.yml"
         
     | 
| 
      
 121 
     | 
    
         
            +
            - Gemfile
         
     | 
| 
      
 122 
     | 
    
         
            +
            - LICENSE.txt
         
     | 
| 
      
 123 
     | 
    
         
            +
            - README.md
         
     | 
| 
      
 124 
     | 
    
         
            +
            - Rakefile
         
     | 
| 
      
 125 
     | 
    
         
            +
            - bin/console
         
     | 
| 
      
 126 
     | 
    
         
            +
            - bin/setup
         
     | 
| 
      
 127 
     | 
    
         
            +
            - exe/financier
         
     | 
| 
      
 128 
     | 
    
         
            +
            - financier.gemspec
         
     | 
| 
      
 129 
     | 
    
         
            +
            - lib/financier.rb
         
     | 
| 
      
 130 
     | 
    
         
            +
            - lib/financier/amortization.rb
         
     | 
| 
      
 131 
     | 
    
         
            +
            - lib/financier/date.rb
         
     | 
| 
      
 132 
     | 
    
         
            +
            - lib/financier/ledger.rb
         
     | 
| 
      
 133 
     | 
    
         
            +
            - lib/financier/rate.rb
         
     | 
| 
      
 134 
     | 
    
         
            +
            - lib/financier/transaction.rb
         
     | 
| 
      
 135 
     | 
    
         
            +
            - lib/financier/version.rb
         
     | 
| 
      
 136 
     | 
    
         
            +
            - spec/financier/amortization_spec.rb
         
     | 
| 
      
 137 
     | 
    
         
            +
            - spec/financier/date_spec.rb
         
     | 
| 
      
 138 
     | 
    
         
            +
            - spec/financier/ledger_spec.rb
         
     | 
| 
      
 139 
     | 
    
         
            +
            - spec/financier/rate_spec.rb
         
     | 
| 
      
 140 
     | 
    
         
            +
            - spec/financier/transaction_spec.rb
         
     | 
| 
      
 141 
     | 
    
         
            +
            - spec/financier_spec.rb
         
     | 
| 
      
 142 
     | 
    
         
            +
            - spec/spec_helper.rb
         
     | 
| 
      
 143 
     | 
    
         
            +
            homepage: https://rubygems.org/gems/financier
         
     | 
| 
      
 144 
     | 
    
         
            +
            licenses:
         
     | 
| 
      
 145 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 146 
     | 
    
         
            +
            metadata:
         
     | 
| 
      
 147 
     | 
    
         
            +
              allowed_push_host: https://rubygems.org
         
     | 
| 
      
 148 
     | 
    
         
            +
              homepage_uri: https://rubygems.org/gems/financier
         
     | 
| 
      
 149 
     | 
    
         
            +
              source_code_uri: https://github.com/Inkybro/financier
         
     | 
| 
      
 150 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 151 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 152 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 153 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 154 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 155 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 156 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 157 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 158 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 159 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 160 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 161 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 162 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 163 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 164 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 165 
     | 
    
         
            +
            rubygems_version: 3.0.3
         
     | 
| 
      
 166 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 167 
     | 
    
         
            +
            specification_version: 4
         
     | 
| 
      
 168 
     | 
    
         
            +
            summary: Provides handy financial calculators.
         
     | 
| 
      
 169 
     | 
    
         
            +
            test_files:
         
     | 
| 
      
 170 
     | 
    
         
            +
            - spec/financier/amortization_spec.rb
         
     | 
| 
      
 171 
     | 
    
         
            +
            - spec/financier/date_spec.rb
         
     | 
| 
      
 172 
     | 
    
         
            +
            - spec/financier/ledger_spec.rb
         
     | 
| 
      
 173 
     | 
    
         
            +
            - spec/financier/rate_spec.rb
         
     | 
| 
      
 174 
     | 
    
         
            +
            - spec/financier/transaction_spec.rb
         
     | 
| 
      
 175 
     | 
    
         
            +
            - spec/financier_spec.rb
         
     | 
| 
      
 176 
     | 
    
         
            +
            - spec/spec_helper.rb
         
     |