Class: SalesforceCertificationCalculator::UI
- Inherits:
-
Object
- Object
- SalesforceCertificationCalculator::UI
- Defined in:
- lib/salesforce_certification_calculator/u_i.rb
Constant Summary collapse
Instance Method Summary collapse
-
#provide_all_details_manually ⇒ Exam
Allows user to provide all exam data manually.
-
#provide_scores(exam) ⇒ Exam
Allows user to input their scores for each section.
-
#select_list_or_new ⇒ String
Allows user to select between viewing a list of all existing exams or inputting all data manually.
-
#select_specific_exam(exams) ⇒ Exam
Allows user to select which exam from the list of existing exams to use.
Instance Method Details
#provide_all_details_manually ⇒ Exam
Allows user to provide all exam data manually
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/salesforce_certification_calculator/u_i.rb', line 98 def provide_all_details_manually exam = SFC::Exam.new puts "What is the title of this exam?" exam.title = gets.chomp puts "How many sections does it have?" length = gets.chomp.to_i # Get names, weights, and scores for each section of the exam from the user (1..length).each do |i| puts "What is the name of Section #{i}?" name = gets.chomp puts "How many percentage points is Section #{i} worth?" weight = gets.chomp.to_i puts "What score did you get on Section #{i}?" score = gets.chomp.to_i exam.add_section(name, weight, score) end return exam end |
#provide_scores(exam) ⇒ Exam
Allows user to input their scores for each section
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/salesforce_certification_calculator/u_i.rb', line 76 def provide_scores(exam) sections = exam.sections # Get scores for each section from the user sections.each do |section| puts "#{section.name} is worth #{section.weight}%" puts "What score did you get on that section? (enter an integer)" score = gets.chomp.to_i section.score = score end return exam end |
#select_list_or_new ⇒ String
Allows user to select between viewing a list of all existing exams or inputting all data manually
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/salesforce_certification_calculator/u_i.rb', line 12 def select_list_or_new puts "Do you want to select an exam from a list (enter LIST), or do you want to type in your own details (enter NEW)?" choice = gets.chomp # Only return value if user selected one of the two provided options; otherwise, recursively recall function if choice == "LIST" || choice == "NEW" return choice else select_list_or_new() end end |
#select_specific_exam(exams) ⇒ Exam
Allows user to select which exam from the list of existing exams to use
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/salesforce_certification_calculator/u_i.rb', line 36 def select_specific_exam(exams) exams_length = exams.length puts "Your choices are:" # List exam options exams.each do |exam| puts "#{exams.find_index(exam) + 1} - #{exam.title}" end # Add option to let user enter details manually if exam not listed puts "#{exams_length + 1} - NOT LISTED" puts "Which one would you like to select? Enter the number before the exam name:" choice = gets.chomp.to_i if choice.between?(1, exams_length) # Only return value if user inputted number within range return exams[choice - 1] elsif choice == exams_length + 1 # Enter details manually if exam not included in list provide_all_details_manually() else # Recursively recall function if invalid input select_specific_exam(exams) end end |