Class: Csv2qti::Question

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

Direct Known Subclasses

Matching, MultipleChoice, MultipleSelect

Constant Summary collapse

TYPE =
7
STEM =
8
CORRECT =
9
DISTRACTOR_1 =
10
DISTRACTOR_2 =
11
LICENSE =
12

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row) ⇒ Question

Returns a new instance of Question.



32
33
34
35
# File 'lib/csv2qti/question.rb', line 32

def initialize(row)
  @stem = process_stem(row[STEM])
  @license = row[LICENSE]
end

Instance Attribute Details

#licenseObject (readonly)

Returns the value of attribute license.



30
31
32
# File 'lib/csv2qti/question.rb', line 30

def license
  @license
end

#stemObject (readonly)

Returns the value of attribute stem.



30
31
32
# File 'lib/csv2qti/question.rb', line 30

def stem
  @stem
end

Class Method Details

.generate(row) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/csv2qti/question.rb', line 10

def self.generate(row)
  type = row[TYPE] || ''
  case type.downcase
    when ''
      raise Csv2qti::QuestionParseError, "Thought this row would be a question but its not."
    when 'mc'
      MultipleChoice.new(row)
    when 'mmc'
      MultipleSelect.new(row)
    when 'category'
      raise Csv2qti::QuestionParseError, "unsupported question type: #{row[TYPE]}"
    when 'matching'
      Matching.new(row)
    when 'process'
      raise Csv2qti::QuestionParseError, "unsupported question type: #{row[TYPE]}"
    else
      raise Csv2qti::QuestionParseError, "unknown question type: #{row[TYPE]}"
  end
end

Instance Method Details

#add_to_assessment(assessment) ⇒ Object



52
53
54
55
56
# File 'lib/csv2qti/question.rb', line 52

def add_to_assessment(assessment)
  if q = generate_cc_question
    assessment.items << q
  end
end

#add_to_group(assessment) ⇒ Object



58
59
60
61
62
# File 'lib/csv2qti/question.rb', line 58

def add_to_group(assessment)
  if q = generate_cc_question
    assessment.questions << q
  end
end

#generate_cc_questionObject



48
49
50
# File 'lib/csv2qti/question.rb', line 48

def generate_cc_question
  nil
end

#process_distractors(row) ⇒ Object



44
45
46
# File 'lib/csv2qti/question.rb', line 44

def process_distractors(row)
  [row[DISTRACTOR_1], row[DISTRACTOR_2]]
end

#process_stem(val) ⇒ Object

converts image references to html images look like this in the original value: (image: )



40
41
42
# File 'lib/csv2qti/question.rb', line 40

def process_stem(val)
  val.gsub(/\(image: ([^\)]*)\)/, %{<img src="\\1" />})
end

#to_qtiObject



64
65
66
# File 'lib/csv2qti/question.rb', line 64

def to_qti
  ''
end

#to_sObject



72
73
74
# File 'lib/csv2qti/question.rb', line 72

def to_s
  type
end

#typeObject



68
69
70
# File 'lib/csv2qti/question.rb', line 68

def type
  "unknown"
end