Class: ProjectEulerCli::ArchiveViewer
- Inherits:
-
Object
- Object
- ProjectEulerCli::ArchiveViewer
- Includes:
- Scraper
- Defined in:
- lib/project_euler_cli/archive_viewer.rb
Overview
Handles the work of displaying information about the problems.
Instance Method Summary collapse
-
#display_custom_page(list) ⇒ Object
Displays a custom page of problems given by an array of IDs.
-
#display_page(page) ⇒ Object
Displays the problem numbers and titles for an individual page of the archive.
-
#display_problem(id) ⇒ Object
Displays the details of an individual problem.
-
#display_recent ⇒ Object
Displays the 10 most recently added problems.
-
#initialize(problems) ⇒ ArchiveViewer
constructor
A new instance of ArchiveViewer.
Methods included from Scraper
#load_page, #load_problem_details, #load_recent, #lookup_totals
Constructor Details
#initialize(problems) ⇒ ArchiveViewer
Returns a new instance of ArchiveViewer.
7 8 9 |
# File 'lib/project_euler_cli/archive_viewer.rb', line 7 def initialize(problems) @problems = problems end |
Instance Method Details
#display_custom_page(list) ⇒ Object
Displays a custom page of problems given by an array of IDs.
-
list- Array of problem IDs
55 56 57 58 |
# File 'lib/project_euler_cli/archive_viewer.rb', line 55 def display_custom_page(list) puts list.each { |id| puts "#{id} - #{@problems[id].title}" } end |
#display_page(page) ⇒ Object
Displays the problem numbers and titles for an individual page of the archive.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/project_euler_cli/archive_viewer.rb', line 24 def display_page(page) load_page(page, @problems) puts i = (page - 1) * Page::LENGTH Page::LENGTH.times do puts "#{i += 1} - #{@problems[i].title}" unless i >= Problem.total - 9 end end |
#display_problem(id) ⇒ Object
Displays the details of an individual problem.
-
id- ID of the problem to be displayed
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/project_euler_cli/archive_viewer.rb', line 38 def display_problem(id) load_problem_details(id, @problems) puts puts "#{@problems[id].title}".upcase puts "Problem #{id}" puts puts @problems[id].published puts @problems[id].solved_by puts @problems[id].difficulty if id < Problem.total - 9 puts puts "https://projecteuler.net/problem=#{id}" end |