Sha256: 7880e9411fbd8a598b91e5411081b681bda69039e7f74484a1cce78819028e99

Contents?: true

Size: 1.06 KB

Versions: 3

Compression:

Stored size: 1.06 KB

Contents

module ProjectEulerCli

# Controller class that manages the archive system. It holds the archive data 
# used by ArchiveViewer and ArchiveSearcher.
class ArchiveController
  include Scraper

  def initialize
    lookup_totals

    @problems = Array.new(Problem.total + 1) { Problem.new }

    @av = ArchiveViewer.new(@problems)
    @as = ArchiveSearcher.new(@problems)
  end

  def searching=(searching)
    @as.searching = searching
  end

  def searching
    @as.searching
  end

  def search(terms)
    @as.search(terms)
  end

  def results_include?(id)
    @as.results.include?(id)
  end

  def display_recent
    @av.display_recent
  end

  def display_page(page)
    @av.display_page(page)
  end

  def display_results
    @av.display_custom_page(@as.results)
  end

  def display_problem(id)
    @av.display_problem(id)
  end

  # call-seq:
  #   get_page(id) => page
  #
  # Returns page number based on the ID of the problem. The recent page is
  # considered page 0.
  def get_page(id)
    id.between?(1, Problem.total - 10) ? (id - 1) / Page::LENGTH + 1 : 0
  end

end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
project_euler_cli-1.2.0 lib/project_euler_cli/archive_controller.rb
project_euler_cli-1.1.3 lib/project_euler_cli/archive_controller.rb
project_euler_cli-1.1.2 lib/project_euler_cli/archive_controller.rb