word_2_quiz 1.0.0 → 1.1.1

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: bc35826919146c5dc8eaabf3d02691f0bb5d316f
4
- data.tar.gz: 774847c6a92cd29628882cff7a30bf13438bc693
3
+ metadata.gz: edc0535cb4aca7b0a501350715ddd9cdd9d3335b
4
+ data.tar.gz: d99a2def739f76cd868b82d67803de996339afac
5
5
  SHA512:
6
- metadata.gz: 857514a6a2306390ca732332838dec3f4e550b0ca34edf8092b1e20a12f24f6d753951d754d33b23573481d8cd690a2e9c2d8363f51c7e0df23b044d729878ca
7
- data.tar.gz: 76a0822f024e1e717a81841663b0f10085de535b475475d78a34544dea2b6c73d983efd18733af3f8f805618a0561a54127896de3a2b654a4c7f4481f5768a77
6
+ metadata.gz: 2603438d795c7feb575ff070522ec9663c79b6d1303afd41d0b66460dce8db91478c782e65db1626aac9d22bb48a94e06e6a0c26014b55d0dc35230482daafe3
7
+ data.tar.gz: bbeaf617acb589856ef2d93f84f99e430b8387cec8c29dfa0c31c3f9faf24ea49000f3a101c334bf29fe0a346b6989d37e2cde54a665304d1ceff2ac4427d315
data/lib/word_2_quiz.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "word_2_quiz/version"
2
2
  require "word_2_quiz/quiz_parser"
3
+ require "word_2_quiz/errors"
3
4
 
4
5
  module Word2Quiz
5
6
  end
@@ -0,0 +1,7 @@
1
+ module Word2Quiz
2
+ class InvalidAnswerKey < RuntimeError
3
+ end
4
+
5
+ class InvalidQuiz < RuntimeError
6
+ end
7
+ end
@@ -100,5 +100,12 @@ module Word2Quiz
100
100
  t.pop while t.last.text.chomp.empty?
101
101
  t
102
102
  end
103
+
104
+ ##
105
+ # Checks for if the quiz is a valid quiz we can process
106
+ ##
107
+ def self.valid_quiz?(text)
108
+ text.include?("Course Examination") && text.include?("Multiple Choice")
109
+ end
103
110
  end
104
111
  end
@@ -1,4 +1,5 @@
1
1
  require "word_2_quiz/helpers"
2
+ require "word_2_quiz/errors"
2
3
 
3
4
  module Word2Quiz
4
5
  ##
@@ -22,6 +23,13 @@ module Word2Quiz
22
23
  # solution: a string containing which answer(a,b,c,d) is correct
23
24
  ##
24
25
  def self.from_paragraphs(paragraphs, solution)
26
+ if solution.nil? || solution.empty?
27
+ raise InvalidAnswerKey.new(
28
+ "Question #{Helpers.get_question_number(paragraphs)} does not have" +
29
+ " an answer.",
30
+ )
31
+ end
32
+
25
33
  answers = []
26
34
 
27
35
  answer_start_indexes = paragraphs.each_index.select do |i|
@@ -72,6 +72,7 @@ module Word2Quiz
72
72
  {
73
73
  title: @title,
74
74
  question_count: @questions.count,
75
+ points_possible: @questions.count * Question::POINTS_POSSIBLE,
75
76
  quiz_type: "assignment",
76
77
  description: @description,
77
78
  allowed_attempts: ALLOWED_ATTEMPTS,
@@ -2,14 +2,22 @@ require "docx"
2
2
  require "word_2_quiz/quiz"
3
3
  require "word_2_quiz/helpers"
4
4
  require "word_2_quiz/quiz_solutions_parser"
5
+ require "word_2_quiz/errors"
5
6
 
6
7
  module Word2Quiz
7
8
  def self.parse_quiz(quiz_path, answer_key_path)
8
9
  doc = Docx::Document.open(quiz_path)
9
10
  paragraphs = doc.paragraphs
11
+ text = doc.text
12
+
13
+ unless Helpers.valid_quiz?(text)
14
+ raise InvalidQuiz.new("The quiz uploaded is not a valid quiz.")
15
+ end
10
16
 
11
17
  answers = Word2Quiz.parse_answers(answer_key_path)
12
18
 
13
19
  Quiz.from_paragraphs(paragraphs, answers)
20
+ rescue Zip::Error
21
+ raise InvalidQuiz.new "The quiz was not a docx file."
14
22
  end
15
23
  end
@@ -1,14 +1,24 @@
1
1
  require "yomu"
2
2
  require "docx"
3
3
  require "strscan"
4
+ require "word_2_quiz/errors"
4
5
 
5
6
  module Word2Quiz
6
7
  def self.parse_answers(file_path)
7
8
  yomu = Yomu.new file_path
8
9
  text = yomu.text
10
+ answers = {}
9
11
 
10
12
  scanner = StringScanner.new(text)
11
- answers = {}
13
+
14
+ # Quizzes accidentally uploaded as an answer key don't fail as they match
15
+ # the regex pattern for the answer key in the questions themselves, so we
16
+ # check that the file is actually an answer key by looking for the text that
17
+ # shows up at the top of the columns in the answer key.
18
+
19
+ unless text.include?("QUES ANS") && text.include?("---- ---")
20
+ raise InvalidAnswerKey.new "The uploaded answer key is not valid."
21
+ end
12
22
 
13
23
  while scanner.scan_until(/\d+\.\s+[A-Z]/)
14
24
  solution_text = scanner.matched.split(".").map(&:strip)
@@ -1,3 +1,3 @@
1
1
  module Word2Quiz
2
- VERSION = "1.0.0".freeze
2
+ VERSION = "1.1.1".freeze
3
3
  end
data/word_2_quiz.gemspec CHANGED
@@ -6,8 +6,7 @@ require "word_2_quiz/version"
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "word_2_quiz"
8
8
  spec.version = Word2Quiz::VERSION
9
- spec.authors = ["Atomic Jolt", "David Spencer"]
10
- spec.email = ["david.spencer@atomicjolt.com"]
9
+ spec.authors = ["Atomic Jolt"]
11
10
 
12
11
  spec.summary = "Read in word doc quizzes and return a hash of questions with answers"
13
12
  spec.description = "Read in word doc quizzes and return a hash of questions with answers"
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: word_2_quiz
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Atomic Jolt
8
- - David Spencer
9
8
  autorequire:
10
9
  bindir: exe
11
10
  cert_chain: []
12
- date: 2017-01-11 00:00:00.000000000 Z
11
+ date: 2017-01-12 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
@@ -138,8 +137,7 @@ dependencies:
138
137
  - !ruby/object:Gem::Version
139
138
  version: '4.2'
140
139
  description: Read in word doc quizzes and return a hash of questions with answers
141
- email:
142
- - david.spencer@atomicjolt.com
140
+ email:
143
141
  executables: []
144
142
  extensions: []
145
143
  extra_rdoc_files: []
@@ -158,6 +156,7 @@ files:
158
156
  - bin/setup
159
157
  - lib/word_2_quiz.rb
160
158
  - lib/word_2_quiz/answer.rb
159
+ - lib/word_2_quiz/errors.rb
161
160
  - lib/word_2_quiz/helpers.rb
162
161
  - lib/word_2_quiz/question.rb
163
162
  - lib/word_2_quiz/quiz.rb