qti 1.0.5 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cfeec2b8ec42ba21144f13b05013cef1425a5d99
4
- data.tar.gz: 6b20f7589d8e8d44f36448ccc082a255bc135e4a
3
+ metadata.gz: 01a0bd0d6fce73ea49a9c058590efc645ae1f07b
4
+ data.tar.gz: 13814e907f52035e0ea02b49be9cff41b93f0220
5
5
  SHA512:
6
- metadata.gz: d6b744f2d7082e7f3c48c7f09db372752ccc6be1561ae7b10822fe8e7b6df6e11cb6ccdf4486e3c9ce5e5a9ad41c5a08e59aeda07ac343832ad1ed29b0f2b78d
7
- data.tar.gz: e1c594853172503d51e918dca051f8e4162a780da4a3c5d1933ffeed8fd773889e125743ddcb6876252c9f0e3bb325a7150d5047ee97c698a75b0ea1485209ad
6
+ metadata.gz: c1375ddeb630a3563154ec29c8e41130e14b9c5885a46388348f270523fe040e81ec57793af37e7d9d9bdf09ae3965dada0a2b3dda31b1d66b29b5e68be25337
7
+ data.tar.gz: 6317d241aa748eb3e8543ad79b3d0d11975f828cc63818338858141cab27831a6f8a918bca3fbcde70ebeea60e481a8b6d30791966c374597261263301f35ce5
@@ -6,22 +6,29 @@ module Qti
6
6
  module V1
7
7
  module Models
8
8
  module Interactions
9
+ ALL_CLASSES = constants.map { |c| const_get(c) }.freeze
10
+ ORDERED_CLASSES = [CanvasMultipleDropdownInteraction, FormulaInteraction, NumericInteraction].freeze
11
+ FALLBACK_CLASSES = [StringInteraction].freeze
9
12
  # This one finds the correct parsing model based on the provided xml node
10
13
  def self.interaction_model(node, parent)
11
- ordered_classes = [CanvasMultipleDropdownInteraction, FormulaInteraction, NumericInteraction]
12
- ordered_classes.each do |interaction_class|
13
- match = interaction_class.matches(node, parent)
14
- return match if match
15
- end
14
+ matches = Interactions.get_matches(node, parent, ORDERED_CLASSES)
15
+ return matches.first unless matches.empty?
16
+
17
+ subclasses = ALL_CLASSES - ORDERED_CLASSES - FALLBACK_CLASSES
16
18
 
17
- subclasses = constants.map { |c| const_get(c) } - ordered_classes
19
+ matches = Interactions.get_matches(node, parent, subclasses)
20
+ matches = Interactions.get_matches(node, parent, FALLBACK_CLASSES) if matches.empty?
18
21
 
19
- matches = subclasses.each_with_object([]) do |interaction_class, result|
22
+ raise UnsupportedSchema if matches.size != 1
23
+ matches.first
24
+ end
25
+
26
+ def self.get_matches(node, parent, classlist)
27
+ matches = classlist.each_with_object([]) do |interaction_class, result|
20
28
  match = interaction_class.matches(node, parent)
21
29
  result << match if match
22
30
  end
23
- raise UnsupportedSchema if matches.size != 1
24
- matches.first
31
+ matches
25
32
  end
26
33
  end
27
34
  end
@@ -6,16 +6,26 @@ module Qti
6
6
  # This will know if a class matches
7
7
  def self.matches(node, parent)
8
8
  return false if node.at_xpath('.//xmlns:respcondition[@continue!="Yes"]/*/xmlns:other').present?
9
- match = if BaseInteraction.canvas_multiple_fib?(node)
10
- node.at_xpath('.//xmlns:response_lid')
11
- else
12
- node.at_xpath('.//xmlns:render_fib')
13
- end
14
- return false if match.blank? ||
15
- match.attributes['fibtype']&.value == 'Decimal'
9
+
10
+ match, answers = FillBlankInteraction.match_and_answers(node)
11
+ return false if answers.blank?
12
+ return false if match.blank? || match.attributes['fibtype']&.value == 'Decimal'
16
13
  new(node, parent)
17
14
  end
18
15
 
16
+ def self.match_and_answers(node)
17
+ if BaseInteraction.canvas_multiple_fib?(node)
18
+ return [
19
+ node.at_xpath('.//xmlns:response_lid'),
20
+ node.xpath('.//xmlns:response_label')
21
+ ]
22
+ end
23
+ [
24
+ node.at_xpath('.//xmlns:render_fib'),
25
+ node.xpath('.//xmlns:respcondition/xmlns:setvar/../xmlns:conditionvar/xmlns:varequal')
26
+ ]
27
+ end
28
+
19
29
  def canvas_multiple_fib?
20
30
  BaseInteraction.canvas_multiple_fib?(@node)
21
31
  end
@@ -90,9 +100,9 @@ module Qti
90
100
 
91
101
  def answer_nodes
92
102
  if canvas_multiple_fib?
93
- @node.xpath('.//xmlns:response_label')
103
+ node.xpath('.//xmlns:response_label')
94
104
  else
95
- @node.xpath('.//xmlns:respcondition/xmlns:setvar/../xmlns:conditionvar/xmlns:varequal')
105
+ node.xpath('.//xmlns:respcondition/xmlns:setvar/../xmlns:conditionvar/xmlns:varequal')
96
106
  end
97
107
  end
98
108
 
@@ -5,8 +5,6 @@ module Qti
5
5
  class StringInteraction < BaseInteraction
6
6
  # This will know if a class matches
7
7
  def self.matches(node, parent)
8
- return false unless node.xpath('.//xmlns:respcondition[@continue!="Yes"]/*/xmlns:other').present?
9
-
10
8
  matches = node.xpath('.//xmlns:render_fib')
11
9
  return false if matches.empty?
12
10
  new(node, parent)
@@ -1,3 +1,3 @@
1
1
  module Qti
2
- VERSION = '1.0.5'.freeze
2
+ VERSION = '1.0.6'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qti
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hannah Bottalla
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-10-23 00:00:00.000000000 Z
12
+ date: 2018-10-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport