Class: Difficulty

Inherits:
Object
  • Object
show all
Defined in:
lib/rubedility/difficulty.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(difficulty) ⇒ Difficulty

Returns a new instance of Difficulty.



3
4
5
6
7
# File 'lib/rubedility/difficulty.rb', line 3

def initialize(difficulty)
  @level = difficulty
  @@all.push(self)
  @all_tasks = []
end

Instance Attribute Details

#levelObject

Returns the value of attribute level.



2
3
4
# File 'lib/rubedility/difficulty.rb', line 2

def level
  @level
end

Class Method Details

.allObject



12
13
14
# File 'lib/rubedility/difficulty.rb', line 12

def self.all
  @@all
end

.display_allObject



26
27
28
29
30
31
32
33
# File 'lib/rubedility/difficulty.rb', line 26

def self.display_all
  self.all.each do |diff|
    puts "\n=====#{diff.level}====="
    diff.display_tasks
    puts "=======================\n"
  end
  puts "\n"
end

.find_or_create(task_difficulty) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/rubedility/difficulty.rb', line 35

def self.find_or_create(task_difficulty)
  self.all.each do |d|
    if d.level == task_difficulty
      return d
    end
  end
  return self.new(task_difficulty)
end

Instance Method Details

#add_task(task) ⇒ Object



44
45
46
# File 'lib/rubedility/difficulty.rb', line 44

def add_task(task)
  self.all.push(task)
end

#allObject



16
17
18
# File 'lib/rubedility/difficulty.rb', line 16

def all
  @all_tasks
end

#display_tasksObject



20
21
22
23
24
# File 'lib/rubedility/difficulty.rb', line 20

def display_tasks
  self.all.each do |task|
    puts task.name
  end
end