Class: SalesforceCertificationCalculator::UI

Inherits:
Object
  • Object
show all
Defined in:
lib/salesforce_certification_calculator/u_i.rb

Constant Summary collapse

SFC =
SalesforceCertificationCalculator

Instance Method Summary collapse

Instance Method Details

#provide_all_details_manuallyExam

Allows user to provide all exam data manually

Examples:

Input Information

>> ui = UI.new
>> exam = ui.provide_all_details_manually
=> <SalesforceCertificationCalculator::Exam 0x000987>

Returns:

  • (Exam)

    object with name, file, and section details, including scores for each section



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

Examples:

Enter Scores

>> ui = UI.new
>> reader = FileReader.new
>> exams = reader.generate_exams_list
>> exam = ui.select_specific_exam(exams)
>> updated_exam = ui.provide_scores(exam)
=> <SalesforceCertificationCalculator::Exam 0x000987>

Parameters:

  • exam (Exam)

    object with name, file, and section details

Returns:

  • (Exam)

    object with name, file, and section details, updated with the individual 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_newString

Allows user to select between viewing a list of all existing exams or inputting all data manually

Examples:

Make Choice

>> ui = UI.new
>> choice = ui.select_list_or_new
=> 'LIST'

Returns:

  • (String)

    ‘LIST’ to indicate user wants to see a list of all existing exams; ‘NEW’ to indicate user wants to input 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

Examples:

Select a Specific Exam

>> ui = UI.new
>> reader = FileReader.new
>> exams = reader.generate_exams_list
>> exam = ui.select_specific_exam(exams)
=> <SalesforceCertificationCalculator::Exam 0x000987>

Parameters:

  • exams (Array)

    collection of Exam objects to use for selection

Returns:

  • (Exam)

    object with name, file, and section details for selected exam



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