Class: Rubedility::Task

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(task_row) ⇒ Task

Returns a new instance of Task.



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

def initialize(task_row)
  add_task_attributes(task_row)
  @@all.push(self)
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



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

def content
  @content
end

#difficultyObject

Returns the value of attribute difficulty.



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

def difficulty
  @difficulty
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#taglineObject

Returns the value of attribute tagline.



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

def tagline
  @tagline
end

#task_reading_urlObject

Returns the value of attribute task_reading_url.



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

def task_reading_url
  @task_reading_url
end

#task_urlObject

Returns the value of attribute task_url.



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

def task_url
  @task_url
end

Class Method Details

.allObject



30
31
32
# File 'lib/rubedility/task.rb', line 30

def self.all
  @@all
end

.create_from_collection(task_hash) ⇒ Object



11
12
13
14
15
# File 'lib/rubedility/task.rb', line 11

def self.create_from_collection(task_hash)
  task_hash.each do |task|
    Task.new(task)
  end
end

.display_allObject



60
61
62
63
64
65
66
# File 'lib/rubedility/task.rb', line 60

def self.display_all
  puts "\nAvailable Tasks: \n"
  self.all.each do |task|
    task.display_row
  end
  return nil
end

.user_display_oneObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rubedility/task.rb', line 34

def self.user_display_one
  print "Enter Task Name:"
  input = gets.strip.downcase
  self.all.each do |task|
    if task.name.downcase==input
      task.display_content
      return nil
    end
  end
  self.display_all
  puts "Try better next time."
end

Instance Method Details

#add_task_attributes(attributes_hash) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rubedility/task.rb', line 17

def add_task_attributes(attributes_hash)
  if attributes_hash == nil
    return
  end
  attributes_hash.each do |key, val|
    self.send(("#{key}="), val)
    if key.to_s == "difficulty"
      d = Difficulty.find_or_create(val)
      d.add_task(self)
    end
  end
end

#display_contentObject



52
53
54
55
56
57
58
# File 'lib/rubedility/task.rb', line 52

def display_content
  puts "========================================="
  puts "==========#{self.name}=========="
  puts "========================================="
  puts "Difficulty: #{self.difficulty}"
  puts @content
end

#display_rowObject



47
48
49
50
# File 'lib/rubedility/task.rb', line 47

def display_row
  puts "=#{self.name}= (#{self.difficulty})"
  puts "#{self.tagline}\n\n"
end