Skip to content

Commit

Permalink
finish the detect_exercise_type function with case-when clause
Browse files Browse the repository at this point in the history
  • Loading branch information
yangchenyun committed Jun 4, 2012
1 parent 77a2e9c commit 92b9462
Showing 1 changed file with 41 additions and 28 deletions.
69 changes: 41 additions & 28 deletions lib/sm_to_anki.rb
Expand Up @@ -22,8 +22,38 @@
# {course_name}.media/

module SmToAnki
module ItemProcessor

def simple_qa(question, answer)
# process the item.xml as simple Question and Answer
# write to output text
# {{Question}}, {{Answer}}, {{Explanation}}, [{{Image_URL}}], {{}}
return {}
end

def cloze(question, answer)
# process the item.xml as blank filling questions
# write to output text
#
return {}
end

def truth(question, answer)
# process item.xml as a truthy question
return {}
end

def checkbox(question, answer)
return {}
end

def radio(question, answer)
return {}
end
end

class CourseProcessor
include SmToAnki::ItemProcessor
attr_reader :process_dir, :course_doc, :course_info
# Read the course.xml file
# Your code goes here...
Expand Down Expand Up @@ -63,9 +93,19 @@ def build_anki_dir
end

def detect_exercise_type(item_url)
return true
# call the processing function accordingly
# Store different types in different text files
item = Nokogiri.XML(File.open(item_url))
answer = item.at_css('item > answer').inner_html if item.at_css('item answer')
question = item.at_css('item > question').inner_html if item.at_css('item question')
return nil unless question
case question
when /checkbox/ then checkbox(question, answer)
when /spellpad/ then cloze(question, answer)
when /radio/ then radio(question, answer)
when /true-false/ then truth(question, answer)
else simple_qa(question, answer)
end
end

def post_process
Expand Down Expand Up @@ -95,33 +135,6 @@ def fetch_node(node)

end

module ItemProcessor

def simple_qa(tags)
tags.push('simple_qa')
# process the item.xml as simple Question and Answer
# write to output text
# {{Question}}, {{Answer}}, {{Explanation}}, [{{Image_URL}}], {{Tags}}
end

def blank_qa(tags)
tags.push('blank_filling')
# process the item.xml as blank filling questions
# write to output text
#
end

def truth_qa(tags)
tags.push('truthy')
# process item.xml as a truthy question
end

def multi_choice_qa(tags)
tags.push('multi_choice')

end

end


module ProcessorHelper
Expand Down

0 comments on commit 92b9462

Please sign in to comment.