Class: ForgetfulApp

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/forgetful-web.rb

Overview


Instance Method Summary collapse

Instance Method Details

#filenames2json(filenames) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/forgetful-web.rb', line 19

def filenames2json(filenames)
  filenames = Array(filenames)

  data = filenames.map do |filename|
    questions = questionaire_from(filename).questions.sort_by { rand }
    {filename: filename, questions: questions}
  end
  data = data.select { |quiz| quiz[:questions].any? }

  JSON.generate(data)
end

#questionaire_from(filename) ⇒ Object



31
32
33
34
# File 'lib/forgetful-web.rb', line 31

def questionaire_from(filename)
  csv_file = ReminderFile.new(filename)
  Questionaire.new(csv_file)
end