Class: ProjectEulerCli::ArchiveViewer

Inherits:
Object
  • Object
show all
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

Methods included from Scraper

#load_page, #load_problem_details, #load_recent, #lookup_totals

Constructor Details

#initializeArchiveViewer

Returns a new instance of ArchiveViewer.



7
8
9
# File 'lib/project_euler_cli/archive_viewer.rb', line 7

def initialize
  lookup_totals
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



59
60
61
62
# File 'lib/project_euler_cli/archive_viewer.rb', line 59

def display_custom_page(list)
  puts
  list.each { |id| puts "#{id} - #{Problem[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)

  puts

  start = (page - 1) * Page::LENGTH + 1
  start.upto(start + Page::LENGTH - 1) do |i|
    puts "#{i} - #{Problem[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
51
52
53
54
# File 'lib/project_euler_cli/archive_viewer.rb', line 38

def display_problem(id)
  load_problem_details(id)

  puts
  puts "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
  puts
  puts Problem[id].title.upcase
  puts "Problem #{id}"
  puts
  puts Problem[id].published
  puts Problem[id].solved_by
  puts Problem[id].difficulty if id < Problem.total - 9
  puts
  puts "https://projecteuler.net/problem=#{id}"
  puts
  puts "=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-="
end

#display_recentObject

Displays the 10 most recently added problems.



12
13
14
15
16
17
18
19
20
# File 'lib/project_euler_cli/archive_viewer.rb', line 12

def display_recent
  load_recent

  puts

  (Problem.total).downto(Problem.total - 9) do |i| 
    puts "#{i} - #{Problem[i].title}" 
  end
end