quiz_master 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 09793a75650ae624f014961a958ef09200897de6
4
- data.tar.gz: 1295731425c36fe6102eec09c597a6b51baa0d13
3
+ metadata.gz: f36424722d7858fc0043388e0bcef810ddf656e4
4
+ data.tar.gz: 64f08b1237efe768726c9074273fda972c751680
5
5
  SHA512:
6
- metadata.gz: 059830f6aacc192b851e2f04e3e474fee6529218f7769e9e34746a6374353533380c7d78e76ddc2a7b50238850cf0e2025b53f99085711cadd05f517209cb3fa
7
- data.tar.gz: 464e3605d6583ba127fb985dc879a74f958b8ebba989a84b95fbea62adec880736e467ffc51af70ef1e012640ac808708d3de045e51ca0ff920bc8f8e823fe6d
6
+ metadata.gz: 7350ceb335a2e36be33902c8a0dde0dc6f423f7eb85f0e7ad5b3291cc77c8e054b21b4162f6364256caa55336f8df78f5cc4a5065564f9dec13c56e470036b8c
7
+ data.tar.gz: 3a26fba34d62deadce6085e68f3d64fdb38c4bb28dcd4c92d350f1f9d554be36e94f08c0c9a23fafbc8cb02c4c9c9f8656a8f9cd078e1975e0c9016aec1cd1de
data/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ # Change log
2
+
3
+ ## master (unreleased)
4
+
5
+ ### New features
6
+
7
+ ### Bugs fixed
8
+
9
+ ## 0.0.2 (2014-07-24)
10
+
11
+ ### New Features
12
+
13
+ * [#1](https://github.com/mikestok/quiz_master/issues/1): Add TextQuestionSheetFormatter
14
+
15
+ ## 0.0.1 (2014-07-20)
16
+
17
+ ### New Features
18
+
19
+ * [#2](https://github.com/mikestok/quiz_master/issues/2): Add TextAnswerSheetFormatter
data/Rakefile CHANGED
@@ -21,6 +21,6 @@ end
21
21
 
22
22
  RDoc::Task.new do |rdoc|
23
23
  rdoc.main = 'README.md'
24
- rdoc.rdoc_files.include('README.md', 'lib/**/*.rb')
24
+ rdoc.rdoc_files.include('README.md', 'CHANGELOG.md', 'lib/**/*.rb')
25
25
  rdoc.options << '--markup=tomdoc'
26
26
  end
data/lib/quiz_master.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'quiz_master/version'
2
2
  require 'quiz_master/text_question_formatter'
3
3
  require 'quiz_master/text_answer_sheet_formatter'
4
+ require 'quiz_master/text_question_sheet_formatter'
4
5
  require 'quiz_master/question'
5
6
  require 'quiz_master/rendered_question'
6
7
  require 'quiz_master/answer'
@@ -13,10 +13,16 @@ module QuizMaster
13
13
 
14
14
  # Public: Initialize an Answer.
15
15
  #
16
- # text - a String of text for the answer.
16
+ # text - a String of text for the answer.
17
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.
18
+ # tag - an optional String which can be used to reference this Answer
19
+ # from other Answers.
20
+ #
21
+ # Examples
22
+ #
23
+ # a1 = Answer.new('Correct!', true)
24
+ # a1.text # => 'Correct!'
25
+ # a1.correct? # => true
20
26
  def initialize(text, correct, tag = nil)
21
27
  @text = text.to_s
22
28
  @correct = correct
@@ -1,14 +1,26 @@
1
1
  module QuizMaster
2
2
  # A quiz is a set of questions and their answers.
3
+ #
4
+ # Examples
5
+ #
6
+ # quiz = Quiz.new([q1, q2, q3, q4])
3
7
  class Quiz
8
+ # Gets the String to be used as the header of a Quiz.
9
+ attr_reader :header
10
+ # Gets the String to be used as the footer of a Quiz.
11
+ attr_reader :footer
12
+ # Gets the Array of Questions in the Quiz.
13
+ attr_reader :questions
14
+
4
15
  # Public: Initialize a quiz with an Array of Quesitons.
5
16
  #
6
- # questions - An Array of Questions
7
- def initialize(questions)
17
+ # questions - An Array of Questions.
18
+ # header - A String containg header text (optional).
19
+ # footer - A String containg footer text (optional).
20
+ def initialize(questions, header: '', footer: '')
8
21
  @questions = questions
22
+ @header = header
23
+ @footer = footer
9
24
  end
10
-
11
- # Gets the Array of Questions
12
- attr_reader :questions
13
25
  end
14
26
  end
@@ -1,10 +1,40 @@
1
1
  module QuizMaster
2
2
  # This class is responsible for formatting a Question as a text
3
3
  # representation.
4
+ #
5
+ # In its current state it is used to help with testing and debugging, so
6
+ # notions such as line length aren't considered.
7
+ #
8
+ # Examples
9
+ #
10
+ # include QuizMaster
11
+ #
12
+ # q = Question.new(
13
+ # prompt: 'This is the prompt. It poses the question.',
14
+ # answers: [
15
+ # Answer.new('This is the first answer', '5'),
16
+ # Answer.new('This is the second answer'),
17
+ # Answer.new('This is the third answer', '3'),
18
+ # Answer.new('{{3}} and {{5}}')
19
+ # ]
20
+ # )
21
+ #
22
+ # TextQuestionFormatter.new.format(q, 1)
23
+ # # =>
24
+ # # 1) This is the prompt. It poses the question.
25
+ # #
26
+ # # a) This is the first answer
27
+ # # b) This is the second answer
28
+ # # c) This is the third answer
29
+ # # d) (a) and (c)
30
+ #
4
31
  class TextQuestionFormatter
5
32
  # Public: This formats a question and its answers with a leading number.
6
33
  #
7
- # Returns: A String containing the formatted Question.
34
+ # question - The Question to be formatted into a String.
35
+ # number - An Integer used as the number for the Question.
36
+ #
37
+ # Returns a String containing the formatted Question.
8
38
  def format(question, number)
9
39
  answers = AnswersRenderer.new(answers: question.answers, first_tag: 'a')
10
40
 
@@ -0,0 +1,33 @@
1
+ require_relative 'text_question_formatter'
2
+
3
+ module QuizMaster
4
+ # This is responsible for generating a text version of Quizes.
5
+ class TextQuestionSheetFormatter
6
+ def initialize
7
+ @question_formatter = TextQuestionFormatter.new
8
+ end
9
+
10
+ # Format a given Quiz
11
+ #
12
+ # quiz - The Quiz to be formatted
13
+ #
14
+ # Returns a String containing the formatted Quiz.
15
+ def format(quiz)
16
+ header(quiz) + "\n" + questions(quiz) + "\n" + footer(quiz)
17
+ end
18
+
19
+ private def header(quiz)
20
+ quiz.header + "\n"
21
+ end
22
+
23
+ private def questions(quiz)
24
+ quiz.questions.zip(1 .. Float::INFINITY).map do |q, n|
25
+ @question_formatter.format(q, n)
26
+ end.join("\n")
27
+ end
28
+
29
+ private def footer(quiz)
30
+ quiz.footer + "\n"
31
+ end
32
+ end
33
+ end
@@ -1,5 +1,5 @@
1
1
  #
2
2
  module QuizMaster
3
3
  # The Gem version. We will use semantic versioning: http://semver.org
4
- VERSION = '0.0.1'
4
+ VERSION = '0.0.2'
5
5
  end
data/quiz_master.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ['mike@stok.ca']
11
11
  spec.summary = 'Simple manager for multiple choice quizzes'
12
12
  # spec.description = %q{TODO: Write a longer description. Optional.}
13
- spec.homepage = ''
13
+ spec.homepage = 'https://github.com/mikestok/quiz_master'
14
14
  spec.license = 'MIT'
15
15
 
16
16
  # Because there are likely to be / characters in the regular expressions
@@ -1,5 +1,4 @@
1
1
  require 'minitest/spec'
2
- require 'minitest/mock'
3
2
  require 'minitest/autorun'
4
3
  require 'quiz_master'
5
4
 
@@ -1,5 +1,4 @@
1
1
  require 'minitest/spec'
2
- require 'minitest/mock'
3
2
  require 'minitest/autorun'
4
3
  require 'quiz_master'
5
4
 
@@ -0,0 +1,56 @@
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'quiz_master'
4
+
5
+ include QuizMaster
6
+
7
+ expected_output = <<ETX
8
+ Header
9
+
10
+ 1) This is the prompt. It poses the question.
11
+
12
+ a) This is the first answer
13
+ b) This is the second answer
14
+ c) This is the third answer
15
+ d) (a) and (c)
16
+
17
+ 2) What is the colour of a Banana?
18
+
19
+ a) Red
20
+ b) Green
21
+ c) Yellow
22
+ d) Brown
23
+ e) Black
24
+ f) All of the above except (a)
25
+
26
+ Footer
27
+ ETX
28
+
29
+ q = Question.new(
30
+ prompt: 'This is the prompt. It poses the question.',
31
+ answers: [
32
+ Answer.new('This is the first answer', false, '5'),
33
+ Answer.new('This is the second answer', false),
34
+ Answer.new('This is the third answer', true, '3'),
35
+ Answer.new('{{3}} and {{5}}', false)
36
+ ]
37
+ )
38
+ q2 = Question.new(
39
+ prompt: 'What is the colour of a Banana?',
40
+ answers: [
41
+ Answer.new('Red', false, 'red'),
42
+ Answer.new('Green', false),
43
+ Answer.new('Yellow', false),
44
+ Answer.new('Brown', false),
45
+ Answer.new('Black', false),
46
+ Answer.new('All of the above except {{red}}', true)
47
+ ]
48
+ )
49
+
50
+ quiz = Quiz.new([q, q2], header: 'Header', footer: 'Footer')
51
+
52
+ describe TextQuestionSheetFormatter do
53
+ it 'formats a test OK' do
54
+ TextQuestionSheetFormatter.new.format(quiz).must_equal expected_output
55
+ end
56
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quiz_master
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Stok
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-20 00:00:00.000000000 Z
11
+ date: 2014-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -104,6 +104,7 @@ files:
104
104
  - ".gitignore"
