Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ROR-Assignment-Day-04/debt_gdp_ratio.rb
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
37 changes: 37 additions & 0 deletions ROR-Assignment-Day-04/economic_analysis.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Define module EconomicAnalysis
module EconomicAnalysis
Copy link
Copy Markdown
Collaborator

@RajatKawale RajatKawale Jan 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After moving DebtGdpRatio into separate file you can include that in this file like below.

Suggested change
module EconomicAnalysis
module EconomicAnalysis
include DebtGdpRatio

Same goes for the other modules.

# 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
72 changes: 72 additions & 0 deletions ROR-Assignment-Day-04/loan_eligibility.rb
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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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

131 changes: 131 additions & 0 deletions ROR-Assignment-Day-04/main.rb
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'
Comment thread
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
50 changes: 50 additions & 0 deletions ROR-Assignment-Day-04/military_defense.rb
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
Copy link
Copy Markdown
Collaborator

@RajatKawale RajatKawale Jan 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there are no incidents occurred for that country?
There should be validation that total_incidents and resolved_incidents shouldn't be in negative and resolved_incidents shouldn't be greater than total_incidents should get checked before going into case clause.

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