forked from saasbook/ruql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.rb
79 lines (64 loc) · 2.63 KB
/
example.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# A quiz has a mandatory name and optional time limit in minutes.
# There's also various other obscure options not documented here.
quiz 'Example quiz', :time_limit => 45 do
# Examples of quiz questions.
# All questions have an optional :points => n that determines the
# number of points the question is worth. The value is
# non-normalized, i.e. it's relative only to other questions. Default
# is 1 if omitted.
# This is straight Ruby code, so you can put in expressions, etc.
# short answer/fill in blanks questions:
# - provide a string or regexp to check answer
# - a "blank" is three or more hyphens in a row
# - all regexps are case-INSENSITIVE unless :case_sensitive => true is passed
fill_in :points => 2 do
text 'The capital of California is ---'
answer 'sacramento'
end
# multiple blanks, order matters: answer must be an array
fill_in do
text 'The --- brown fox jumped over the lazy ---'
answer [/fox/, /dog/]
end
# multiple blanks, order doesn't matter but no answer can be reused
fill_in :order => false do
text 'Two of the Three Stooges are --- and ---'
answer %w(moe larry curly)
end
# true/false questions - explanation is optional
truefalse true, 'The week has 7 days.'
truefalse false, 'The earth is flat.', :explanation => 'No, just looks that way'
# multiple choice questions (one correct answer):
# - can provide a generic 'explanation' clause and/or override it
# with specific explanations to accompany right or wrong answers.
# - if :randomize => true is given, order of choices will be randomized
# (default is to preserve order)
choice_answer :points => 3, :randomize => true do
text "What is the largest US state?"
explanation "Not big enough." # for distractors without their own explanation
answer 'Alaska'
distractor 'Hawaii'
distractor 'Texas', :explanation => "That's pretty big, but think colder."
end
# multiple choice question with HTML markup in question text or answer
# choices (eg for code)
choice_answer :raw => true do
text %Q{What does the following code do:
<pre>
puts "Hello world!"
</pre>
}
distractor 'Throws an exception', :explanation => "Don't be an idiot."
answer 'Prints a friendly message'
end
# "select all that are true" question
# Just like choice_answer, but multiple 'answer' clauses allowed
select_multiple do
text "Which are American political parties?"
answer "Democrats"
answer "Republicans"
answer "Greens", :explanation => "Yes, they're a party!"
distractor "Tories", :explanation => "They're British"
distractor "Social Democrats"
end
end