105
105
  - ".rubocop.yml"
106
106
  - ".travis.yml"
107
+ - CHANGELOG.md
107
108
  - Gemfile
108
109
  - LICENSE.txt
109
110
  - README.md
@@ -117,11 +118,13 @@ files:
117
118
  - lib/quiz_master/text_answer_sheet_formatter.rb
118
119
  - lib/quiz_master/text_assembler.rb
119
120
  - lib/quiz_master/text_question_formatter.rb
121
+ - lib/quiz_master/text_question_sheet_formatter.rb
120
122
  - lib/quiz_master/version.rb
121
123
  - quiz_master.gemspec
122
124
  - test/test_text_answer_sheet_formatter.rb
123
125
  - test/test_text_question_formatter.rb
124
- homepage: ''
126
+ - test/test_text_question_sheet_formatter.rb
127
+ homepage: https://github.com/mikestok/quiz_master
125
128
  licenses:
126
129
  - MIT
127
130
  metadata: {}
@@ -148,4 +151,5 @@ summary: Simple manager for multiple choice quizzes
148
151
  test_files:
149
152
  - test/test_text_answer_sheet_formatter.rb
150
153
  - test/test_text_question_formatter.rb
154
+ - test/test_text_question_sheet_formatter.rb
151
155
  has_rdoc: