myco_pricing_engine 0.1.0 → 0.1.1
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 +4 -4
- data/README.md +97 -13
- data/lib/myco_pricing_engine/calculator.rb +59 -0
- data/lib/myco_pricing_engine/version.rb +1 -1
- data/lib/myco_pricing_engine.rb +1 -2
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 27d95967f5eacfaa6e16e3f6b4baaf660f216703c2a4f59d55ec64fb28887459
|
4
|
+
data.tar.gz: 5d4c32234de86b8107cedeab0947af8e295ec6c871285556dc573bc7abf9b4f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d9f6571b3d16677a2ed488e143ea9b31d3c0bc85d7e6161cb693178f999aa8bf77f62a4a1b71d49db7b46d0bddb742aaeb3b11e5c485fd4bf20dfc7fc7af7ee
|
7
|
+
data.tar.gz: 60e1dd8ad8dd8144b117411d9ef010a91a96134b4647289a80fadd4804d3b693acaf6cd321fd16e41fc6bced83fcb1b423412df522604d2bc416f2a0f07f1d3e
|
data/README.md
CHANGED
@@ -1,35 +1,119 @@
|
|
1
1
|
# MycoPricingEngine
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
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/myco_pricing_engine`. To experiment with that code, run `bin/console` for an interactive prompt.
|
3
|
+
MycoPricingEngine is a Ruby gem for handling **pricing calculations, loan/EMI computations, and financial preference management** in Rails applications. It provides a flexible engine for modeling pricing rules, calculating interest, and managing dynamic preferences per entity.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
|
7
|
+
You can install the gem by adding it to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'myco_pricing_engine'
|
11
|
+
```
|
10
12
|
|
11
|
-
|
13
|
+
Then execute:
|
12
14
|
|
13
15
|
```bash
|
14
|
-
bundle
|
16
|
+
bundle install
|
15
17
|
```
|
16
18
|
|
17
|
-
|
19
|
+
Or install it manually:
|
18
20
|
|
19
21
|
```bash
|
20
|
-
gem install
|
22
|
+
gem install myco_pricing_engine
|
21
23
|
```
|
22
24
|
|
23
25
|
## Usage
|
24
26
|
|
25
|
-
|
27
|
+
### 1. Including Pricing Engine in Rails Models
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
class Loan < ApplicationRecord
|
31
|
+
include MycoPricingEngine::Calculator
|
32
|
+
|
33
|
+
# Example: calculate EMI
|
34
|
+
def monthly_emi
|
35
|
+
MycoPricingEngine::Calculator.compute_emi(principal, rate_of_interest, tenure)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
```
|
26
39
|
|
27
|
-
|
40
|
+
### 2. Managing Preferences
|
41
|
+
|
42
|
+
The gem supports dynamic preferences using `SerialPreference`:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
class DummyClass < ApplicationRecord
|
46
|
+
include SerialPreference::HasSerialPreferences
|
47
|
+
|
48
|
+
preferences do
|
49
|
+
boolean :taxable, default: true
|
50
|
+
string :vat_no
|
51
|
+
integer :max_invoice_items, default: 100
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
d = DummyClass.new
|
56
|
+
d.taxable? # => true
|
57
|
+
d.vat_no = "ABC123"
|
58
|
+
d.max_invoice_items # => 100
|
59
|
+
```
|
28
60
|
|
29
|
-
|
61
|
+
### 3. Supported Rails Versions
|
30
62
|
|
31
|
-
|
63
|
+
MycoPricingEngine supports:
|
64
|
+
|
65
|
+
- Rails 4.x → 7.x
|
66
|
+
- ActiveRecord 4.x → 8.x
|
67
|
+
- Ruby 2.7+ → 3.4
|
68
|
+
|
69
|
+
### 4. Development
|
70
|
+
|
71
|
+
Clone the repository and set up dependencies:
|
72
|
+
|
73
|
+
```bash
|
74
|
+
git clone https://github.com/mrmalvi/myco_pricing_engine.git
|
75
|
+
cd myco_pricing_engine
|
76
|
+
bin/setup
|
77
|
+
```
|
78
|
+
|
79
|
+
Run the console to experiment:
|
80
|
+
|
81
|
+
```bash
|
82
|
+
bin/console
|
83
|
+
```
|
84
|
+
|
85
|
+
Run tests:
|
86
|
+
|
87
|
+
```bash
|
88
|
+
bundle exec rspec
|
89
|
+
```
|
90
|
+
|
91
|
+
To install the gem locally:
|
92
|
+
|
93
|
+
```bash
|
94
|
+
bundle exec rake install
|
95
|
+
```
|
96
|
+
|
97
|
+
To release a new version:
|
98
|
+
|
99
|
+
```bash
|
100
|
+
# Update the version in lib/myco_pricing_engine/version.rb
|
101
|
+
bundle exec rake release
|
102
|
+
```
|
103
|
+
|
104
|
+
This will create a git tag, push commits, and push the gem to RubyGems.org.
|
32
105
|
|
33
106
|
## Contributing
|
34
107
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub
|
108
|
+
Bug reports and pull requests are welcome! Please open issues or PRs on [GitHub](https://github.com/mrmalvi/myco_pricing_engine).
|
109
|
+
|
110
|
+
Before contributing, ensure all tests pass:
|
111
|
+
|
112
|
+
```bash
|
113
|
+
bundle exec rspec
|
114
|
+
```
|
115
|
+
|
116
|
+
## License
|
117
|
+
|
118
|
+
This gem is released under the MIT License. See [LICENSE](LICENSE) for details.
|
119
|
+
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MycoPricingEngine
|
4
|
+
class Calculator
|
5
|
+
attr_reader :base_price, :user, :options, :config
|
6
|
+
|
7
|
+
def initialize(base_price:, user:, options: {}, config: {})
|
8
|
+
@base_price = base_price
|
9
|
+
@user = user
|
10
|
+
@options = options
|
11
|
+
@config = default_config.merge(config)
|
12
|
+
end
|
13
|
+
|
14
|
+
def final_price
|
15
|
+
price = base_price
|
16
|
+
price -= loyalty_discount(price)
|
17
|
+
price += tax(price)
|
18
|
+
price -= coupon_discount(price)
|
19
|
+
price.round(2)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def default_config
|
25
|
+
{
|
26
|
+
loyalty_threshold: 1000,
|
27
|
+
loyalty_discount: 0.10,
|
28
|
+
tax_rate: 0.18,
|
29
|
+
coupons: {}
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
def loyalty_discount(price)
|
34
|
+
return 0 unless user.respond_to?(:loyalty_points)
|
35
|
+
|
36
|
+
if user.loyalty_points > config[:loyalty_threshold]
|
37
|
+
price * config[:loyalty_discount]
|
38
|
+
else
|
39
|
+
0
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def tax(price)
|
44
|
+
price * config[:tax_rate]
|
45
|
+
end
|
46
|
+
|
47
|
+
def coupon_discount(price)
|
48
|
+
coupon_code = options[:coupon]
|
49
|
+
return 0 unless coupon_code && config[:coupons].key?(coupon_code)
|
50
|
+
|
51
|
+
discount_value = config[:coupons][coupon_code]
|
52
|
+
if discount_value.is_a?(Numeric) && discount_value <= 1.0
|
53
|
+
price * discount_value
|
54
|
+
else
|
55
|
+
discount_value
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/myco_pricing_engine.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: myco_pricing_engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mrmalvi
|
@@ -76,6 +76,7 @@ files:
|
|
76
76
|
- README.md
|
77
77
|
- Rakefile
|
78
78
|
- lib/myco_pricing_engine.rb
|
79
|
+
- lib/myco_pricing_engine/calculator.rb
|
79
80
|
- lib/myco_pricing_engine/version.rb
|
80
81
|
- sig/myco_pricing_engine.rbs
|
81
82
|
homepage: https://github.com/mrmalvi/myco_pricing_engine
|