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
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/salesforce_certification_calculator/u_i.rb', line 86 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 (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
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/salesforce_certification_calculator/u_i.rb', line 65 def provide_scores(exam) sections = exam.sections 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 |
# 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 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
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/salesforce_certification_calculator/u_i.rb', line 35 def select_specific_exam(exams) puts "Your choices are:" exams.each do |exam| puts "#{exams.find_index(exam) + 1} - #{exam.title}" end 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) return exams[choice - 1] else select_specific_exam(exams) end end |