Class: Question
- Inherits:
-
Object
- Object
- Question
- Defined in:
- lib/ruql/question.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#answers ⇒ Object
Returns the value of attribute answers.
-
#name ⇒ Object
Returns the value of attribute name.
-
#points ⇒ Object
Returns the value of attribute points.
-
#question_comment ⇒ Object
Returns the value of attribute question_comment.
-
#question_group ⇒ Object
Returns the value of attribute question_group.
-
#question_tags ⇒ Object
Returns the value of attribute question_tags.
-
#question_text ⇒ Object
Returns the value of attribute question_text.
-
#randomize ⇒ Object
Returns the value of attribute randomize.
-
#uid(str) ⇒ Object
Returns the value of attribute uid.
Instance Method Summary collapse
- #answer(text, opts = {}) ⇒ Object
- #as_json ⇒ Object
- #comment(str = '') ⇒ Object
- #correct_answer ⇒ Object
- #correct_answers ⇒ Object
- #distractor(text, opts = {}) ⇒ Object
- #explanation(text) ⇒ Object
- #group(str) ⇒ Object
-
#initialize(*args) ⇒ Question
constructor
A new instance of Question.
- #raw? ⇒ Boolean
-
#tags(*args) ⇒ Object
these are ignored but legal for now:.
- #text(s) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Question
Returns a new instance of Question.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/ruql/question.rb', line 4 def initialize(*args) = if args[-1].kind_of?(Hash) then args[-1] else {} end @answers = [:answers] || [] @points = [[:points].to_i, 1].max @raw = [:raw] @name = [:name] @question_tags = [] @question_group = '' @question_comment = '' end |
Instance Attribute Details
#answers ⇒ Object
Returns the value of attribute answers.
2 3 4 |
# File 'lib/ruql/question.rb', line 2 def answers @answers end |
#name ⇒ Object
Returns the value of attribute name.
2 3 4 |
# File 'lib/ruql/question.rb', line 2 def name @name end |
#points ⇒ Object
Returns the value of attribute points.
2 3 4 |
# File 'lib/ruql/question.rb', line 2 def points @points end |
#question_comment ⇒ Object
Returns the value of attribute question_comment.
2 3 4 |
# File 'lib/ruql/question.rb', line 2 def question_comment @question_comment end |
#question_group ⇒ Object
Returns the value of attribute question_group.
2 3 4 |
# File 'lib/ruql/question.rb', line 2 def question_group @question_group end |
#question_tags ⇒ Object
Returns the value of attribute question_tags.
2 3 4 |
# File 'lib/ruql/question.rb', line 2 def @question_tags end |
#question_text ⇒ Object
Returns the value of attribute question_text.
2 3 4 |
# File 'lib/ruql/question.rb', line 2 def question_text @question_text end |
#randomize ⇒ Object
Returns the value of attribute randomize.
2 3 4 |
# File 'lib/ruql/question.rb', line 2 def randomize @randomize end |
#uid(str) ⇒ Object
Returns the value of attribute uid.
2 3 4 |
# File 'lib/ruql/question.rb', line 2 def uid @uid end |
Instance Method Details
#answer(text, opts = {}) ⇒ Object
38 39 40 |
# File 'lib/ruql/question.rb', line 38 def answer(text, opts={}) @answers << Answer.new(text, correct=true, opts[:explanation]) end |
#as_json ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ruql/question.rb', line 15 def as_json Hash( :question_text => @question_text, :question_tags => @question_tags.compact, :question_group => @question_group, :answers => @answers.map(&:as_json), :question_type => self.class.to_s, :raw => !!@raw, :name => @name, :points => @points ).compact end |
#comment(str = '') ⇒ Object
59 60 61 |
# File 'lib/ruql/question.rb', line 59 def comment(str = '') @question_comment = str.to_s end |
#correct_answer ⇒ Object
63 |
# File 'lib/ruql/question.rb', line 63 def correct_answer ; @answers.detect(&:correct?) ; end |
#correct_answers ⇒ Object
65 |
# File 'lib/ruql/question.rb', line 65 def correct_answers ; @answers.collect(&:correct?) ; end |
#distractor(text, opts = {}) ⇒ Object
42 43 44 |
# File 'lib/ruql/question.rb', line 42 def distractor(text, opts={}) @answers << Answer.new(text, correct=false, opts[:explanation]) end |
#explanation(text) ⇒ Object
34 35 36 |
# File 'lib/ruql/question.rb', line 34 def explanation(text) @answers.each { |answer| answer.explanation ||= text } end |
#group(str) ⇒ Object
46 47 48 |
# File 'lib/ruql/question.rb', line 46 def group(str) @question_group = str end |
#raw? ⇒ Boolean
30 |
# File 'lib/ruql/question.rb', line 30 def raw? ; !!@raw ; end |
#tags(*args) ⇒ Object
these are ignored but legal for now:
51 52 53 54 55 56 57 |
# File 'lib/ruql/question.rb', line 51 def (*args) # string or array of strings if args.length > 1 @question_tags += args.map(&:to_s) else @question_tags << args.first.to_s end end |
#text(s) ⇒ Object
32 |
# File 'lib/ruql/question.rb', line 32 def text(s) ; @question_text = s ; end |