Class: StudentProgress::CLI
- Inherits:
-
Object
- Object
- StudentProgress::CLI
- Defined in:
- lib/student_progress/cli.rb
Instance Method Summary collapse
- #call ⇒ Object
- #display_students ⇒ Object
- #goodbye ⇒ Object
- #list_choices ⇒ Object
- #list_cohorts ⇒ Object
- #list_previous_reports ⇒ Object
- #main_menu ⇒ Object
- #prompt_for_cohort_by_number ⇒ Object
- #prompt_for_cohort_name ⇒ Object
- #prompt_for_goal ⇒ Object
- #prompt_for_login ⇒ Object
- #prompt_for_reports ⇒ Object
- #prompt_for_usernames ⇒ Object
Instance Method Details
#call ⇒ Object
2 3 4 5 6 7 8 |
# File 'lib/student_progress/cli.rb', line 2 def call puts "Hello from CLI" prompt_for_login StudentProgress::Scraper.scrape_lessons goodbye end |
#display_students ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/student_progress/cli.rb', line 131 def display_students output = [] now = DateTime.now output << now.strftime('%b %e, %Y %l:%M %p') @selected_cohort ||= StudentProgress::Student.all @selected_cohort.run_progress_report if @goal output << "\n" output << "Students should #{@goal[:goal]} by the end of the week" output << "To do that, they'll have completed #{@goal[:lessons]} lessons and #{@goal[:labs]} labs" end headers = ['Student Name', 'Current Lab', 'Lessons', 'Labs'] report = @selected_cohort.progress_reports.last rows = report.student_reports.collect.with_index(1) do |student_report| [student_report.student_name, student_report.current_lab, student_report.lessons_complete, student_report.labs_complete] end table = Terminal::Table.new headings: headers, rows: rows output << table if @goal split_by_progress = report.on_track(@goal, @selected_cohort) on_track = split_by_progress[:on_track].collect.with_index(1) do |student_report| [student_report.student_name, student_report.current_lab, student_report.lessons_complete, student_report.labs_complete] end behind = split_by_progress[:behind].collect.with_index(1) do |student_report| [student_report.student_name, student_report.current_lab, student_report.lessons_complete, student_report.labs_complete] end ahead = split_by_progress[:ahead].collect.with_index(1) do |student_report| [student_report.student_name, student_report.current_lab, student_report.lessons_complete, student_report.labs_complete] end behind_table = Terminal::Table.new headings: headers, rows: behind on_track_table = Terminal::Table.new headings: headers, rows: on_track ahead_table = Terminal::Table.new headings: headers, rows: ahead output << "BEHIND" output << behind_table output << "ON TRACK" output << on_track_table output << "Ahead" output << ahead_table end report.content = output.join("\n") report.save puts output end |
#goodbye ⇒ Object
202 203 204 205 |
# File 'lib/student_progress/cli.rb', line 202 def goodbye puts "\n" puts "Thanks for using the Student Tracker CLI! See you next time!!!" end |
#list_choices ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/student_progress/cli.rb', line 49 def list_choices puts "Choose an option below by number" puts "1. Select Cohort" puts "2. Add Cohort" puts "3. Set goal for the week" puts "4. To view a list of past reports" puts "'exit' to leave the program" puts "type 'menu' at any point if you'd like to see these options again" end |
#list_cohorts ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/student_progress/cli.rb', line 59 def list_cohorts @selected_cohort = nil until @selected_cohort || @input == "exit" puts "Please select the cohort you'd like to view details for" StudentProgress::Cohort.all.each.with_index(1) do |cohort, index| puts "#{index}. #{cohort.name}" end @input = gets.strip if @input.to_i > 0 && @input.to_i <= StudentProgress::Cohort.count @selected_cohort = StudentProgress::Cohort.all[@input.to_i - 1] elsif @input == "exit" || @input == "back" return else puts "Whoops! Didn't understand that input" end end display_students end |
#list_previous_reports ⇒ Object
196 197 198 199 200 |
# File 'lib/student_progress/cli.rb', line 196 def list_previous_reports DB[:progress_reports].each do |p| puts "#{p[:id]}. #{p[:created_at].strftime('%b %e, %Y %l:%M %p')}" if p[:created_at] end end |
#main_menu ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/student_progress/cli.rb', line 20 def @input = nil @goal = nil @selected_cohort = nil list_choices while @input != "exit" puts "type 'exit' at any point to quit or 'menu' to see your options" @input = gets.strip if @input == 'menu' list_choices elsif @input == '1' list_cohorts elsif @input == '2' prompt_for_cohort_name elsif @input == '3' prompt_for_goal elsif @input == '4' prompt_for_reports elsif @input == 'exit' break elsif @input == 'debug' binding.pry else puts "Whoops! I didn't understand that" list_choices end end end |
#prompt_for_cohort_by_number ⇒ Object
78 79 80 |
# File 'lib/student_progress/cli.rb', line 78 def prompt_for_cohort_by_number end |
#prompt_for_cohort_name ⇒ Object
82 83 84 85 86 87 |
# File 'lib/student_progress/cli.rb', line 82 def prompt_for_cohort_name puts "Please enter the name of the cohort you'd like to create" name = gets.chomp @new_cohort = StudentProgress::Cohort.find_or_create(name: name) prompt_for_usernames end |
#prompt_for_goal ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/student_progress/cli.rb', line 97 def prompt_for_goal @goal = nil puts "Which topic should students be working in at the end of the week?" StudentProgress::Topic.all.each.with_index(1) {|t,i| puts "#{i}. #{t.title}"} @input = gets.strip if @input == "exit" return elsif @input.to_i <= 0 puts "Make sure you enter a number in range" prompt_for_goal elsif topic = StudentProgress::Topic.all[@input.to_i-1] puts "Great! We'll be looking within #{topic.title}" else puts "Whoops! Don't have that option" prompt_for_goal end while @input != "exit" && @goal.nil? puts "Which unit should students finish by the end of the week?" topic.units.each.with_index(1) {|t,i| puts "#{i}. #{t.title}"} @input = gets.strip if @input == "exit" return elsif @input.to_i <= 0 puts "Make sure you enter a number in range" prompt_for_goal elsif unit = topic.units[@input.to_i-1] puts "Great! We'll set the goal for the week" @goal = StudentProgress::Lesson.progress_when_unit_complete(unit.title) else puts "Whoops! Don't have that option" end end end |
#prompt_for_login ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/student_progress/cli.rb', line 10 def prompt_for_login puts "Log in to your learn.co account:" print "Email: " email = gets.strip puts "\n" print "Password: " password = STDIN.noecho(&:gets).chomp StudentProgress::Scraper.login_user(email, password) end |
#prompt_for_reports ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/student_progress/cli.rb', line 176 def prompt_for_reports list_previous_reports @input = nil until @input == "exit" || @input == "back" puts "Enter the number of the report you'd like to view (type 'back' to return to main menu)" puts "You can also type 'list' to see the list of reports again" @input = gets.strip if DB[:progress_reports].first(id: @input.to_i) puts DB[:progress_reports].first(id: @input.to_i)[:content] elsif @input == "list" list_previous_reports elsif @input == "exit" || @input == "back" break else put "Whoops! I didn't understand that." end end end |
#prompt_for_usernames ⇒ Object
89 90 91 92 93 94 95 |
# File 'lib/student_progress/cli.rb', line 89 def prompt_for_usernames puts "Please enter the GitHub usernames for the students you'd like info about (separated by commas)" usernames = gets.chomp.split(',').map(&:strip) puts "Hang on a sec, adding #{usernames.count} students" @new_cohort.add_students(usernames) puts "All done!" end |