Class: ProjectEulerCli::Problem
- Inherits:
-
Object
- Object
- ProjectEulerCli::Problem
- Defined in:
- lib/project_euler_cli/problem.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#difficulty ⇒ Object
Returns the value of attribute difficulty.
-
#published ⇒ Object
Returns the value of attribute published.
-
#solved_by ⇒ Object
Returns the value of attribute solved_by.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
- .[](id) ⇒ Object
- .[]=(id, value) ⇒ Object
-
.page(id) ⇒ Object
call-seq: get_page(id) => page.
- .total ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Problem
constructor
A new instance of Problem.
Constructor Details
#initialize ⇒ Problem
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
#difficulty ⇒ Object
Returns the value of attribute difficulty.
4 5 6 |
# File 'lib/project_euler_cli/problem.rb', line 4 def difficulty @difficulty end |
#published ⇒ Object
Returns the value of attribute published.
4 5 6 |
# File 'lib/project_euler_cli/problem.rb', line 4 def published @published end |
#solved_by ⇒ Object
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 |
#title ⇒ Object
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 |
.total ⇒ Object
20 21 22 |
# File 'lib/project_euler_cli/problem.rb', line 20 def self.total @@all.size end |