gt-collection-calculator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 95478c51cfbc0425fe98dfd284532ac378010079
4
+ data.tar.gz: 787a0c8fa2476d8e6fefe2268ee0b33aaff1207a
5
+ SHA512:
6
+ metadata.gz: ef413ca0828d447f849c80d9a294cfbc803df60803700dc7dc1d54556aadbccbefd950c1de837095c1b33f6e1d63a14199fe15821dc3e815921067f758c3694c
7
+ data.tar.gz: 863e8c6d5b24d1b880f0b10cb0cbfb3a774cee5d872d539a5ec00da73a8ba9a5e95bd8ce2822bc854191054169451ef54bce87ea9ab538ef1b73608f391a75e1
@@ -0,0 +1 @@
1
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gt-collection-calculator.gemspec
4
+ gemspec
@@ -0,0 +1,33 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ gt-collection-calculator (0.0.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ rspec (3.7.0)
11
+ rspec-core (~> 3.7.0)
12
+ rspec-expectations (~> 3.7.0)
13
+ rspec-mocks (~> 3.7.0)
14
+ rspec-core (3.7.1)
15
+ rspec-support (~> 3.7.0)
16
+ rspec-expectations (3.7.0)
17
+ diff-lcs (>= 1.2.0, < 2.0)
18
+ rspec-support (~> 3.7.0)
19
+ rspec-mocks (3.7.0)
20
+ diff-lcs (>= 1.2.0, < 2.0)
21
+ rspec-support (~> 3.7.0)
22
+ rspec-support (3.7.1)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ bundler (~> 1.7)
29
+ gt-collection-calculator!
30
+ rspec
31
+
32
+ BUNDLED WITH
33
+ 1.16.1
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2018 Phuong Nguyen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ 'Software'), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,15 @@
1
+ # GTCollection Calculator
2
+
3
+ A calculator to address GTCollection nasty fee calculation
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'gt-collection-calculator'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gt-collection-calculator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gt-collection-calculator"
8
+ spec.version = GtCollectionCalculator::VERSION
9
+ spec.authors = ["Phuong Nguyen"]
10
+ spec.email = ["phuongnd08@gmail.com"]
11
+ spec.summary = %q{A calculator to deal with GTCollection nasty charging calculation}
12
+ spec.description = %q{A calculator to deal with GTCollection nasty charging calculation}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency("rspec", [">= 0"])
23
+ end
@@ -0,0 +1,20 @@
1
+ require 'bigdecimal'
2
+
3
+ class GtCollectionCalculator
4
+ MAX_AMOUNT_THAT_USE_PERCENT = BigDecimal.new(2000)/0.015
5
+ MAX_DEBIT_AMOUNT_THAT_USE_PERCENT = MAX_AMOUNT_THAT_USE_PERCENT * 1.015
6
+
7
+ def self.credit2request(credit_amount)
8
+ debit_amount = BigDecimal.new(credit_amount) + 105
9
+ if debit_amount > MAX_AMOUNT_THAT_USE_PERCENT
10
+ debit_amount - 2000
11
+ else
12
+ debit_amount/1.015
13
+ end
14
+ end
15
+
16
+ def self.request2credit(request_amount)
17
+ fee = [BigDecimal.new(request_amount) * 0.015, 2000].min
18
+ request_amount + fee - 105
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ class GtCollectionCalculator
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe GtCollectionCalculator do
4
+ let(:c) { GtCollectionCalculator }
5
+
6
+ describe ".request2credit" do
7
+ it "returns correctly" do
8
+ expect(c.request2credit(1000)).to eq 910
9
+ expect(c.request2credit(5000)).to eq 4970
10
+ expect(c.request2credit(10000)).to eq 10045
11
+ expect(c.request2credit(200000)).to eq 201895
12
+ expect(c.request2credit(2000000)).to eq 2001895
13
+ end
14
+ end
15
+
16
+ describe ".credit2request" do
17
+ it "returns correctly" do
18
+ expect(c.request2credit(c.credit2request(1000)).round).to eq 1000
19
+ expect(c.request2credit(c.credit2request(5000)).round).to eq 5000
20
+ expect(c.request2credit(c.credit2request(10000)).round).to eq 10000
21
+ expect(c.request2credit(c.credit2request(20000)).round).to eq 20000
22
+ expect(c.request2credit(c.credit2request(200000)).round).to eq 200000
23
+ expect(c.request2credit(c.credit2request(2000000)).round).to eq 2000000
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,20 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'gt-collection-calculator'
4
+
5
+ # Requires supporting ruby files with custom matchers and macros, etc,
6
+ # in spec/support/ and its subdirectories.
7
+ Dir[File.expand_path("./spec/support/**/*.rb")].each { |f| require f }
8
+
9
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
10
+ RSpec.configure do |config|
11
+ config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+
15
+ # Run specs in random order to surface order dependencies. If you find an
16
+ # order dependency and want to debug it, you can fix the order by providing
17
+ # the seed, which is printed after each run.
18
+ # --seed 1234
19
+ config.order = 'random'
20
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gt-collection-calculator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Phuong Nguyen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-03 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: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A calculator to deal with GTCollection nasty charging calculation
42
+ email:
43
+ - phuongnd08@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - Gemfile.lock
51
+ - LICENSE.txt
52
+ - README.md
53
+ - gt-collection-calculator.gemspec
54
+ - lib/gt-collection-calculator.rb
55
+ - lib/gt-collection-calculator/version.rb
56
+ - spec/lib/gt_collection_calculator_spec.rb
57
+ - spec/spec_helper.rb
58
+ homepage: ''
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.4.5.3
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: A calculator to deal with GTCollection nasty charging calculation
82
+ test_files:
83
+ - spec/lib/gt_collection_calculator_spec.rb
84
+ - spec/spec_helper.rb