myco_pricing_engine 0.1.1 → 0.1.2
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/.github/workflows/rubyonrails.yml +26 -0
- data/.ruby-version +1 -0
- data/LICENSE.txt +21 -0
- data/README.md +70 -66
- data/lib/myco_pricing_engine/calculator.rb +86 -15
- data/lib/myco_pricing_engine/version.rb +1 -1
- data/lib/myco_pricing_engine.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f5824035436e46227cf1d8ead9027b8d2da05668ba855cf288cb78e598e9a8b
|
4
|
+
data.tar.gz: 6e2637000fa652fe9e1ec71f850c4a5c7469a2488c914158e05521690df32f2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d48d2684e8ec09138c745271d0e842dd2696747a40c05823d4fffefe7d6365fc70bc16671e474455c47a73b94f2d93b8d196c7fc0deab03bc705bb76cea9aac5
|
7
|
+
data.tar.gz: 416c1573f5c171501cbde75948c79b6f28d30141cddc2bb56f8a7a436222b4dcc7f79db0c10c5c3cd5ddd22105f82f8e0737039e1be5b8c4b2aafc100f474fff
|
@@ -0,0 +1,26 @@
|
|
1
|
+
name: Ruby CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ "main" ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ "main" ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
test:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
|
13
|
+
steps:
|
14
|
+
- uses: actions/checkout@v3
|
15
|
+
|
16
|
+
- name: Set up Ruby
|
17
|
+
uses: ruby/setup-ruby@78c01b705fd9d5ad960d432d3a0cfa341d50e410 # v1.179.1
|
18
|
+
with:
|
19
|
+
ruby-version: 3.2.0
|
20
|
+
bundler-cache: true
|
21
|
+
|
22
|
+
- name: Install dependencies
|
23
|
+
run: bundle install
|
24
|
+
|
25
|
+
- name: Run RSpec tests
|
26
|
+
run: bundle exec rspec
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 mrmalvi
|
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
CHANGED
@@ -1,119 +1,123 @@
|
|
1
|
-
#
|
1
|
+
# 🚀 Myco Pricing Engine – Rails Engine for Pricing Utilities
|
2
2
|
|
3
|
-
|
3
|
+
[](https://rubygems.org/gems/myco_pricing_engine)
|
4
|
+
[](https://github.com/your-username/myco_pricing_engine/actions)
|
5
|
+
[](LICENSE)
|
4
6
|
|
5
|
-
|
7
|
+
**Myco Pricing Engine** is an open-source **Rails engine** that provides utilities for pricing calculations and automation.
|
8
|
+
It helps developers integrate pricing logic, split EMIs, and manage financial calculations in Rails applications.
|
6
9
|
|
7
|
-
|
10
|
+
👉 [RubyGems page](https://rubygems.org/gems/myco_pricing_engine) |
|
11
|
+
👉 [Source code on GitHub](https://github.com/your-username/myco_pricing_engine)
|
12
|
+
|
13
|
+
---
|
14
|
+
|
15
|
+
## ✨ Features
|
16
|
+
- ⚡ Automatic pricing calculations
|
17
|
+
- 🔢 EMI and interest rate utilities
|
18
|
+
- 🧩 Easily integratable with Rails apps
|
19
|
+
|
20
|
+
---
|
21
|
+
|
22
|
+
## 📦 Installation
|
23
|
+
|
24
|
+
Add this line to your Rails app `Gemfile`:
|
8
25
|
|
9
26
|
```ruby
|
10
27
|
gem 'myco_pricing_engine'
|
11
28
|
```
|
12
29
|
|
13
|
-
Then
|
30
|
+
Then install the gem:
|
14
31
|
|
15
32
|
```bash
|
16
33
|
bundle install
|
17
34
|
```
|
18
35
|
|
19
|
-
Or install
|
36
|
+
Or install manually:
|
20
37
|
|
21
38
|
```bash
|
22
39
|
gem install myco_pricing_engine
|
23
40
|
```
|
24
41
|
|
25
|
-
## Usage
|
42
|
+
## 🚀 Usage
|
26
43
|
|
27
|
-
###
|
44
|
+
### Automatic Features
|
45
|
+
- Pricing calculations for products, EMI breakdown, and financial summaries.
|
28
46
|
|
47
|
+
### Manual Usage
|
29
48
|
```ruby
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
49
|
+
user = User.new(loyalty_points: 1200) # Active Record/Openstruct
|
50
|
+
|
51
|
+
# Optional configuration
|
52
|
+
config = {
|
53
|
+
loyalty_threshold: 1000, # Points required for loyalty discount
|
54
|
+
loyalty_discount: 0.10, # 10% discount
|
55
|
+
tax_rate: 0.18, # 18% tax
|
56
|
+
coupons: { # Coupon codes
|
57
|
+
"SAVE50" => 50, # Fixed discount
|
58
|
+
"NEW10" => 0.10 # Percentage discount
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
# Initialize calculator
|
63
|
+
calc = MycoPricingEngine::Calculator.new(
|
64
|
+
base_price: 1000,
|
65
|
+
user: user,
|
66
|
+
options: { coupon: "SAVE50" },
|
67
|
+
config: config
|
68
|
+
)
|
69
|
+
|
70
|
+
# Calculate final price
|
71
|
+
puts calc.final_price
|
72
|
+
# => 1062.0
|
43
73
|
|
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
74
|
```
|
60
75
|
|
61
|
-
|
62
|
-
|
63
|
-
MycoPricingEngine supports:
|
76
|
+
---
|
64
77
|
|
65
|
-
|
66
|
-
- ActiveRecord 4.x → 8.x
|
67
|
-
- Ruby 2.7+ → 3.4
|
78
|
+
## 🧪 Development & Testing
|
68
79
|
|
69
|
-
|
70
|
-
|
71
|
-
Clone the repository and set up dependencies:
|
80
|
+
Clone and setup:
|
72
81
|
|
73
82
|
```bash
|
74
|
-
git clone https://github.com/
|
83
|
+
git clone https://github.com/your-username/myco_pricing_engine.git
|
75
84
|
cd myco_pricing_engine
|
76
|
-
|
77
|
-
```
|
78
|
-
|
79
|
-
Run the console to experiment:
|
80
|
-
|
81
|
-
```bash
|
82
|
-
bin/console
|
85
|
+
bundle install
|
83
86
|
```
|
84
87
|
|
85
|
-
Run
|
88
|
+
Run specs:
|
86
89
|
|
87
90
|
```bash
|
88
91
|
bundle exec rspec
|
89
92
|
```
|
90
93
|
|
91
|
-
|
94
|
+
Build gem locally:
|
92
95
|
|
93
96
|
```bash
|
94
97
|
bundle exec rake install
|
95
98
|
```
|
96
99
|
|
97
|
-
|
100
|
+
Release a version:
|
98
101
|
|
99
102
|
```bash
|
100
|
-
# Update the version in lib/myco_pricing_engine/version.rb
|
101
103
|
bundle exec rake release
|
102
104
|
```
|
103
105
|
|
104
|
-
|
106
|
+
---
|
105
107
|
|
106
|
-
## Contributing
|
108
|
+
## 🤝 Contributing
|
107
109
|
|
108
|
-
|
110
|
+
Contributions, bug reports, and pull requests are welcome!
|
111
|
+
See [issues](https://github.com/your-username/myco_pricing_engine/issues).
|
109
112
|
|
110
|
-
|
113
|
+
---
|
111
114
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
+
## 📜 License
|
116
|
+
|
117
|
+
Released under the [MIT License](LICENSE.txt).
|
115
118
|
|
116
|
-
|
119
|
+
---
|
117
120
|
|
118
|
-
|
121
|
+
### 📈 SEO Keywords
|
122
|
+
*Rails engine, Ruby gem, pricing utilities, EMI calculation, Rails financial gem, Myco Pricing Engine*
|
119
123
|
|
@@ -13,9 +13,23 @@ module MycoPricingEngine
|
|
13
13
|
|
14
14
|
def final_price
|
15
15
|
price = base_price
|
16
|
+
|
17
|
+
# Apply discounts
|
16
18
|
price -= loyalty_discount(price)
|
19
|
+
price -= early_bird_discount(price)
|
20
|
+
|
21
|
+
# Add tax
|
17
22
|
price += tax(price)
|
18
|
-
|
23
|
+
|
24
|
+
# Apply coupons (after tax)
|
25
|
+
price -= coupon_discounts(price)
|
26
|
+
|
27
|
+
# Add delivery/service fee
|
28
|
+
price += delivery_fee
|
29
|
+
|
30
|
+
# Apply caps
|
31
|
+
price = apply_price_caps(price)
|
32
|
+
|
19
33
|
price.round(2)
|
20
34
|
end
|
21
35
|
|
@@ -23,36 +37,93 @@ module MycoPricingEngine
|
|
23
37
|
|
24
38
|
def default_config
|
25
39
|
{
|
26
|
-
|
27
|
-
|
40
|
+
# Loyalty
|
41
|
+
loyalty_levels: {
|
42
|
+
silver: { threshold: 500, discount: 0.05 },
|
43
|
+
gold: { threshold: 1000, discount: 0.10 },
|
44
|
+
platinum: { threshold: 2000, discount: 0.20 }
|
45
|
+
},
|
46
|
+
|
47
|
+
# Tax
|
28
48
|
tax_rate: 0.18,
|
29
|
-
|
49
|
+
|
50
|
+
# Coupons
|
51
|
+
coupons: {},
|
52
|
+
|
53
|
+
# Early bird
|
54
|
+
early_bird_deadline: nil, # Date or Time
|
55
|
+
early_bird_discount: 0.10,
|
56
|
+
|
57
|
+
# Fees
|
58
|
+
delivery_fee: 0.0,
|
59
|
+
|
60
|
+
# Caps
|
61
|
+
min_price: 0.0,
|
62
|
+
max_price: Float::INFINITY
|
30
63
|
}
|
31
64
|
end
|
32
65
|
|
66
|
+
# ---------------------
|
67
|
+
# Discounts
|
68
|
+
# ---------------------
|
33
69
|
def loyalty_discount(price)
|
34
70
|
return 0 unless user.respond_to?(:loyalty_points)
|
35
71
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
72
|
+
discount = 0
|
73
|
+
config[:loyalty_levels].each_value do |level|
|
74
|
+
if user.loyalty_points >= level[:threshold]
|
75
|
+
discount = level[:discount]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
price * discount
|
80
|
+
end
|
81
|
+
|
82
|
+
def coupon_discounts(price)
|
83
|
+
return 0 unless options[:coupons].is_a?(Array)
|
84
|
+
|
85
|
+
options[:coupons].sum do |code|
|
86
|
+
next 0 unless config[:coupons].key?(code)
|
87
|
+
|
88
|
+
discount_value = config[:coupons][code]
|
89
|
+
if discount_value.is_a?(Numeric) && discount_value <= 1.0
|
90
|
+
price * discount_value
|
91
|
+
else
|
92
|
+
discount_value
|
93
|
+
end
|
40
94
|
end
|
41
95
|
end
|
42
96
|
|
97
|
+
def early_bird_discount(price)
|
98
|
+
deadline = config[:early_bird_deadline]
|
99
|
+
return 0 unless deadline && current_time <= deadline
|
100
|
+
|
101
|
+
price * config[:early_bird_discount]
|
102
|
+
end
|
103
|
+
|
104
|
+
# ---------------------
|
105
|
+
# Fees & Tax
|
106
|
+
# ---------------------
|
43
107
|
def tax(price)
|
44
108
|
price * config[:tax_rate]
|
45
109
|
end
|
46
110
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
111
|
+
def delivery_fee
|
112
|
+
config[:delivery_fee].to_f
|
113
|
+
end
|
114
|
+
|
115
|
+
# ---------------------
|
116
|
+
# Caps
|
117
|
+
# ---------------------
|
118
|
+
def apply_price_caps(price)
|
119
|
+
[[price, config[:min_price]].max, config[:max_price]].min
|
120
|
+
end
|
50
121
|
|
51
|
-
|
52
|
-
if
|
53
|
-
|
122
|
+
def current_time
|
123
|
+
if defined?(Time.zone) && Time.zone
|
124
|
+
Time.current
|
54
125
|
else
|
55
|
-
|
126
|
+
Time.now
|
56
127
|
end
|
57
128
|
end
|
58
129
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mrmalvi
|
@@ -73,6 +73,9 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
+
- ".github/workflows/rubyonrails.yml"
|
77
|
+
- ".ruby-version"
|
78
|
+
- LICENSE.txt
|
76
79
|
- README.md
|
77
80
|
- Rakefile
|
78
81
|
- lib/myco_pricing_engine.rb
|