tax_manipulator 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e3a84266c4dd89b984374003d4f1a6655c908ca6
4
+ data.tar.gz: 939140582ec3ea7434f90a4c634d4463014d88db
5
+ SHA512:
6
+ metadata.gz: 3e8cc5bb56a3acd6a7c06f8e1185d41dfe5914d3a098b2516be8e85f7c7d16434ed49acfa12c9b568441fe91e8186a63bf1ae7c8c91970c3ebba31478709b42a
7
+ data.tar.gz: 147833880f1597395b9de21ad72707767b6545bdaa6e837d197d77fdd4d81d8075fde82507daef5150d184f0b35219ca3c704c8db5c549edfda5fd8d87dcbbc1
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.7
4
+ - 2.2.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tax_manipulator.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Marion Duprey
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,79 @@
1
+ [![Build Status](https://travis-ci.org/TiteiKo/tax_manipulator.svg?branch=master)](https://travis-ci.org/TiteiKo/tax_manipulator)
2
+ [![Code Climate](https://codeclimate.com/github/TiteiKo/tax_manipulator/badges/gpa.svg)](https://codeclimate.com/github/TiteiKo/tax_manipulator)
3
+
4
+ # TaxManipulator
5
+
6
+ 2014, France. Taxes go up from 19.6% to 20% on the 1st of January.
7
+
8
+ I then changed the class we used to compute prices (taxes amount and without taxes prices)
9
+ to be able to compute it depending on the date.
10
+
11
+ Today, I think it's finally time for me to cleanup and open source this bit of code !
12
+
13
+ ## Installation
14
+
15
+ TaxManipulator requires **ruby >= 2.1** as it takes advantages of named parameters.
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'tax_manipulator'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install tax_manipulator
30
+
31
+ ## Usage
32
+
33
+ config/initializers/tax_manipulator.rb
34
+
35
+ ```ruby
36
+ TaxManipulator.configure do |config|
37
+ config.add_rate rate: 19.6, ending: Date.parse('2013-12-31')
38
+ config.add_rate rate: 2.0, starting: Date.parse('2014-01-01')
39
+
40
+ # optional: default scheme for the price given (:incl_tax or :excl_tax)
41
+ config.default_scheme :incl_tax
42
+ end
43
+ ```
44
+
45
+ Examples:
46
+
47
+ ```ruby
48
+ # if you have your price including tax
49
+ TaxManipulator.for(42, scheme: :incl_tax).price_excl_tax
50
+ TaxManipulator.for(42, scheme: :incl_tax).vat
51
+ TaxManipulator.for(42, scheme: :incl_tax, date: Date.parse('2013-12-10')).vat
52
+
53
+ # if you have your price excluding tax
54
+ TaxManipulator.for(42, scheme: :excl_tax).price_incl_tax
55
+ TaxManipulator.for(42, scheme: :excl_tax).vat
56
+ TaxManipulator.for(42, scheme: :excl_tax, date: Date.parse('2013-12-10')).vat
57
+
58
+ # if the default scheme is set
59
+ TaxManipulator.for(42).vat
60
+ TaxManipulator.for(42, date: Date.parse('2013-12-10')).vat
61
+ ```
62
+
63
+ ## Development
64
+
65
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt
66
+ that will allow you to experiment.
67
+
68
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
69
+ version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version,
70
+ push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
71
+
72
+ ## Contributing
73
+
74
+ 1. Fork it ( https://github.com/TiteiKo/tax_manipulator/fork )
75
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
76
+ 3. Run the tests and write your owns (`bundle exec rake`)
77
+ 4. Commit your changes (`git commit -am 'Add some feature'`)
78
+ 5. Push to the branch (`git push origin my-new-feature`)
79
+ 6. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ %w(bundler find rake/testtask).each { |lib| require lib }
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "lib"
7
+ t.libs << "test"
8
+ t.test_files = FileList['test/**/test_*.rb', 'test/**/*_spec.rb']
9
+ t.verbose = true
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tax_manipulator"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,36 @@
1
+ require 'tax_manipulator/version'
2
+ require 'tax_manipulator/errors'
3
+ require 'tax_manipulator/configuration'
4
+
5
+ require 'tax_manipulator/rate'
6
+
7
+ require 'tax_manipulator/manipulators/base'
8
+ require 'tax_manipulator/manipulators/excluding_tax'
9
+ require 'tax_manipulator/manipulators/including_tax'
10
+
11
+ module TaxManipulator
12
+ def self.config
13
+ @config ||= Configuration.new
14
+ end
15
+
16
+ def self.configure
17
+ yield(config)
18
+ end
19
+
20
+ def self.for(price, scheme: nil, date: Date.today)
21
+ scheme ||= config.default_scheme
22
+
23
+ case scheme
24
+ when :excl_tax
25
+ Manipulator::ExcludingTax.new(price, date)
26
+ when :incl_tax
27
+ Manipulator::IncludingTax.new(price, date)
28
+ else
29
+ raise UnknownStrategyError
30
+ end
31
+ end
32
+
33
+ def self.reset_config!
34
+ @config = Configuration.new
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ module TaxManipulator
2
+ class Configuration
3
+ attr_reader :rates, :default_scheme
4
+
5
+ def initialize
6
+ @rates = []
7
+ end
8
+
9
+ def add_rate(rate:, starting: nil, ending: nil)
10
+ rates << Rate.new(rate: rate, starting: starting, ending: ending)
11
+ end
12
+
13
+ def default_scheme=(scheme)
14
+ raise UnknownStrategyError unless scheme.nil? || [:excl_tax, :incl_tax].include?(scheme)
15
+
16
+ @default_scheme = scheme
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,5 @@
1
+ module TaxManipulator
2
+ class Error < StandardError; end
3
+
4
+ class UnknownStrategyError < Error; end
5
+ end
@@ -0,0 +1,17 @@
1
+ module TaxManipulator
2
+ module Manipulator
3
+ class Base
4
+ attr_reader :price, :date
5
+
6
+ def initialize(price, date)
7
+ @price, @date = price.to_f, date
8
+ end
9
+
10
+ def rate
11
+ @rate ||= begin
12
+ TaxManipulator.config.rates.find { |r| r.match?(date) }.rate / 100.0
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module TaxManipulator
2
+ module Manipulator
3
+ class ExcludingTax < Base
4
+ def vat
5
+ (rate * price).round(2)
6
+ end
7
+
8
+ def price_incl_tax
9
+ (price + vat).round(2)
10
+ end
11
+
12
+ def price_excl_tax
13
+ price.round(2)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module TaxManipulator
2
+ module Manipulator
3
+ class IncludingTax < Base
4
+ def vat
5
+ (price - (price / (rate + 1))).round(2)
6
+ end
7
+
8
+ def price_incl_tax
9
+ price.round(2)
10
+ end
11
+
12
+ def price_excl_tax
13
+ (price - vat).round(2)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ module TaxManipulator
2
+ class Rate
3
+ attr_accessor :rate, :starting, :ending
4
+
5
+ def initialize(params)
6
+ params.each { |key, value| send "#{key}=", value }
7
+ end
8
+
9
+ def match?(date)
10
+ return true if starting.nil? && ending.nil?
11
+ return date <= ending if starting.nil?
12
+ return date >= starting if ending.nil?
13
+ date <= ending && date >= starting
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module TaxManipulator
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tax_manipulator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tax_manipulator"
8
+ spec.version = TaxManipulator::VERSION
9
+ spec.authors = ["Marion Duprey"]
10
+ spec.email = ["titeiko@gmail.com"]
11
+
12
+ spec.summary = %q{Configurable vat, price including tax and price excluding tax computing}
13
+ spec.homepage = "https://github.com/TiteiKo/tax_manipulator"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = '>= 2.1'
22
+
23
+ spec.add_development_dependency 'bundler', '>= 1.7'
24
+ spec.add_development_dependency 'rake', '>= 10.0'
25
+ spec.add_development_dependency 'minitest'
26
+ spec.add_development_dependency 'minitest-reporters'
27
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tax_manipulator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marion Duprey
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-reporters
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description:
70
+ email:
71
+ - titeiko@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/tax_manipulator.rb
85
+ - lib/tax_manipulator/configuration.rb
86
+ - lib/tax_manipulator/errors.rb
87
+ - lib/tax_manipulator/manipulators/base.rb
88
+ - lib/tax_manipulator/manipulators/excluding_tax.rb
89
+ - lib/tax_manipulator/manipulators/including_tax.rb
90
+ - lib/tax_manipulator/rate.rb
91
+ - lib/tax_manipulator/version.rb
92
+ - tax_manipulator.gemspec
93
+ homepage: https://github.com/TiteiKo/tax_manipulator
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '2.1'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.4.5
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Configurable vat, price including tax and price excluding tax computing
117
+ test_files: []