Conversation
ROR-Assignment-Day-04/main.rb
Outdated
| class MilitaryAndDefenseAnalysis | ||
| include MilitaryAndDefense | ||
| end |
There was a problem hiding this comment.
This is already being defined above. Please remove this.
ROR-Assignment-Day-04/main.rb
Outdated
| puts "Economic Analysis Tool" | ||
|
|
||
| print "Enter the country name: " | ||
| country_name = gets.chomp.split.map(&:capitalize).join(' ') |
There was a problem hiding this comment.
| country_name = gets.chomp.split.map(&:capitalize).join(' ') | |
| country_name = gets.chomp.squish.titleize |
Can you please check if this does the same?
There was a problem hiding this comment.
Yes it does the same work. I have actually checked capitalize but it didn't work hence I used it
ROR-Assignment-Day-04/main.rb
Outdated
| puts "Military and Defense Analysis Tool" | ||
|
|
||
| print "Enter the country name: " | ||
| country_name = gets.chomp.split.map(&:capitalize).join(' ') |
ROR-Assignment-Day-04/main.rb
Outdated
| puts "Loan Eligibility Tool" | ||
|
|
||
| print "Enter the country name: " | ||
| country_name = gets.chomp.split.map(&:capitalize).join(' ') |
ROR-Assignment-Day-04/main.rb
Outdated
| gdp = Integer(gets.chomp) | ||
|
|
||
| print "Enter the Debt: " | ||
| debt = Integer(gets.chomp) |
There was a problem hiding this comment.
Do you think it's better to use Integer only in the above cases also instead of to_i.
There was a problem hiding this comment.
Yes it will be better. I will modify it
ROR-Assignment-Day-04/main.rb
Outdated
| loan = LoanEligibilityTool.new | ||
| puts loan.details(country_name, gdp, debt) # Adjust the values as needed | ||
|
|
||
| rescue Error => e |
There was a problem hiding this comment.
Can we have a single rescue block for this entire case clause instead of having individual rescue block for all different cases? As i can see the message is same for all rescue block.
ROR-Assignment-Day-04/main.rb
Outdated
| # end | ||
| else | ||
| puts "Invalid choice" | ||
| end No newline at end of file |
There was a problem hiding this comment.
This case will only execute once per execution of the file. What if i want to repeat this until the user choose a specific option to exit like option 4: type 'exit' to quit. Can you make it like this?
Also the size of each case block is too long, i think it's better to split it in methods for each case block.
|
|
||
| # Debt sustainability based on GDP and debt ratio | ||
| def debt_sustainability(country_name, gdp, debt) | ||
| if is_imf_member?(country_name) |
There was a problem hiding this comment.
Why are we checking this again when we have already checked this in loan_eligibility method?
| end | ||
|
|
||
| # Check if the country is committed to reforms | ||
| def commitment_to_reforms(country_name) |
There was a problem hiding this comment.
Again why this method?
| 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" |
There was a problem hiding this comment.
| "Country is not a member of IMF" | |
| "Country is not a member of IMF so loan can't be approved" |
|
|
||
| # Method to assess cybersecurity preparedness | ||
| def cybersecurity_preparedness(total_incidents, resolved_incidents) | ||
| return 'Total incidents cannot be zero' if total_incidents == 0 |
There was a problem hiding this comment.
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.
| module DebtGdpRatio | ||
| # Method to calculate debt-to-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 |
There was a problem hiding this comment.
You can create a new separate module file for this module and include it in all other modules instead of defining this same module in each other individual module.
| end | ||
|
|
||
| # Define module EconomicAnalysis | ||
| module EconomicAnalysis |
There was a problem hiding this comment.
After moving DebtGdpRatio into separate file you can include that in this file like below.
| module EconomicAnalysis | |
| module EconomicAnalysis | |
| include DebtGdpRatio |
Same goes for the other modules.
No description provided.