Class: Rubedility::Lesson

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lesson_hash) ⇒ Lesson

Returns a new instance of Lesson.



6
7
8
9
10
# File 'lib/rubedility/lesson.rb', line 6

def initialize(lesson_hash)
  add_lesson_attributes(lesson_hash)
  @tasks = []
  @@all.push(self)
end

Instance Attribute Details

#lesson_urlObject

Returns the value of attribute lesson_url.



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

def lesson_url
  @lesson_url
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#numberObject

Returns the value of attribute number.



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

def number
  @number
end

#reading_urlObject

Returns the value of attribute reading_url.



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

def reading_url
  @reading_url
end

#tests_solvedObject

Returns the value of attribute tests_solved.



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

def tests_solved
  @tests_solved
end

#tests_startedObject

Returns the value of attribute tests_started.



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

def tests_started
  @tests_started
end

Class Method Details

.allObject



20
21
22
# File 'lib/rubedility/lesson.rb', line 20

def self.all
  @@all
end

.display_allObject



43
44
45
46
47
48
49
50
# File 'lib/rubedility/lesson.rb', line 43

def self.display_all
  puts "\nAvailable Lessons: \n"
  self.all.each do |les|
    puts "#{les.number}. #{les.name}"
  end
  puts "\n"
  return nil
end

.populate_from_scraping(lessons_array) ⇒ Object



14
15
16
17
18
# File 'lib/rubedility/lesson.rb', line 14

def self.populate_from_scraping(lessons_array)
  lessons_array.each do |lesson|
    self.new(lesson)
  end
end

.user_display_oneObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubedility/lesson.rb', line 24

def self.user_display_one
  self.display_all
  print "Select Lesson Number:"
  input = gets.strip.to_i
  self.all.each do |lesson|
    if lesson.number==input
      lesson.display_lesson
      return nil
    end
  end
  puts "Try selecting a correct number next time."
end

.user_display_statsObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rubedility/lesson.rb', line 52

def self.user_display_stats
  self.display_all
  print "Select Lesson Number for stats:"
  input = gets.strip.to_i
  self.all.each do |lesson|
    if lesson.number==input
      lesson.display_stats
      return nil
    end
  end
  return "Try selecting a correct number next time."
end

.user_open_readingObject



71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/rubedility/lesson.rb', line 71

def self.user_open_reading
  self.display_all
  print "Select Lesson Number for reading:"
  input = gets.strip.to_i
  self.all.each do |lesson|
    if lesson.number==input
      #lesson.open_reading
      return lesson.reading_url
    end
  end
  return "Try selecting a correct number next time."
end

Instance Method Details

#add_lesson_attributes(attributes_hash) ⇒ Object



99
100
101
102
103
104
# File 'lib/rubedility/lesson.rb', line 99

def add_lesson_attributes(attributes_hash)
  if attributes_hash == nil
    return
  end
  attributes_hash.each{|key, val| self.send(("#{key}="), val)}
end

#add_tasks(task_array) ⇒ Object



89
90
91
92
93
# File 'lib/rubedility/lesson.rb', line 89

def add_tasks(task_array)
  task_array.each do |task_row|
    self.tasks.push(Rubedility::Task.new(task_row))
  end
end

#display_lessonObject



37
38
39
40
41
# File 'lib/rubedility/lesson.rb', line 37

def display_lesson
  self.tasks.each do |task|
    task.display_row
  end
end

#display_statsObject



65
66
67
68
69
# File 'lib/rubedility/lesson.rb', line 65

def display_stats
  puts "\n#{self.tests_started} tests have been started from this lesson."
  puts "#{self.tests_solved} tests have been solved from this lesson."
  puts "#{self.tasks.length} task(s) gives an average success rate of #{(self.tests_solved.to_f/self.tests_started.to_f).round(3)*100}%"
end

#open_readingObject



84
85
86
87
# File 'lib/rubedility/lesson.rb', line 84

def open_reading
  puts "launchy: #{@reading_url}"
  launchy @reading_url
end

#tasksObject



95
96
97
# File 'lib/rubedility/lesson.rb', line 95

def tasks
  @tasks
end