Class: Rubedility

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

Defined Under Namespace

Classes: Lesson, Task

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRubedility

Returns a new instance of Rubedility.



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

def initialize
  scrape_index
  scrape_lessons
  scrape_tasks
  display_greeting
  #display_menu (menu will display from the 'while' loop below)
end

Class Method Details

.listObject



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

def self.list
  puts "this might one day be a list of stuff!"
end

Instance Method Details

#display_greetingObject



75
76
77
78
# File 'lib/rubedility.rb', line 75

def display_greeting
  puts "\nWelcome to Rubedility!"
  puts "Your command line access point for Ruby-flavored Codility lessons and tasks.\n"
end

#display_menuObject



80
81
82
83
# File 'lib/rubedility.rb', line 80

def display_menu
  puts "Commands: '<list/open> <lesson(s)/task(s)/stats/reading>', 'list by difficulty', 'exit'"
  #puts "Commands: 'list lessons', 'open lesson', 'list tasks', 'open task', 'list stats', 'open reading', 'exit'"
end

#run(commands = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/rubedility.rb', line 17

def run(commands=nil)
  input = ""
  until input=="exit" || input=="quit" || input=="close"

    case input
    when "list lessons"
      Lesson.display_all

    when "list tasks"
      Task.display_all

    when "list stats"
      Lesson.user_display_stats

    when "open lesson"
      Lesson.user_display_one

    when "open task"
      Task.user_display_one

    when "list by difficulty"
      Difficulty.display_all

    when "open reading"
      Launchy.open(Lesson.user_open_reading)

    else
      display_menu

    end
    input = gets.strip
  end
end

#scrape_indexObject



51
52
53
54
55
# File 'lib/rubedility.rb', line 51

def scrape_index
  print "fetching index  ..."
  Lesson.populate_from_scraping(Scraper.scrape_index_page('https://codility.com/programmers/lessons/'))
  puts "\n"
end

#scrape_lessonsObject



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

def scrape_lessons
  #this would be an ideal time for some Asynchronous magical powers of awesome
  print "fetching lessons..."
  Lesson.all.each do |lesson|
    attributes_hash, task_array = Scraper.scrape_lesson_page(lesson.lesson_url)
    lesson.add_lesson_attributes(attributes_hash)
    lesson.add_tasks(task_array)
  end
  puts "\n"
end

#scrape_tasksObject



68
69
70
71
72
73
# File 'lib/rubedility.rb', line 68

def scrape_tasks
  print "fetching tasks  ..."
  Task.all.each do |task|
    task.add_task_attributes(Scraper.scrape_task_page(task.task_url))
  end
end