Skip to content

Latest commit

 

History

History
127 lines (87 loc) · 3.06 KB

README.md

File metadata and controls

127 lines (87 loc) · 3.06 KB

INFO

A Ruby parser for the GIFT question format.

GIFT is the format used by Moodle Learning Management System for writing multiple-choice, true-false, short answer, match missing word and numerical questions.

For details on the GIFT file format see: http://docs.moodle.org/en/GIFT

The parser is generated by Treetop parser generator. http://treetop.rubyforge.org/

P.S. The parser is not yet complete. It generates the syntactic tree but does not have all the semantic features as yet. It will give marks for answers using pattern matching of strings to mark close answers.

See the tests to get an idea on how the parser is supposed to be used.

See the file LICENCE for copyright details. (MIT license.)

Authors

Original Author: https://github.com/stuart/gift-parser Stuart Coyle 2010

Usage

In this gem you can see two main classes:

  1. Gift - it's a main class, whitch take an argument with GIFT string or file
  2. GiftParse - it's automatic generated class from treetop
require 'gift'

parser = Gift::Gift.new(my_gift_file)

# all questions
parser.questions

# count of all questions
parser.questions.count # or length

# questions enumerators
parser.questions.each { |q| ... }

When you will iterate in questions list, you will see, that every question object is instance of special class. It can be TrueFalseQuestion, DescriptionQuestion, ShortAnswerQuestion, EssayQuestion, MultipleChoiceQuestion, NumericQuestion, MatchQuestion, FillInQuestion

Every instance has methods to get any info about question:

# get title ::this is title::
question.title

# get text of question
question.text

# get list of answers
question.answers

# get list of correct answers (where :correct => true)
question.correct_answers

# get comment //this is comment
question.comment

# get markup lang. info e.g. [html]
question.markup_language

Formats of answers

# TrueFalseQuestion#answers
[{:value => true, :correct => true, :feedback => "Feedback string"}]  

# DescriptionQuestion#answers
[]

# EssayQuestion#answers
[]

# MultipleChoiceQuestion#answers
[
  {:value => "Grant", :correct=> true, :feedback=> nil}, 
  {:value => "No one", :correct => false, :feedback => "Was true for 12 years, but Grant's remains were buried in the tomb in 1897"}
]

# ShortAnswerQuestion#answers
[
  {:feedback => nil, :value => "Grant", :correct => true}, 
  {:feedback => nil, :value => "Ulysses S. Grant", :correct => true}, 
  {:feedback => nil, :value => "Ulysses Grant" , :correct => true}
] 

# NumericQuestion#answers
[{:minimum => "1822", :maximum => "1822"}]

# MatchQuestion#answers
{'Canada' => 'Ottowa','Italy' => 'Rome'}

# FillInQuestion#answers
[
  {:value => 'second', :correct => false},
  {:value => 'third', :correct => false},
  {:value => 'fourth', :correct => true}
]

Contributing

  1. Fork it ( https://github.com/[my-github-username]/gift-parser/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request