strongmind_multi_version_common_cartridge 1.0.4

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.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/gem-push.yml +46 -0
  3. data/.gitignore +14 -0
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +60 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +674 -0
  8. data/PULL_REQUEST_TEMPLATE.md +7 -0
  9. data/README.md +36 -0
  10. data/lib/multi_version_common_cartridge/cartridge.rb +58 -0
  11. data/lib/multi_version_common_cartridge/cartridge_versions.rb +25 -0
  12. data/lib/multi_version_common_cartridge/item.rb +29 -0
  13. data/lib/multi_version_common_cartridge/manifest.rb +33 -0
  14. data/lib/multi_version_common_cartridge/resources/basic_lti_link.rb +46 -0
  15. data/lib/multi_version_common_cartridge/resources/canvas_assignment.rb +30 -0
  16. data/lib/multi_version_common_cartridge/resources/canvas_course_settings.rb +29 -0
  17. data/lib/multi_version_common_cartridge/resources/canvas_elements/assignment.rb +33 -0
  18. data/lib/multi_version_common_cartridge/resources/canvas_elements/course_settings.rb +111 -0
  19. data/lib/multi_version_common_cartridge/resources/resource.rb +23 -0
  20. data/lib/multi_version_common_cartridge/sax_machine_nokogiri_xml_saver.rb +85 -0
  21. data/lib/multi_version_common_cartridge/version.rb +19 -0
  22. data/lib/multi_version_common_cartridge/writers/basic_lti_extension_writer.rb +45 -0
  23. data/lib/multi_version_common_cartridge/writers/basic_lti_link_writer.rb +242 -0
  24. data/lib/multi_version_common_cartridge/writers/basic_lti_vendor_writer.rb +66 -0
  25. data/lib/multi_version_common_cartridge/writers/canvas_assignment_writer.rb +104 -0
  26. data/lib/multi_version_common_cartridge/writers/canvas_course_settings_writer.rb +218 -0
  27. data/lib/multi_version_common_cartridge/writers/cartridge_writer.rb +85 -0
  28. data/lib/multi_version_common_cartridge/writers/factory.rb +61 -0
  29. data/lib/multi_version_common_cartridge/writers/item_writer.rb +60 -0
  30. data/lib/multi_version_common_cartridge/writers/manifest_metadata_writer.rb +62 -0
  31. data/lib/multi_version_common_cartridge/writers/manifest_organization_writer.rb +68 -0
  32. data/lib/multi_version_common_cartridge/writers/manifest_resources_writer.rb +48 -0
  33. data/lib/multi_version_common_cartridge/writers/manifest_writer.rb +88 -0
  34. data/lib/multi_version_common_cartridge/writers/resource_writer.rb +54 -0
  35. data/lib/multi_version_common_cartridge/writers/supported_versions.rb +37 -0
  36. data/lib/multi_version_common_cartridge/xml_definitions.rb +149 -0
  37. data/lib/multi_version_common_cartridge.rb +45 -0
  38. data/multi_version_common_cartridge.gemspec +27 -0
  39. metadata +164 -0
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # multi_version_common_cartridge
2
+ A gem for writing different versions of Common Cartridges.
3
+
4
+ It supports Common Cartridge version 1.1, 1.2, 1.3 and Thin CC version 1.2 and 1.3.
5
+
6
+ ## Usage
7
+ ``` ruby
8
+ # Create a Common Cartridge
9
+ cartridge = MultiVersionCommonCartridge::Cartridge.new
10
+ cartridge.manifest.set_title('My cartridge')
11
+ cartridge.items = [
12
+ MultiVersionCommonCartridge::Item.new.tap do |item|
13
+ item.title = 'My activity'
14
+ item.identifier = 'Some identifier'
15
+ item.resource = MultiVersionCommonCartridge::Resources::BasicLtiLink::BasicLtiLink.new.tap do |lti|
16
+ lti.title = 'My activity title'
17
+ lti.identiier = 'My activity identifier'
18
+ lti.scure_launch_url = 'https://example.com/lti'
19
+ end
20
+ end
21
+ ]
22
+
23
+ # Create a Common Cartridge writer for version 1.2.0
24
+ writer = MultiVersionCommonCartridge::Writers::CartridgeWriter.new(
25
+ cartridge, '1.2.0'
26
+ end
27
+
28
+ # Finalize the Common Cartridge for the specified version.
29
+ writer.finalize
30
+
31
+ # Check for error
32
+ return if writer.errors?
33
+
34
+ # Write the Common Cartridge
35
+ writer.write_to_zip('cartridge.imscc')
36
+ ```
@@ -0,0 +1,58 @@
1
+ # multi_version_common_cartridge
2
+ # Copyright © 2019 Vista Higher Learning, Inc.
3
+ #
4
+ # multi_version_common_cartridge is free software: you can redistribute it
5
+ # and/or modify it under the terms of the GNU General Public
6
+ # License as published by the Free Software Foundation, either
7
+ # version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # multi_version_common_cartridge is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with multi_version_common_cartridge. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ module MultiVersionCommonCartridge
18
+ class Cartridge
19
+ attr_accessor :items
20
+
21
+ def initialize
22
+ @items = []
23
+ @resources = []
24
+ end
25
+
26
+ def manifest
27
+ @manifest ||= Manifest.new
28
+ end
29
+
30
+ def add_item(item)
31
+ @items << item
32
+ end
33
+
34
+ def all_items
35
+ @all_items ||= begin
36
+ @items.each_with_object([]) do |item, memo|
37
+ memo << item
38
+ child_items(item, memo)
39
+ end
40
+ end.flatten
41
+ end
42
+
43
+ def add_resource(resource)
44
+ @resources << resource
45
+ end
46
+
47
+ def all_resources
48
+ @all_resources ||= all_items.map(&:resource).compact + @resources
49
+ end
50
+
51
+ private def child_items(item, memo)
52
+ item.children.each do |child|
53
+ memo << child
54
+ child_items(child, memo)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,25 @@
1
+ # multi_version_common_cartridge
2
+ # Copyright © 2019 Vista Higher Learning, Inc.
3
+ #
4
+ # multi_version_common_cartridge is free software: you can redistribute it
5
+ # and/or modify it under the terms of the GNU General Public
6
+ # License as published by the Free Software Foundation, either
7
+ # version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # multi_version_common_cartridge is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with multi_version_common_cartridge. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ module MultiVersionCommonCartridge
18
+ module CartridgeVersions
19
+ CC_1_1_0 = '1.1.0'.freeze
20
+ CC_1_2_0 = '1.2.0'.freeze
21
+ CC_1_3_0 = '1.3.0'.freeze
22
+ THIN_CC_1_2_0 = 'Thin 1.2.0'.freeze
23
+ THIN_CC_1_3_0 = 'Thin 1.3.0'.freeze
24
+ end
25
+ end
@@ -0,0 +1,29 @@
1
+ # multi_version_common_cartridge
2
+ # Copyright © 2019 Vista Higher Learning, Inc.
3
+ #
4
+ # multi_version_common_cartridge is free software: you can redistribute it
5
+ # and/or modify it under the terms of the GNU General Public
6
+ # License as published by the Free Software Foundation, either
7
+ # version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # multi_version_common_cartridge is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with multi_version_common_cartridge. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ module MultiVersionCommonCartridge
18
+ class Item
19
+ attr_accessor :title, :identifier, :resource, :children
20
+
21
+ def initialize
22
+ @children = []
23
+ end
24
+
25
+ def add_item(item)
26
+ children << item
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,33 @@
1
+ # multi_version_common_cartridge
2
+ # Copyright © 2019 Vista Higher Learning, Inc.
3
+ #
4
+ # multi_version_common_cartridge is free software: you can redistribute it
5
+ # and/or modify it under the terms of the GNU General Public
6
+ # License as published by the Free Software Foundation, either
7
+ # version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # multi_version_common_cartridge is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with multi_version_common_cartridge. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ module MultiVersionCommonCartridge
18
+ class Manifest
19
+ attr_accessor :identifier, :titles, :description, :organization_identifier
20
+
21
+ def initialize
22
+ @titles = {}
23
+ end
24
+
25
+ def set_title(title, language: 'en-US')
26
+ titles[language] = title
27
+ end
28
+
29
+ def title(language)
30
+ titles[language]
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,46 @@
1
+ # multi_version_common_cartridge
2
+ # Copyright © 2019 Vista Higher Learning, Inc.
3
+ #
4
+ # multi_version_common_cartridge is free software: you can redistribute it
5
+ # and/or modify it under the terms of the GNU General Public
6
+ # License as published by the Free Software Foundation, either
7
+ # version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # multi_version_common_cartridge is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with multi_version_common_cartridge. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ module MultiVersionCommonCartridge
18
+ module Resources
19
+ module BasicLtiLink
20
+ class Vendor
21
+ attr_accessor :code, :name, :description, :url, :contact_email
22
+ end
23
+
24
+ class BasicLtiLink < MultiVersionCommonCartridge::Resources::Resource
25
+ attr_accessor :title, :description, :secure_launch_url, :extensions, :launch_url
26
+
27
+ def initialize
28
+ @extensions = []
29
+ end
30
+
31
+ def vendor
32
+ @vendor ||= Vendor.new
33
+ end
34
+ end
35
+
36
+ class Extension
37
+ attr_accessor :platform, :properties
38
+
39
+ def initialize(platform)
40
+ @platform = platform
41
+ @properties = {}
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,30 @@
1
+ # multi_version_common_cartridge
2
+ # Copyright © 2023 StrongMind
3
+ #
4
+ # multi_version_common_cartridge is free software: you can redistribute it
5
+ # and/or modify it under the terms of the GNU General Public
6
+ # License as published by the Free Software Foundation, either
7
+ # version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # multi_version_common_cartridge is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with multi_version_common_cartridge. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ module MultiVersionCommonCartridge
18
+ module Resources
19
+ module CanvasAssignment
20
+
21
+ class CanvasAssignment < MultiVersionCommonCartridge::Resources::Resource
22
+ attr_accessor :title, :assignment_group_identifierref, :points_possible, :max_attempts, :allowed_attempts,
23
+ :is_end_of_module_exam, :grading_type, :submission_types, :peer_review_count, :external_tool_url
24
+
25
+ def initialize; end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,29 @@
1
+ # multi_version_common_cartridge
2
+ # Copyright © 2023 StrongMind
3
+ #
4
+ # multi_version_common_cartridge is free software: you can redistribute it
5
+ # and/or modify it under the terms of the GNU General Public
6
+ # License as published by the Free Software Foundation, either
7
+ # version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # multi_version_common_cartridge is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with multi_version_common_cartridge. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ module MultiVersionCommonCartridge
18
+ module Resources
19
+ module CanvasCourseSettings
20
+
21
+ class CanvasCourseSettings < MultiVersionCommonCartridge::Resources::Resource
22
+ attr_accessor :image_url, :group_weighting_scheme, :assignment_groups, :modules, :href
23
+
24
+ def initialize; end
25
+
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,33 @@
1
+ module CanvasCartridge
2
+ module Elements
3
+ module Resources
4
+ module CanvasAssignment
5
+
6
+ class Assignment
7
+ include SAXMachine
8
+
9
+ attribute :xmlns
10
+ attribute 'xmlns:xsi', as: :xmlns_xsi
11
+ attribute :identifier, as: :identifier
12
+
13
+ element 'title', as: :title
14
+ element 'assignment_group_identifierref', as: :assignment_group_identifierref
15
+ element 'points_possible', as: :points_possible
16
+ element 'max_attempts', as: :max_attempts
17
+ element 'allowed_attempts', as: :allowed_attempts
18
+ element 'is_end_of_module_exam', as: :is_end_of_module_exam
19
+ element 'grading_type', as: :grading_type
20
+ element 'submission_types', as: :submission_types
21
+ element 'peer_review_count', as: :peer_review_count
22
+ element 'external_tool_url', as: :external_tool_url
23
+
24
+ def self.type
25
+ :canvas_assignment
26
+ end
27
+
28
+ def self.pattern; end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,111 @@
1
+ module CanvasCartridge
2
+ module Elements
3
+ module Resources
4
+ module CourseSettings
5
+
6
+ class CourseSettings
7
+ include SAXMachine
8
+
9
+ attribute :identifier
10
+
11
+ attribute :xmlns
12
+ attribute 'xmlns:xsi', as: :xmlns_xsi
13
+
14
+ element 'image_url', as: :image_url
15
+ element 'group_weighting_scheme', as: :group_weighting_scheme
16
+
17
+ def self.type
18
+ :course_settings
19
+ end
20
+
21
+ def self.pattern; end
22
+ end
23
+
24
+ class AssignmentGroup
25
+ include SAXMachine
26
+
27
+ attribute :identifier
28
+
29
+ element 'title', as: :title
30
+ element 'position', as: :position
31
+ element 'group_weight', as: :group_weight
32
+
33
+ end
34
+
35
+ class AssignmentGroups
36
+ include SAXMachine
37
+
38
+ attribute :xmlns
39
+ attribute 'xmlns:xsi', as: :xmlns_xsi
40
+
41
+ elements 'assignmentGroup', class: AssignmentGroup, as: :groups
42
+ end
43
+
44
+ class Prerequisite
45
+ include SAXMachine
46
+ attribute :type
47
+ element :title
48
+ element :identifierref
49
+ end
50
+
51
+ class Prerequisites
52
+ include SAXMachine
53
+
54
+ elements :prerequisite, as: :prerequisites, class: Prerequisite
55
+ end
56
+
57
+ class Item
58
+ include SAXMachine
59
+ attribute :identifier, as: :identifier
60
+ element :title
61
+ element :workflow_state
62
+ element :content_type
63
+ element :identifierref
64
+ element :url
65
+ element :position
66
+ element :indent
67
+ element :global_identifierref
68
+ end
69
+
70
+ class Items
71
+ include SAXMachine
72
+
73
+ elements :item, as: :items, class: Item
74
+ end
75
+
76
+ class CompletionRequirement
77
+ include SAXMachine
78
+ attribute :type
79
+ element :identifierref
80
+ end
81
+
82
+ class CompletionRequirements
83
+ include SAXMachine
84
+
85
+ elements :completionRequirement, as: :completion_requirements, class: CompletionRequirement
86
+ end
87
+
88
+ class Module
89
+ include SAXMachine
90
+ attribute :identifier
91
+ element :title
92
+ element :workflow_state
93
+ element :position
94
+ element :require_sequential_progress
95
+ element :requirement_count
96
+ element :prerequisites, as: :root_prerequisites, class: Prerequisites
97
+ element :items, as: :root_items, class: Items
98
+ element :completionRequirements, as: :root_requirements, class: CompletionRequirements
99
+ end
100
+
101
+ class Modules
102
+ include SAXMachine
103
+
104
+ attribute :xmlns
105
+ attribute 'xmlns:xsi', as: :xmlns_xsi
106
+ elements :module, as: :modules, class: Module
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,23 @@
1
+ # multi_version_common_cartridge
2
+ # Copyright © 2019 Vista Higher Learning, Inc.
3
+ #
4
+ # multi_version_common_cartridge is free software: you can redistribute it
5
+ # and/or modify it under the terms of the GNU General Public
6
+ # License as published by the Free Software Foundation, either
7
+ # version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # multi_version_common_cartridge is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with multi_version_common_cartridge. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ module MultiVersionCommonCartridge
18
+ module Resources
19
+ class Resource
20
+ attr_accessor :identifier, :href
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,85 @@
1
+ # multi_version_common_cartridge
2
+ # Copyright © 2019 Vista Higher Learning, Inc.
3
+ #
4
+ # multi_version_common_cartridge is free software: you can redistribute it
5
+ # and/or modify it under the terms of the GNU General Public
6
+ # License as published by the Free Software Foundation, either
7
+ # version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # multi_version_common_cartridge is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with multi_version_common_cartridge. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ class SaxMachineNokogiriXmlSaver
18
+ def save(builder, object, name)
19
+ sax_config = sax_config_for(object)
20
+ unless sax_config
21
+ builder.send(name, object)
22
+ return
23
+ end
24
+
25
+ attrs = xml_attributes(object, sax_config)
26
+ content = xml_content(object, sax_config)
27
+ create_xml_node(builder, name, content, attrs) do |xml_element|
28
+ sax_config.top_level_elements.each do |_, configs|
29
+ configs.each do |config|
30
+ as = config.instance_variable_get(:@as)
31
+ save(xml_element, object.send(as), config.name)
32
+ end
33
+ end
34
+
35
+ sax_config.collection_elements.each do |_, configs|
36
+ configs.each do |config|
37
+ as = config.instance_variable_get(:@as)
38
+ object.send(as).each do |elm|
39
+ save(xml_element, elm, config.name)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ private def xml_attributes(object, sax_config)
47
+ attrs = sax_config.top_level_attributes.map do |attr|
48
+ [attr.name, object.send(attr.instance_variable_get(:@as))]
49
+ end.to_h
50
+ attrs.delete_if { |_, v| v.nil? }
51
+ end
52
+
53
+ private def xml_content(object, sax_config)
54
+ return if sax_config.top_level_element_value.empty?
55
+ element_value_config = sax_config.top_level_element_value.last
56
+ object.send(element_value_config.name)
57
+ end
58
+
59
+ private def create_xml_node(builder, name, content, attrs, &block)
60
+ if name.include?(':')
61
+ namespace, name = name.split(':', 2)
62
+ create_xml_element(builder[namespace], name, content, attrs, &block)
63
+ else
64
+ create_xml_element(builder, name, content, attrs, &block)
65
+ end
66
+ end
67
+
68
+ private def create_xml_element(builder, name, content, attrs, &block)
69
+ if content
70
+ builder.send(name, content, attrs) do |xml_element|
71
+ yield xml_element
72
+ end
73
+ else
74
+ builder.send(name, attrs) do |xml_element|
75
+ yield xml_element
76
+ end
77
+ end
78
+ end
79
+
80
+ private def sax_config_for(object)
81
+ if object.class.respond_to?(:sax_config)
82
+ object.class.sax_config
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,19 @@
1
+ # multi_version_common_cartridge
2
+ # Copyright © 2019 Vista Higher Learning, Inc.
3
+ #
4
+ # multi_version_common_cartridge is free software: you can redistribute it
5
+ # and/or modify it under the terms of the GNU General Public
6
+ # License as published by the Free Software Foundation, either
7
+ # version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # multi_version_common_cartridge is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with multi_version_common_cartridge. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ module MultiVersionCommonCartridge
18
+ VERSION = '1.0.4'.freeze
19
+ end
@@ -0,0 +1,45 @@
1
+ # multi_version_common_cartridge
2
+ # Copyright © 2019 Vista Higher Learning, Inc.
3
+ #
4
+ # multi_version_common_cartridge is free software: you can redistribute it
5
+ # and/or modify it under the terms of the GNU General Public
6
+ # License as published by the Free Software Foundation, either
7
+ # version 3 of the License, or (at your option) any later version.
8
+ #
9
+ # multi_version_common_cartridge is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
+ # General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with multi_version_common_cartridge. If not, see <http://www.gnu.org/licenses/>.
16
+
17
+ module MultiVersionCommonCartridge
18
+ module Writers
19
+ class BasicLtiExtensionWriter
20
+ include SupportedVersions
21
+
22
+ attr_reader :extension
23
+
24
+ def initialize(extension, version)
25
+ @extension = extension
26
+ @version = validate_version(version)
27
+ end
28
+
29
+ def finalize
30
+ end
31
+
32
+ def extension_element
33
+ @extension_element ||= CommonCartridge::Elements::Resources::BasicLtiLink::Extension.new.tap do |element|
34
+ element.platform = extension.platform
35
+ element.properties = extension.properties.map do |key, value|
36
+ CommonCartridge::Elements::Resources::BasicLtiLink::ExtensionProperty.new(
37
+ name: key, value: value
38
+ )
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+