-
Notifications
You must be signed in to change notification settings - Fork 0
Ror assignment day 04 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
06efc4d
3596248
fe473cf
ac1195c
89ece8c
847e8ed
6b8858b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Define module DebtGdpRatio | ||
| module DebtGdpRatio | ||
| # Define method debt_gdp_ratio | ||
| def self.debt_gdp_ratio(gdp, debt) | ||
| return 'GDP cannot be zero' if gdp == 0 | ||
| (debt.to_f / gdp.to_f) * 100 | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # Define module EconomicAnalysis | ||
| module EconomicAnalysis | ||
| # Method to analyze inflation rate | ||
| def inflation_rate_analysis(initial_price, final_price, years) | ||
| return 'Years cannot be zero' if years == 0 | ||
| ((final_price - initial_price) / initial_price.to_f) / years * 100 | ||
| end | ||
|
|
||
| # Method to analyze trade balance | ||
| def trade_balance_analysis(exports, imports) | ||
| balance = exports - imports | ||
| case balance | ||
| when 0 | ||
| 'Trade is Balanced' | ||
| when 1..Float::INFINITY | ||
| "Trade Surplus: #{balance}" | ||
| when -Float::INFINITY..-1 | ||
| "Trade Deficit: #{balance.abs}" | ||
| else | ||
| 'Invalid balance' | ||
| end | ||
| end | ||
|
|
||
| # Method to provide details for a country | ||
| def details(country_name, gdp, debt, initial_price, final_price, years, exports, imports) | ||
| debt_gdp_ratio = DebtGdpRatio.debt_gdp_ratio(gdp, debt) | ||
| inflation_rate = inflation_rate_analysis(initial_price, final_price, years) | ||
| trade_balance = trade_balance_analysis(exports, imports) | ||
|
|
||
| <<-DETAILS | ||
| Country: #{country_name} | ||
| Debt-to-GDP Ratio: #{debt_gdp_ratio}% | ||
| Inflation Rate (per year): #{inflation_rate}% | ||
| Trade Balance: #{trade_balance} | ||
| DETAILS | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Define module LoanEligibility | ||
| module LoanEligibility | ||
| # IMF members list | ||
| IMF_MEMBERS = [ | ||
| "Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda", | ||
| "Argentina", "Armenia", "Australia", "Austria", "Azerbaijan", "Bahamas", | ||
| "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", | ||
| "Benin", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", | ||
| "Brazil", "Brunei Darussalam", "Bulgaria", "Burkina Faso", "Burundi", | ||
| "Cabo Verde", "Cambodia", "Cameroon", "Canada", "Central African Republic", | ||
| "Chad", "Chile", "China", "Colombia", "Comoros", "Congo", "Congo, Democratic Republic of the", | ||
| "Costa Rica", "Croatia", "Cuba", "Cyprus", "Czech Republic", "Denmark", | ||
| "Djibouti", "Dominica", "Dominican Republic", "Ecuador", "Egypt", | ||
| "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Eswatini", | ||
| "Ethiopia", "Fiji", "Finland", "France", "Gabon", "Gambia", "Georgia", | ||
| "Germany", "Ghana", "Greece", "Grenada", "Guatemala", "Guinea", | ||
| "Guinea-Bissau", "Guyana", "Haiti", "Honduras", "Hungary", "Iceland", | ||
| "India", "Indonesia", "Iran", "Iraq", "Ireland", "Israel", "Italy", | ||
| "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", | ||
| "Korea, Democratic People's Republic of", "Korea, Republic of", "Kuwait", | ||
| "Kyrgyzstan", "Lao People's Democratic Republic", "Latvia", "Lebanon", | ||
| "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", | ||
| "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", | ||
| "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia (Federated States of)", | ||
| "Moldova", "Monaco", "Mongolia", "Montenegro", "Morocco", "Mozambique", | ||
| "Myanmar", "Namibia", "Nauru", "Nepal", "Netherlands", "New Zealand", | ||
| "Nicaragua", "Niger", "Nigeria", "North Macedonia", "Norway", "Oman", | ||
| "Pakistan", "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", | ||
| "Philippines", "Poland", "Portugal", "Qatar", "Romania", "Russian Federation", | ||
| "Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines", | ||
| "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", | ||
| "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Slovak Republic", | ||
| "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Sudan", | ||
| "Spain", "Sri Lanka", "Sudan", "Suriname", "Sweden", "Switzerland", | ||
| "Syrian Arab Republic", "Taiwan", "Tajikistan", "Tanzania", "Thailand", | ||
| "Timor-Leste", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", | ||
| "Turkmenistan", "Tuvalu", "Uganda", "Ukraine", "United Arab Emirates", | ||
| "United Kingdom", "United States", "Uruguay", "Uzbekistan", "Vanuatu", | ||
| "Venezuela", "Viet Nam", "Yemen", "Zambia", "Zimbabwe" | ||
| ] | ||
|
|
||
| # Check if the country is an IMF member | ||
| def is_imf_member?(country_name) | ||
| IMF_MEMBERS.include?(country_name) | ||
| end | ||
|
|
||
| # Debt sustainability based on GDP and debt ratio | ||
| def debt_sustainability(country_name, gdp, debt) | ||
| dept_gdp_ratio = DebtGdpRatio.debt_gdp_ratio(gdp, debt) | ||
| dept_gdp_ratio <= 60 | ||
| end | ||
|
|
||
| # Check if the country is committed to reforms | ||
| def commitment_to_reforms(country_name) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again why this method? |
||
| is_imf_member?(country_name) | ||
| end | ||
|
|
||
| # Determine loan eligibility based on GDP and debt sustainability | ||
| def loan_eligibility(country_name, gdp, debt) | ||
| if is_imf_member?(country_name) | ||
| debt_sustainability(country_name, gdp, debt) && commitment_to_reforms(country_name) ? "Loan is approved" : "Loan is not approved" | ||
| else | ||
| "Country is not a member of IMF so loan can't be approved" | ||
| end | ||
| end | ||
|
|
||
| # Call loan eligibility method (for easier access) | ||
| def details(country_name, gdp, debt) | ||
| loan_eligibility(country_name, gdp, debt) | ||
| end | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| require_relative 'loan_eligibility' | ||
| require_relative 'economic_analysis' | ||
| require_relative 'military_defense' | ||
|
YashShah-Josh marked this conversation as resolved.
|
||
| require_relative 'debt_gdp_ratio' | ||
| require 'active_support/core_ext/string' | ||
|
|
||
|
|
||
| class LoanEligibilityTool | ||
| include DebtGdpRatio | ||
| include LoanEligibility | ||
| end | ||
|
|
||
| class EconomicAnalysisTool | ||
| include DebtGdpRatio | ||
| include EconomicAnalysis | ||
| end | ||
|
|
||
| class MilitaryAndDefenseAnalysis | ||
| include MilitaryAndDefense | ||
| end | ||
|
|
||
| def economic_analysis_tool | ||
| puts "Economic Analysis Tool" | ||
|
|
||
| print "Enter the country name: " | ||
| country_name = gets.chomp.squish.titleize | ||
|
|
||
| print "Enter GDP: " | ||
| gdp = gets.chomp.to_f | ||
|
|
||
| print "Enter Debt: " | ||
| debt = gets.chomp.to_f | ||
|
|
||
| print "Enter Initial Price (of goods/services): " | ||
| initial_price = gets.chomp.to_f | ||
|
|
||
| print "Enter Final Price (of goods/services): " | ||
| final_price = Integer(gets.chomp) | ||
|
|
||
| print "Enter the number of years over which inflation occurred: " | ||
| years = Integer(gets.chomp) | ||
|
|
||
| print "Enter Total Exports: " | ||
| exports = gets.chomp.to_f | ||
|
|
||
| print "Enter Total Imports: " | ||
| imports = gets.chomp.to_f | ||
|
|
||
| # Display analysis details | ||
| economic_analysis = EconomicAnalysisTool.new | ||
| puts economic_analysis.details(country_name, gdp, debt, initial_price, final_price, years, exports, imports) | ||
| rescue => e | ||
| puts "Error: #{e.message}" | ||
| end | ||
|
|
||
| def military_and_defense_analysis_tool | ||
| puts "Military and Defense Analysis Tool" | ||
|
|
||
| print "Enter the country name: " | ||
| country_name = gets.chomp.squish.titleize | ||
|
|
||
| print "Enter Defense Budget: " | ||
| defense_budget = gets.chomp.to_f | ||
|
|
||
| print "Enter GDP: " | ||
| gdp = gets.chomp.to_f | ||
|
|
||
| print "Enter Global Military Rank: " | ||
| rank = Integer(gets.chomp) | ||
|
|
||
| print "Enter Total Number of Countries: " | ||
| total_countries = Integer(gets.chomp) | ||
|
|
||
| print "Enter Total Cybersecurity Incidents Reported: " | ||
| total_incidents = Integer(gets.chomp) | ||
|
|
||
| print "Enter Number of Resolved Cybersecurity Incidents: " | ||
| resolved_incidents = Integer(gets.chomp) | ||
|
|
||
| # Display analysis details | ||
| military_analysis = MilitaryAndDefenseAnalysis.new | ||
| puts military_analysis.details(country_name, defense_budget, gdp, rank, total_countries, total_incidents, resolved_incidents) | ||
| rescue => e | ||
| puts "Error: #{e.message}" | ||
| end | ||
|
|
||
| def loan_eligibility_tool | ||
| puts "Loan Eligibility Tool" | ||
|
|
||
| print "Enter the country name: " | ||
| country_name = gets.chomp.squish.titleize | ||
|
|
||
| print "Enter the GDP: " | ||
| gdp = Integer(gets.chomp) | ||
|
|
||
| print "Enter the Debt: " | ||
| debt = Integer(gets.chomp) | ||
|
|
||
| # Example of usage: | ||
| loan = LoanEligibilityTool.new | ||
| puts loan.details(country_name, gdp, debt) # Adjust the values as needed | ||
| rescue => e | ||
| puts "Error: #{e.message}" | ||
| end | ||
|
|
||
| def main | ||
| puts "Analysis Loan Tool" | ||
|
|
||
| loop do | ||
| puts "************ 🚀 Program Start 🚀 ************" | ||
| puts "Choose the tool you want to use: " | ||
| print "1. Economic Analysis Tool\n2. Military and Defense Analysis Tool\n3. Loan Eligibility Tool\n4. Exit\n" | ||
| choice = Integer(gets.chomp) | ||
|
|
||
| case choice | ||
| when 1 | ||
| economic_analysis_tool | ||
| when 2 | ||
| military_and_defense_analysis_tool | ||
| when 3 | ||
| loan_eligibility_tool | ||
| when 4 | ||
| puts "Exiting..." | ||
| break | ||
| else | ||
| puts "Invalid choice." | ||
| end | ||
| end | ||
| end | ||
|
|
||
| main | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| # Define module MilitaryAndDefense | ||
| module MilitaryAndDefense | ||
| # Method to calculate defense spending as a percentage of GDP | ||
| def defense_spending_analysis(defense_budget, gdp) | ||
| return 'GDP cannot be zero' if gdp == 0 | ||
| (defense_budget.to_f / gdp.to_f) * 100 | ||
| end | ||
|
|
||
| # Method to compare global military rank | ||
| def global_military_rank_comparison(rank, total_countries) | ||
| if rank > total_countries || rank <= 0 | ||
| "Invalid rank. Rank must be between 1 and #{total_countries}." | ||
| else | ||
| "Rank #{rank} out of #{total_countries} places the country in the top #{((rank.to_f / total_countries) * 100).round(2)}% globally." | ||
| end | ||
| end | ||
|
|
||
| # Method to assess cybersecurity preparedness | ||
| def cybersecurity_preparedness(total_incidents, resolved_incidents) | ||
| return 'Total incidents cannot be zero' if total_incidents == 0 | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if there are no incidents occurred for that country? |
||
| resolution_rate = (resolved_incidents.to_f / total_incidents) * 100 | ||
| case resolution_rate | ||
| when 90..100 | ||
| "Excellent preparedness with a resolution rate of #{resolution_rate.round(2)}%." | ||
| when 70...90 | ||
| "Good preparedness with a resolution rate of #{resolution_rate.round(2)}%." | ||
| when 50...70 | ||
| "Moderate preparedness with a resolution rate of #{resolution_rate.round(2)}%." | ||
| when 100..Float::INFINITY | ||
| "Invalid resolution rate. Resolved incidents cannot be more than total incidents." | ||
| else | ||
| "Poor preparedness with a resolution rate of #{resolution_rate.round(2)}%." | ||
| end | ||
| end | ||
|
|
||
| # Method to display full analysis | ||
| def details(country_name, defense_budget, gdp, rank, total_countries, total_incidents, resolved_incidents) | ||
| defense_spending = defense_spending_analysis(defense_budget, gdp) | ||
| rank_comparison = global_military_rank_comparison(rank, total_countries) | ||
| cybersecurity_status = cybersecurity_preparedness(total_incidents, resolved_incidents) | ||
|
|
||
| <<-DETAILS | ||
| Country: #{country_name} | ||
| Defense Spending (% of GDP): #{defense_spending} | ||
| Global Military Rank: #{rank_comparison} | ||
| Cybersecurity Preparedness: #{cybersecurity_status} | ||
| DETAILS | ||
| end | ||
| end | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After moving
DebtGdpRatiointo separate file you can include that in this file like below.Same goes for the other modules.