myco_pricing_engine 0.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0d392274767ced10357628ce5bc50e2ac989e63a77dceecc690a403b4576caa8
4
- data.tar.gz: 8a2bc24fe07f259d263ac2733d293e271e4155b9e48055d1fa6cc133fff6f833
3
+ metadata.gz: 6f5824035436e46227cf1d8ead9027b8d2da05668ba855cf288cb78e598e9a8b
4
+ data.tar.gz: 6e2637000fa652fe9e1ec71f850c4a5c7469a2488c914158e05521690df32f2d
5
5
  SHA512:
6
- metadata.gz: 927a55f82120995128ba152ea726e3c57cc9e720e27680f6ed1def73a61657c2a0010fcda52b237b54e916522332ba6b0787d9d331044e961187eb1cf8b8cc39
7
- data.tar.gz: a722070da98de99179f48e8a916250f7e41e2cc1bbb9120da359146210da3b99d695cc8a2a2a2fd3a976656992c6f8a2bec883fc045761b710bfff1feeda539e
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,35 +1,123 @@
1
- # MycoPricingEngine
1
+ # 🚀 Myco Pricing Engine – Rails Engine for Pricing Utilities
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ [![Gem Version](https://badge.fury.io/rb/myco_pricing_engine.svg)](https://rubygems.org/gems/myco_pricing_engine)
4
+ [![Build Status](https://github.com/your-username/myco_pricing_engine/actions/workflows/ci.yml/badge.svg)](https://github.com/your-username/myco_pricing_engine/actions)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
4
6
 
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.
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
- ## Installation
10
+ 👉 [RubyGems page](https://rubygems.org/gems/myco_pricing_engine) |
11
+ 👉 [Source code on GitHub](https://github.com/your-username/myco_pricing_engine)
8
12
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
13
+ ---
10
14
 
11
- Install the gem and add to the application's Gemfile by executing:
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`:
25
+
26
+ ```ruby
27
+ gem 'myco_pricing_engine'
28
+ ```
29
+
30
+ Then install the gem:
31
+
32
+ ```bash
33
+ bundle install
34
+ ```
35
+
36
+ Or install manually:
37
+
38
+ ```bash
39
+ gem install myco_pricing_engine
40
+ ```
41
+
42
+ ## 🚀 Usage
43
+
44
+ ### Automatic Features
45
+ - Pricing calculations for products, EMI breakdown, and financial summaries.
46
+
47
+ ### Manual Usage
48
+ ```ruby
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
73
+
74
+ ```
75
+
76
+ ---
77
+
78
+ ## 🧪 Development & Testing
79
+
80
+ Clone and setup:
12
81
 
13
82
  ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
83
+ git clone https://github.com/your-username/myco_pricing_engine.git
84
+ cd myco_pricing_engine
85
+ bundle install
15
86
  ```
16
87
 
17
- If bundler is not being used to manage dependencies, install the gem by executing:
88
+ Run specs:
18
89
 
19
90
  ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
91
+ bundle exec rspec
21
92
  ```
22
93
 
23
- ## Usage
94
+ Build gem locally:
95
+
96
+ ```bash
97
+ bundle exec rake install
98
+ ```
99
+
100
+ Release a version:
101
+
102
+ ```bash
103
+ bundle exec rake release
104
+ ```
105
+
106
+ ---
107
+
108
+ ## 🤝 Contributing
109
+
110
+ Contributions, bug reports, and pull requests are welcome!
111
+ See [issues](https://github.com/your-username/myco_pricing_engine/issues).
24
112
 
25
- TODO: Write usage instructions here
113
+ ---
26
114
 
27
- ## Development
115
+ ## 📜 License
28
116
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
117
+ Released under the [MIT License](LICENSE.txt).
30
118
 
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
119
+ ---
32
120
 
33
- ## Contributing
121
+ ### 📈 SEO Keywords
122
+ *Rails engine, Ruby gem, pricing utilities, EMI calculation, Rails financial gem, Myco Pricing Engine*
34
123
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/myco_pricing_engine.
@@ -0,0 +1,130 @@
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
+
17
+ # Apply discounts
18
+ price -= loyalty_discount(price)
19
+ price -= early_bird_discount(price)
20
+
21
+ # Add tax
22
+ price += tax(price)
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
+
33
+ price.round(2)
34
+ end
35
+
36
+ private
37
+
38
+ def default_config
39
+ {
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
48
+ tax_rate: 0.18,
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
63
+ }
64
+ end
65
+
66
+ # ---------------------
67
+ # Discounts
68
+ # ---------------------
69
+ def loyalty_discount(price)
70
+ return 0 unless user.respond_to?(:loyalty_points)
71
+
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
94
+ end
95
+ end
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
+ # ---------------------
107
+ def tax(price)
108
+ price * config[:tax_rate]
109
+ end
110
+
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
121
+
122
+ def current_time
123
+ if defined?(Time.zone) && Time.zone
124
+ Time.current
125
+ else
126
+ Time.now
127
+ end
128
+ end
129
+ end
130
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MycoPricingEngine
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
-
3
- require_relative "myco_pricing_engine/version"
4
- require_relative "myco_pricing_engine/calculator"
2
+ require "active_support/all"
3
+ require "myco_pricing_engine/calculator"
5
4
 
6
5
  module MycoPricingEngine
7
6
  class Error < StandardError; end
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.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - mrmalvi
@@ -73,9 +73,13 @@ 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
82
+ - lib/myco_pricing_engine/calculator.rb
79
83
  - lib/myco_pricing_engine/version.rb
80
84
  - sig/myco_pricing_engine.rbs
81
85
  homepage: https://github.com/mrmalvi/myco_pricing_engine