Class: Gipper::Quiz

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(gift_file) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/quiz.rb', line 6

def self.parse gift_file
  quiz = Quiz.new()
  gift = []
  gift_file.strip!
  
  quiz.iterate_through gift_file do |question|
    q = Gipper::Question.new
    q.parse(question)
    gift << q
  end
  
  gift
end

Instance Method Details

#iterate_through(questions) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/quiz.rb', line 20

def iterate_through questions
  questions.gsub!(/^\s*\/\/.*$/, "")  # strip out comment lines
  
  list = questions.split(/[\r\n][\r\n\t\s]*[\r\n]/)
  list.each do |item|
    if item != ''
      yield item 
    end
  end
end