/
kitchen_sink_survey.rb
218 lines (187 loc) · 8.47 KB
/
kitchen_sink_survey.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
survey "“Kitchen Sink” survey" do
section "Basic questions" do
# A label is a question that accepts no answers
label "These questions are examples of the basic supported input types"
# A basic question with radio buttons
question_1 "What is your favorite color?", :pick => :one
answer "red"
answer "blue"
answer "green"
answer "yellow"
answer :other
# A basic question with checkboxes
# "question" and "answer" may be abbreviated as "q" and "a"
q_2 "Choose the colors you don't like", :pick => :any
a_1 "red"
a_2 "blue"
a_3 "green"
a_4 "yellow"
a :omit
# A dependent question, with conditions and rule to logically join them
# the question's reference identifier is "2a", and the answer's reference_identifier is "1"
# question reference identifiers used in conditions need to be unique on a survey for the lookups to work
q_2a "Please explain why you don't like this color?"
a_1 "explanation", :text
dependency :rule => "A or B or C or D"
condition_A :q_2, "==", :a_1
condition_B :q_2, "==", :a_2
condition_C :q_2, "==", :a_3
condition_D :q_2, "==", :a_4
# When :pick isn't specified, the default is :none (no checkbox or radio button)
q_montypython3 "What... is your name? (e.g. It is 'Arthur', King of the Britons)"
a_1 :string
# Dependency conditions can refer to any value, not just answer_id. An answer_reference still needs to be specified, to know which answer you would like to check
q_montypython4 "What... is your quest? (e.g. To seek the Holy Grail)"
a_1 :string
dependency :rule => "A"
condition_A :q_montypython3, "==", {:string_value => "It is 'Arthur', King of the Britons", :answer_reference => "1"}
# http://www.imdb.com/title/tt0071853/quotes
q_montypython5 "What... is the air-speed velocity of an unladen swallow? (e.g. What do you mean? An African or European swallow?)"
a_1 :string
dependency :rule => "A"
condition_A :q_montypython4, "==", {:string_value => "To seek the Holy Grail", :answer_reference => "1"}
label "Huh? I-- I don't know that! Auuuuuuuugh!"
dependency :rule => "A"
condition_A :q_montypython5, "==", {:string_value => "What do you mean? An African or European swallow?", :answer_reference => "1"}
# Surveys, sections, questions, groups, and answers all take the following reference arguments
# :reference_identifier # usually from paper
# :data_export_identifier # data export
# :common_namespace # maping to a common vocab
# :common_identifier # maping to a common vocab
q "Get me started on an improv sketch", :reference_identifier => "improv_start", :data_export_identifier => "i_s", :common_namespace => "sketch comedy questions", :common_identifier => "get me started"
a "who", :string
a "what", :string
a "where", :string
# Various types of responses can be accepted, and validated
q "How many pets do you own?"
a :integer
validation :rule => "A"
condition_A ">=", :integer_value => 0
# Surveys, sections, questions, groups, and answers also take a custom css class for covenience in custom styling
q "What is your address?", :custom_class => 'address'
a :text, :custom_class => 'mapper'
# validations can use regexp values
validation :rule => "A"
condition_A "=~", :regexp => /[0-9a-zA-z\. #]/
# Questions, groups, and answers take a custom renderer (a partial in the application's views dir)
# defaults are "/partials/question_group", "/partials/question", "/partials/answer", so the custom renderers should have a different name
q "Pick your favorite date AND time" #, :custom_renderer => "/partials/custom_question"
a :datetime
q_time_lunch "What time do you usually take a lunch break?"
a_1 :time
# # validation conditions can look up the response to another question/answer pair
# q_time_dinner "What time do you usually take a dinner break?"
# a :time
# validation :rule => "A"
# condition_A ">=", :question_reference => "time_lunch", :answer_reference => "1"
q "When would you like to meet for dinner?"
a :date
# Sliders deprecate to select boxes when javascript is off
# Valid Ruby code may be used to shorted repetitive tasks
q "Adjust the slider to reflect your level of awesomeness", :pick => :one, :display_type => :slider
(1..10).to_a.each{|num| a num.to_s}
q "How much do you like Ruby?", :pick => :one, :display_type => :slider
["not at all", "a little", "some", "a lot", "a ton"].each{|level| a level}
# The "|" pipe is used to place labels before or after the input elements
q "How much money do you want?"
a "$|USD", :float
# Questions may be grouped
group "How much oil do you use per day?", :display_type => :inline do
q "Quantity"
a "Quantity", :float
q "Unit", :pick => :one, :display_type => :dropdown
a "Barrels"
a "Gallons"
a "Quarts"
end
q "Choose your Illinois county", :pick => :one, :display_type => :dropdown
["Adams","Alexander","Bond", "Boone",
"Brown","Bureau","Calhoun","Carroll","Cass",
"Champaign", "Christian", "Clark","Clay",
"Clinton", "Coles", "Cook", "Crawford","Cumberland","DeKalb",
"De Witt","Douglas","DuPage","Edgar", "Edwards",
"Effingham","Fayette", "Ford","Franklin","Fulton",
"Gallatin","Greene", "Grundy", "Hamilton","Hancock",
"Hardin","Henderson","Henry","Iroquois","Jackson",
"Jasper", "Jefferson","Jersey","Jo Daviess","Johnson",
"Kane","Kankakee","Kendall","Knox", "La Salle",
"Lake", "Lawrence", "Lee","Livingston","Logan",
"Macon","Macoupin","Madison","Marion","Marshall", "Mason",
"Massac","McDonough","McHenry","McLean","Menard",
"Mercer","Monroe", "Montgomery","Morgan","Moultrie",
"Ogle","Peoria","Perry","Piatt","Pike","Pope",
"Pulaski","Putnam","Randolph","Richland","Rock Island",
"Saline","Sangamon","Schuyler","Scott","Shelby",
"St. Clair","Stark", "Stephenson","Tazewell","Union",
"Vermilion","Wabash","Warren","Washington","Wayne",
"White","Whiteside","Will","Williamson","Winnebago","Woodford"].each{ |county| a county}
# When an is_exclusive answer is checked, it unchecks all other options and disables them (using Javascript)
q "Choose your favorite meats", :display_type => :inline, :pick => :any
a "Chicken"
a "Pork"
a "Beef"
a "Shellfish"
a "Fish"
a "I don't eat meats!!!", :is_exclusive => true
q "All out of ideas for questions?", :pick => :one, :display_type => :inline
a "yes"
a "maybe"
a "no"
a "I don't know"
end
section "Complicated questions" do
# Grids are useful for repeated questions with the same set of answers, which are specified before the questions
grid "Tell us how often do you cover these each day" do
a "1"
a "2"
a "3"
q "Head", :pick => :one
q "Knees", :pick => :one
q "Toes", :pick => :one
end
# "grid" is a shortcut for group with :display_type => :grid
# The answers will be repeated every 10 rows, but long grids aren't recommended as they are generally tedious
grid "Tell us how you feel today day" do
a "-2"
a "-1"
a "0"
a "1"
a "2"
q "down|up" , :pick => :one
q "sad|happy", :pick => :one
q "limp|perky", :pick => :one
end
q "Please rank the following foods based on how much you like them"
a "|pizza", :integer
a "|salad", :integer
a "|sushi", :integer
a "|ice cream", :integer
a "|breakfast ceral", :integer
# :other, :string allows someone to specify both the "other" and some other information
q "Choose your favorite utensils and enter frequency of use (daily, weekly, monthly, etc...)", :pick => :any
a "spoon", :string
a "fork", :string
a "knife", :string
a :other, :string
# Repeaters allow multiple responses to a question or set of questions
repeater "Tell us about the cars you own" do
q "Make", :pick => :one, :display_type => :dropdown
a "Toyota"
a "Ford"
a "GMChevy"
a "Ferrari"
a "Tesla"
a "Honda"
a "Other weak brand"
q "Model"
a :string
q "Year"
a :string
end
repeater "Tell us the name and age of your siblings" do
q "Sibling"
a "Name", :string
a "Age|years", :integer
end
end
end