quiz_master 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.rubocop.yml +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +62 -0
- data/Rakefile +26 -0
- data/lib/quiz_master.rb +16 -0
- data/lib/quiz_master/answer.rb +33 -0
- data/lib/quiz_master/answers_renderer.rb +117 -0
- data/lib/quiz_master/question.rb +31 -0
- data/lib/quiz_master/quiz.rb +14 -0
- data/lib/quiz_master/rendered_question.rb +25 -0
- data/lib/quiz_master/text_answer_sheet_formatter.rb +21 -0
- data/lib/quiz_master/text_assembler.rb +66 -0
- data/lib/quiz_master/text_question_formatter.rb +16 -0
- data/lib/quiz_master/version.rb +5 -0
- data/quiz_master.gemspec +31 -0
- data/test/test_text_answer_sheet_formatter.rb +40 -0
- data/test/test_text_question_formatter.rb +31 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 09793a75650ae624f014961a958ef09200897de6
|
4
|
+
data.tar.gz: 1295731425c36fe6102eec09c597a6b51baa0d13
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 059830f6aacc192b851e2f04e3e474fee6529218f7769e9e34746a6374353533380c7d78e76ddc2a7b50238850cf0e2025b53f99085711cadd05f517209cb3fa
|
7
|
+
data.tar.gz: 464e3605d6583ba127fb985dc879a74f958b8ebba989a84b95fbea62adec880736e467ffc51af70ef1e012640ac808708d3de045e51ca0ff920bc8f8e823fe6d
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
html/
|
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Use the default set of cops as a starting point
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Mike Stok
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
[![PullReview stats](https://www.pullreview.com/github/mikestok/quiz_master/badges/master.svg?)](https://www.pullreview.com/github/mikestok/quiz_master/reviews/master)
|
2
|
+
[![Build
|
3
|
+
Status](https://secure.travis-ci.org/mikestok/quiz_master.png)](http://travis-ci.org/mikestok/quiz_master)
|
4
|
+
|
5
|
+
# QuizMaster
|
6
|
+
|
7
|
+
This is a gem which will contain the components necessary to create multiple
|
8
|
+
choice tests, and generate question and answer sheets for those tests.
|
9
|
+
|
10
|
+
**It is currently in a pre-release state** as I experiment with its internal
|
11
|
+
structure and use it as a "programming exercise yard".
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
gem 'quiz_master'
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install quiz_master
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
At the moment the only working part is a **crude** text formatter:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'quiz_master'
|
33
|
+
|
34
|
+
include QuizMaster
|
35
|
+
|
36
|
+
q = Question.new(
|
37
|
+
prompt: 'This is the prompt. It poses the question.',
|
38
|
+
answers: [
|
39
|
+
Answer.new('This is the first answer', '5'),
|
40
|
+
Answer.new('This is the second answer'),
|
41
|
+
Answer.new('This is the third answer', '3'),
|
42
|
+
Answer.new('{{3}} and {{5}}')
|
43
|
+
]
|
44
|
+
)
|
45
|
+
|
46
|
+
TextQuestionFormatter.new.format(q, 1)
|
47
|
+
# =>
|
48
|
+
# 1) This is the prompt. It poses the question.
|
49
|
+
#
|
50
|
+
# a) This is the first answer
|
51
|
+
# b) This is the second answer
|
52
|
+
# c) This is the third answer
|
53
|
+
# d) (a) and (c)
|
54
|
+
```
|
55
|
+
|
56
|
+
## Contributing
|
57
|
+
|
58
|
+
1. Fork it ( https://github.com/mikestok/quiz_master/fork )
|
59
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
60
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
61
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
62
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rubocop/rake_task'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rdoc/task'
|
5
|
+
|
6
|
+
task default: [:test]
|
7
|
+
|
8
|
+
desc 'Run RuboCop on the lib directory'
|
9
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
10
|
+
task.patterns = ['Rakefile', 'lib/**/*.rb']
|
11
|
+
# only show the files with failures
|
12
|
+
task.formatters = ['files']
|
13
|
+
# don't abort rake on failure
|
14
|
+
task.fail_on_error = false
|
15
|
+
end
|
16
|
+
|
17
|
+
Rake::TestTask.new do |t|
|
18
|
+
t.libs << 'test'
|
19
|
+
t.test_files = FileList['test/**/test_*.rb']
|
20
|
+
end
|
21
|
+
|
22
|
+
RDoc::Task.new do |rdoc|
|
23
|
+
rdoc.main = 'README.md'
|
24
|
+
rdoc.rdoc_files.include('README.md', 'lib/**/*.rb')
|
25
|
+
rdoc.options << '--markup=tomdoc'
|
26
|
+
end
|
data/lib/quiz_master.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'quiz_master/version'
|
2
|
+
require 'quiz_master/text_question_formatter'
|
3
|
+
require 'quiz_master/text_answer_sheet_formatter'
|
4
|
+
require 'quiz_master/question'
|
5
|
+
require 'quiz_master/rendered_question'
|
6
|
+
require 'quiz_master/answer'
|
7
|
+
require 'quiz_master/quiz'
|
8
|
+
require 'quiz_master/answers_renderer'
|
9
|
+
require 'quiz_master/text_assembler'
|
10
|
+
|
11
|
+
# This provides a namespace for all of the components.
|
12
|
+
module QuizMaster
|
13
|
+
# This error is raised when something discovers that there are the wrong
|
14
|
+
# number of correct answers in a set of answers.
|
15
|
+
NumberOfCorrectAnswersError = Class.new(StandardError)
|
16
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module QuizMaster
|
2
|
+
# This is the representation of Answers in the system.
|
3
|
+
#
|
4
|
+
# In the "raw" state the tags are optional and allow Answers to reference each
|
5
|
+
# other using {{ and }} to surround a reference to another Answer's tag in
|
6
|
+
# the text.
|
7
|
+
class Answer
|
8
|
+
# Public: Returns the String tag associated with the Answer. This can be
|
9
|
+
# +nil+ if there is no associated tag.
|
10
|
+
attr_reader :tag
|
11
|
+
# Public: Returns the String of text associated with the Answer.
|
12
|
+
attr_reader :text
|
13
|
+
|
14
|
+
# Public: Initialize an Answer.
|
15
|
+
#
|
16
|
+
# text - a String of text for the answer.
|
17
|
+
# correct - whether this answer is true or false.
|
18
|
+
# tag - an optional String which can be used to reference this Answer from
|
19
|
+
# other Answers.
|
20
|
+
def initialize(text, correct, tag = nil)
|
21
|
+
@text = text.to_s
|
22
|
+
@correct = correct
|
23
|
+
@tag = tag
|
24
|
+
end
|
25
|
+
|
26
|
+
# Public: Tell whether this Answer is correct
|
27
|
+
#
|
28
|
+
# Returns +true+ or +false+
|
29
|
+
def correct?
|
30
|
+
@correct ? true : false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
module QuizMaster
|
2
|
+
# Public: This renders a list of answers into a new list of answers updating
|
3
|
+
# tag references enclosed in {{...}} so that the new answers have tags
|
4
|
+
# starting at +first_tag+
|
5
|
+
class AnswersRenderer
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
# Public: Initialize an AnswersRenderer object.
|
9
|
+
#
|
10
|
+
# answers - An Array of Answer objects.
|
11
|
+
# first_tag - Something that responds to #succ which is used as the initial
|
12
|
+
# tag in the stream of yielded Answers.
|
13
|
+
def initialize(answers:, first_tag:)
|
14
|
+
@first_tag = first_tag
|
15
|
+
@tag_map = make_tag_map(answers)
|
16
|
+
@rendered_answers = render_answers(answers)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Public: Allows iteration over the rendered answers.
|
20
|
+
#
|
21
|
+
# Yields an Answer object.
|
22
|
+
#
|
23
|
+
# Returns nothing.
|
24
|
+
def each
|
25
|
+
@rendered_answers.each do |a|
|
26
|
+
yield a
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
# Private: Create a mapping from the tags used in the original questions
|
33
|
+
# passed to our initialize to the tags we'll use in the rendered answer.
|
34
|
+
# The tag map will be used when substituting the {{xxx}} constructs from
|
35
|
+
# the original answers.
|
36
|
+
#
|
37
|
+
# original_answers - an Array of Answer objects.
|
38
|
+
#
|
39
|
+
# Examples
|
40
|
+
#
|
41
|
+
# # oa = [ Answer('{{x}} and {{y}}'), # will be tagged as 'a'
|
42
|
+
# # Answer('foo', 'y'), # will be tagged as 'b'
|
43
|
+
# # Answer('bar', 'x') ] # will be tagged as 'c'
|
44
|
+
# make_tag_map(oa)
|
45
|
+
# # => { 'x' => 'c', 'y' => 'b' }
|
46
|
+
#
|
47
|
+
# Returns a Hash mapping the original_answers tags to rendered answers
|
48
|
+
# tags.
|
49
|
+
def make_tag_map(original_answers)
|
50
|
+
tagged_list(original_answers).each_with_object({}) do |(tag, ans), map|
|
51
|
+
map[ans.tag] = tag if ans.tag
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Private: This takes the original_answers and re-tags them starting with
|
56
|
+
# @first_tag, and resolves any {{...}} tags in the answer text to reference
|
57
|
+
# the new tags.
|
58
|
+
#
|
59
|
+
# original_answers - and Array of Answer objects
|
60
|
+
#
|
61
|
+
# Returns an Array of Answer objects.
|
62
|
+
def render_answers(original_answers)
|
63
|
+
tagged_list(original_answers).map do |tag, answer|
|
64
|
+
Answer.new(replace_tags(answer.text), answer.correct?, tag)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Private: This replaces the tag place holders in a string with references
|
69
|
+
# to the generated tags using the tag map.
|
70
|
+
#
|
71
|
+
# string - The String which might contain tag place holders.
|
72
|
+
#
|
73
|
+
# Returns a String with the tag place holders replaced with the correct
|
74
|
+
# tags.
|
75
|
+
def replace_tags(string)
|
76
|
+
string
|
77
|
+
.split(/({{[^}]+}})/)
|
78
|
+
.each_with_object(TextAssembler.new) do |fragment, assembler|
|
79
|
+
if (m = /\A{{([^}]+)}}\z/.match(fragment))
|
80
|
+
assembler.add_tag_reference @tag_map.fetch(m[1])
|
81
|
+
else
|
82
|
+
assembler.add_text fragment
|
83
|
+
end
|
84
|
+
end.to_s
|
85
|
+
end
|
86
|
+
|
87
|
+
# Private: A utility method to label a list with tags starting from
|
88
|
+
# @first_tag
|
89
|
+
#
|
90
|
+
# Examples
|
91
|
+
#
|
92
|
+
# # assuming @first_tag = 'a'
|
93
|
+
# tagged_list %w(foo bar baz)
|
94
|
+
# # => [['a', 'foo'], ['b', 'bar'], ['c', 'baz']
|
95
|
+
#
|
96
|
+
# Returns an Array whose elements are Arrays containing [tag, list_element]
|
97
|
+
def tagged_list(list)
|
98
|
+
list.zip(tag_sequence).map do |element, tag|
|
99
|
+
[tag, element]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Private: This makes a new Enumerator which will generate a stream of tags
|
104
|
+
# starting with @first_tag.
|
105
|
+
#
|
106
|
+
# Returns an Enumerator which generates tags.
|
107
|
+
def tag_sequence
|
108
|
+
Enumerator.new do |yielder|
|
109
|
+
tag = @first_tag
|
110
|
+
loop do
|
111
|
+
yielder.yield tag.dup
|
112
|
+
tag = tag.succ
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module QuizMaster
|
2
|
+
# A simple class to link a prompt to a list of Answers.
|
3
|
+
class Question
|
4
|
+
# Get the String prompt for the Question.
|
5
|
+
attr_reader :prompt
|
6
|
+
# Get the Array of Answer objects for the Question.
|
7
|
+
attr_reader :answers
|
8
|
+
|
9
|
+
# Public: Initialize a Question
|
10
|
+
#
|
11
|
+
# prompt - A String which poses the question.
|
12
|
+
# answers - An Array of Answer objects.
|
13
|
+
#
|
14
|
+
# Examples
|
15
|
+
#
|
16
|
+
# Question.new('Is 5 odd?', [Answer.new('Yes'), Answer.new('No')])
|
17
|
+
def initialize(prompt:, answers:)
|
18
|
+
@prompt = prompt.clone
|
19
|
+
@answers = answers.clone
|
20
|
+
end
|
21
|
+
|
22
|
+
# Public: Return the correct answer for this question.
|
23
|
+
#
|
24
|
+
# Examples
|
25
|
+
#
|
26
|
+
# Returns a clone of the correct Answer.
|
27
|
+
def correct_answer
|
28
|
+
answers.find(&:correct?).clone
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module QuizMaster
|
2
|
+
# A quiz is a set of questions and their answers.
|
3
|
+
class Quiz
|
4
|
+
# Public: Initialize a quiz with an Array of Quesitons.
|
5
|
+
#
|
6
|
+
# questions - An Array of Questions
|
7
|
+
def initialize(questions)
|
8
|
+
@questions = questions
|
9
|
+
end
|
10
|
+
|
11
|
+
# Gets the Array of Questions
|
12
|
+
attr_reader :questions
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative 'question'
|
2
|
+
require_relative 'answers_renderer'
|
3
|
+
|
4
|
+
module QuizMaster
|
5
|
+
# This class is a question which has its answers rendered.
|
6
|
+
class RenderedQuestion < Question
|
7
|
+
# Public: Initialize a RenderedQuestion
|
8
|
+
#
|
9
|
+
# prompt - A String to use as the propmpt.
|
10
|
+
# answers - An Array of Answers.
|
11
|
+
# first_tag - The tag to use on the initial rendered Answer (must respond
|
12
|
+
# to .succ).
|
13
|
+
#
|
14
|
+
# Returns nothing.
|
15
|
+
# Raises WrongNumberOfCorrectAnswers if there isn't exactly 1 correct Answer
|
16
|
+
def initialize(prompt:, answers:, first_tag:)
|
17
|
+
correct_answers = answers.count { |a| a.correct? }
|
18
|
+
fail NumberOfCorrectAnswersError unless correct_answers == 1
|
19
|
+
|
20
|
+
super(prompt: prompt,
|
21
|
+
answers: AnswersRenderer.new(answers: answers,
|
22
|
+
first_tag: first_tag).to_a)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module QuizMaster
|
2
|
+
# This class is responsible for formatting a quiz as text.
|
3
|
+
class TextAnswerSheetFormatter
|
4
|
+
# Public: Generate the textual representation of the answer sheet for the
|
5
|
+
# provided Quiz.
|
6
|
+
#
|
7
|
+
# quiz - The Quiz whose answer sheet we want formatted.
|
8
|
+
#
|
9
|
+
# Returns a String containing the answer sheet.
|
10
|
+
def format(quiz)
|
11
|
+
# See: http://banisterfiend.wordpress.com/2009/10/02/wtf-infinite-ranges-in-ruby/
|
12
|
+
#
|
13
|
+
# This generates an infinite range which we can use for numbering the
|
14
|
+
# questions.
|
15
|
+
numbers = (1 .. Float::INFINITY)
|
16
|
+
quiz.questions.zip(numbers).each_with_object('') do |(q, number), result|
|
17
|
+
result << "#{number}) #{q.correct_answer.tag}\n"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module QuizMaster
|
2
|
+
# A TextAssembler is a utility whose String representation (from to_s)
|
3
|
+
# contains text fragments and references to tags. The references to tags
|
4
|
+
# are surrounded with parentheses, and they are sorted in the output of
|
5
|
+
# to_s .
|
6
|
+
#
|
7
|
+
# The sorting in to_s is a speculative feature, it seems to make sense from a
|
8
|
+
# cosmetic perspective, and will work as long as the answers are simple "(a)
|
9
|
+
# and (c)".
|
10
|
+
#
|
11
|
+
# Examples
|
12
|
+
#
|
13
|
+
# ta = TextAssember.new
|
14
|
+
# ta.add_text 'Both '
|
15
|
+
# ta.add_tag_reference 'b'
|
16
|
+
# ta.add_text ' and '
|
17
|
+
# ta.add_tag_reference 'a'
|
18
|
+
# ta.to_s
|
19
|
+
# # => 'Both (a) and (b)'
|
20
|
+
class TextAssembler
|
21
|
+
# Public: Create a TextAssembler object
|
22
|
+
def initialize
|
23
|
+
@tags = []
|
24
|
+
@format_string = ''
|
25
|
+
end
|
26
|
+
|
27
|
+
# Public: Add a tag reference to the text we are assembling.
|
28
|
+
#
|
29
|
+
# tag - The tag to be added.
|
30
|
+
#
|
31
|
+
# Examples
|
32
|
+
#
|
33
|
+
# ta.add_tag_reference 'x'
|
34
|
+
#
|
35
|
+
# Returns nothing.
|
36
|
+
def add_tag_reference(tag)
|
37
|
+
@tags << tag
|
38
|
+
@format_string << '(%s)'
|
39
|
+
end
|
40
|
+
|
41
|
+
# Public: Add some literal text to the text we are assembling.
|
42
|
+
#
|
43
|
+
# text - The text to be added.
|
44
|
+
#
|
45
|
+
# Examples
|
46
|
+
#
|
47
|
+
# ta.add_text ' The cat sat on the mat'
|
48
|
+
#
|
49
|
+
# Returns nothing.
|
50
|
+
def add_text(text)
|
51
|
+
@format_string << text.gsub('%', '%%')
|
52
|
+
end
|
53
|
+
|
54
|
+
# Public: Get the String representation of the TextAssembler.
|
55
|
+
#
|
56
|
+
# Examples
|
57
|
+
#
|
58
|
+
# ta.to_s
|
59
|
+
# # => '(x) The cat sat on the mat'
|
60
|
+
#
|
61
|
+
# Returns a String representing the TextAssembler state.
|
62
|
+
def to_s
|
63
|
+
@format_string % @tags.sort
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module QuizMaster
|
2
|
+
# This class is responsible for formatting a Question as a text
|
3
|
+
# representation.
|
4
|
+
class TextQuestionFormatter
|
5
|
+
# Public: This formats a question and its answers with a leading number.
|
6
|
+
#
|
7
|
+
# Returns: A String containing the formatted Question.
|
8
|
+
def format(question, number)
|
9
|
+
answers = AnswersRenderer.new(answers: question.answers, first_tag: 'a')
|
10
|
+
|
11
|
+
answers.each_with_object("#{number}) #{question.prompt}\n\n") do |a, text|
|
12
|
+
text << " #{a.tag}) #{a.text}\n"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/quiz_master.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'quiz_master/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'quiz_master'
|
8
|
+
spec.version = QuizMaster::VERSION
|
9
|
+
spec.authors = ['Mike Stok']
|
10
|
+
spec.email = ['mike@stok.ca']
|
11
|
+
spec.summary = 'Simple manager for multiple choice quizzes'
|
12
|
+
# spec.description = %q{TODO: Write a longer description. Optional.}
|
13
|
+
spec.homepage = ''
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
# Because there are likely to be / characters in the regular expressions
|
17
|
+
# we relax the rubocop checks for a bit...
|
18
|
+
# rubocop:disable Style/RegexpLiteral
|
19
|
+
spec.files = `git ls-files -z`.split("\x0")
|
20
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
# rubocop:enable Style/RegexpLiteral
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.6'
|
26
|
+
spec.add_development_dependency 'rake'
|
27
|
+
spec.add_development_dependency 'rubocop'
|
28
|
+
spec.add_development_dependency 'rdoc'
|
29
|
+
spec.add_development_dependency 'inch'
|
30
|
+
spec.add_development_dependency 'sparkr' # inch should have included this...
|
31
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
require 'minitest/mock'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'quiz_master'
|
5
|
+
|
6
|
+
include QuizMaster
|
7
|
+
|
8
|
+
expected_output = <<ETX
|
9
|
+
1) b
|
10
|
+
2) d
|
11
|
+
ETX
|
12
|
+
|
13
|
+
q1 = RenderedQuestion.new(
|
14
|
+
prompt: 'This is the prompt. It poses the question.',
|
15
|
+
answers: [
|
16
|
+
Answer.new('This is the first answer', false, '5'),
|
17
|
+
Answer.new('This is the second answer', true),
|
18
|
+
Answer.new('This is the third answer', false, '3'),
|
19
|
+
Answer.new('This is the fourth answer {{tag', false)
|
20
|
+
],
|
21
|
+
first_tag: 'a'
|
22
|
+
)
|
23
|
+
q2 = RenderedQuestion.new(
|
24
|
+
prompt: 'This is the prompt. It poses the question.',
|
25
|
+
answers: [
|
26
|
+
Answer.new('This is the first answer', false, 'tag'),
|
27
|
+
Answer.new('This is the second answer', false),
|
28
|
+
Answer.new('This is the third answer', false),
|
29
|
+
Answer.new('This is the fourth answer {{tag}}', true)
|
30
|
+
],
|
31
|
+
first_tag: 'a'
|
32
|
+
)
|
33
|
+
|
34
|
+
quiz = Quiz.new([q1, q2])
|
35
|
+
|
36
|
+
describe TextAnswerSheetFormatter do
|
37
|
+
it 'formats a single question test OK' do
|
38
|
+
TextAnswerSheetFormatter.new.format(quiz).must_equal expected_output
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'minitest/spec'
|
2
|
+
require 'minitest/mock'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'quiz_master'
|
5
|
+
|
6
|
+
include QuizMaster
|
7
|
+
|
8
|
+
expected_output = <<ETX
|
9
|
+
1) This is the prompt. It poses the question.
|
10
|
+
|
11
|
+
a) This is the first answer
|
12
|
+
b) This is the second answer
|
13
|
+
c) This is the third answer
|
14
|
+
d) (a) and (c)
|
15
|
+
ETX
|
16
|
+
|
17
|
+
q = Question.new(
|
18
|
+
prompt: 'This is the prompt. It poses the question.',
|
19
|
+
answers: [
|
20
|
+
Answer.new('This is the first answer', false, '5'),
|
21
|
+
Answer.new('This is the second answer', true),
|
22
|
+
Answer.new('This is the third answer', false, '3'),
|
23
|
+
Answer.new('{{3}} and {{5}}', false)
|
24
|
+
]
|
25
|
+
)
|
26
|
+
|
27
|
+
describe TextQuestionFormatter do
|
28
|
+
it 'formats a single question test OK' do
|
29
|
+
TextQuestionFormatter.new.format(q, 1).must_equal expected_output
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quiz_master
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Stok
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rdoc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: inch
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sparkr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- mike@stok.ca
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rubocop.yml"
|
106
|
+
- ".travis.yml"
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- lib/quiz_master.rb
|
112
|
+
- lib/quiz_master/answer.rb
|
113
|
+
- lib/quiz_master/answers_renderer.rb
|
114
|
+
- lib/quiz_master/question.rb
|
115
|
+
- lib/quiz_master/quiz.rb
|
116
|
+
- lib/quiz_master/rendered_question.rb
|
117
|
+
- lib/quiz_master/text_answer_sheet_formatter.rb
|
118
|
+
- lib/quiz_master/text_assembler.rb
|
119
|
+
- lib/quiz_master/text_question_formatter.rb
|
120
|
+
- lib/quiz_master/version.rb
|
121
|
+
- quiz_master.gemspec
|
122
|
+
- test/test_text_answer_sheet_formatter.rb
|
123
|
+
- test/test_text_question_formatter.rb
|
124
|
+
homepage: ''
|
125
|
+
licenses:
|
126
|
+
- MIT
|
127
|
+
metadata: {}
|
128
|
+
post_install_message:
|
129
|
+
rdoc_options: []
|
130
|
+
require_paths:
|
131
|
+
- lib
|
132
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '0'
|
142
|
+
requirements: []
|
143
|
+
rubyforge_project:
|
144
|
+
rubygems_version: 2.2.2
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: Simple manager for multiple choice quizzes
|
148
|
+
test_files:
|
149
|
+
- test/test_text_answer_sheet_formatter.rb
|
150
|
+
- test/test_text_question_formatter.rb
|
151
|
+
has_rdoc:
|