Class: ProjectEulerCli::Problem

Inherits:
Object
  • Object
show all
Defined in:
lib/project_euler_cli/problem.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeProblem

Returns a new instance of Problem.



8
9
10
# File 'lib/project_euler_cli/problem.rb', line 8

def initialize
  @@all << self
end

Instance Attribute Details

#difficultyObject

Returns the value of attribute difficulty.



4
5
6
# File 'lib/project_euler_cli/problem.rb', line 4

def difficulty
  @difficulty
end

#publishedObject

Returns the value of attribute published.



4
5
6
# File 'lib/project_euler_cli/problem.rb', line 4

def published
  @published
end

#solved_byObject

Returns the value of attribute solved_by.



4
5
6
# File 'lib/project_euler_cli/problem.rb', line 4

def solved_by
  @solved_by
end

#titleObject

Returns the value of attribute title.



4
5
6
# File 'lib/project_euler_cli/problem.rb', line 4

def title
  @title
end

Class Method Details

.[](id) ⇒ Object



12
13
14
# File 'lib/project_euler_cli/problem.rb', line 12

def self.[](id)
  @@all[id - 1]
end

.[]=(id, value) ⇒ Object



16
17
18
# File 'lib/project_euler_cli/problem.rb', line 16

def self.[]=(id, value)
  @@all[id - 1] = value
end

.page(id) ⇒ Object

call-seq:

get_page(id) => page

Returns page number based on the ID of the problem. The recent page is considered page 0.



29
30
31
# File 'lib/project_euler_cli/problem.rb', line 29

def self.page(id)
  id.between?(1, total - 10) ? (id - 1) / Page::LENGTH + 1 : 0
end

.totalObject



20
21
22
# File 'lib/project_euler_cli/problem.rb', line 20

def self.total
  @@all.size
end