common_cartridge 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/lib/common_cartridge.rb +40 -0
  3. data/lib/common_cartridge/elements/lom.rb +60 -0
  4. data/lib/common_cartridge/elements/manifest.rb +24 -0
  5. data/lib/common_cartridge/elements/metadata.rb +12 -0
  6. data/lib/common_cartridge/elements/organizations.rb +42 -0
  7. data/lib/common_cartridge/elements/outcomes.rb +10 -0
  8. data/lib/common_cartridge/elements/outcomes/outcome.rb +15 -0
  9. data/lib/common_cartridge/elements/outcomes/outcome_group.rb +12 -0
  10. data/lib/common_cartridge/elements/outcomes/outcome_root.rb +11 -0
  11. data/lib/common_cartridge/elements/resources.rb +117 -0
  12. data/lib/common_cartridge/elements/resources/assessment.rb +21 -0
  13. data/lib/common_cartridge/elements/resources/assignment.rb +59 -0
  14. data/lib/common_cartridge/elements/resources/attachments.rb +20 -0
  15. data/lib/common_cartridge/elements/resources/page.rb +22 -0
  16. data/lib/common_cartridge/elements/resources/topic.rb +28 -0
  17. data/lib/common_cartridge/elements/resources/web_link.rb +25 -0
  18. data/lib/common_cartridge/package.rb +87 -0
  19. data/lib/common_cartridge/parsers/dependencies.rb +23 -0
  20. data/lib/common_cartridge/parsers/files.rb +34 -0
  21. data/lib/common_cartridge/parsers/items.rb +58 -0
  22. data/lib/common_cartridge/parsers/outcomes.rb +17 -0
  23. data/lib/common_cartridge/parsers/parser.rb +78 -0
  24. data/lib/common_cartridge/parsers/questions.rb +34 -0
  25. data/lib/sax_machine/sax_handler.rb +13 -0
  26. data/spec/elements/lom_spec.rb +66 -0
  27. data/spec/elements/manifest_spec.rb +27 -0
  28. data/spec/elements/metadata_spec.rb +40 -0
  29. data/spec/elements/organizations_spec.rb +51 -0
  30. data/spec/elements/outcomes/outcome_group_spec.rb +29 -0
  31. data/spec/elements/outcomes/outcome_spec.rb +37 -0
  32. data/spec/elements/resources/assignment_spec.rb +53 -0
  33. data/spec/elements/resources/attachments_spec.rb +24 -0
  34. data/spec/elements/resources/resources_spec.rb +73 -0
  35. data/spec/elements/resources/topic_spec.rb +39 -0
  36. data/spec/elements/resources/web_link_spec.rb +31 -0
  37. data/spec/files/canvas_large_1.3.imscc +0 -0
  38. data/spec/files/canvas_small_1.1.corrupt.imscc +0 -0
  39. data/spec/files/canvas_small_1.1.imscc +0 -0
  40. data/spec/package_spec.rb +110 -0
  41. data/spec/parser_spec.rb +13 -0
  42. data/spec/spec_helper.rb +13 -0
  43. metadata +179 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d5b2481f5a5f1ba164d5ca9a60fea3847c18035b
4
+ data.tar.gz: e8efc878e6554217fa1d79dbec768cdf6a0d07fd
5
+ SHA512:
6
+ metadata.gz: d41a9f3fb2ad06e4c876c8798b650798efec9b3553a48d0e288b552a1692970ed674c3d330eb0b5837ddc6475902e86e62e5a0586eeeb9178fe4520c0395d2e3
7
+ data.tar.gz: 1877b1fbb6d429054fc8f86f4555d5dd7bcc81f6092c6253bf21d3ae00755b59c8bba9e23918118f03b12af1796c039e38c8a8163f5f20b0e3c2f74a35340003
@@ -0,0 +1,40 @@
1
+ require 'sax-machine'
2
+ require 'sax_machine/sax_handler'
3
+
4
+ module CommonCartridge
5
+ def self.parse_from_zip(zipfile)
6
+ parser = Parsers::Parser.new(zipfile)
7
+ package = parser.parse
8
+ package
9
+ end
10
+
11
+ # todo: methods to detect version and inject resultant namespace
12
+
13
+ # Configuration
14
+ class << self
15
+ attr_accessor :config
16
+ end
17
+
18
+ def self.configure
19
+ self.config ||= Config.new
20
+ yield(config)
21
+ end
22
+
23
+ class Config
24
+ attr_accessor :import_directory, :export_directory
25
+
26
+ def initialize
27
+ @import_directory = '.'
28
+ @export_directory = '/tmp'
29
+ end
30
+ end
31
+ end
32
+
33
+ require 'common_cartridge/elements/lom'
34
+ require 'common_cartridge/elements/metadata'
35
+ require 'common_cartridge/elements/organizations'
36
+ require 'common_cartridge/elements/resources'
37
+ require 'common_cartridge/elements/outcomes'
38
+ require 'common_cartridge/elements/manifest'
39
+ require 'common_cartridge/package'
40
+ require 'common_cartridge/parsers/parser'
@@ -0,0 +1,60 @@
1
+ module CommonCartridge
2
+ module Elements
3
+ module Lom
4
+ class Title
5
+ include SAXMachine
6
+
7
+ element :string, as: :value
8
+ element :string, value: :language, as: :language
9
+
10
+ def to_s; string; end
11
+ end
12
+
13
+ class Description
14
+ include SAXMachine
15
+
16
+ element :string, as: :value
17
+ element :string, value: :language, as: :language
18
+
19
+ def to_s; string; end
20
+ end
21
+
22
+ class Keyword
23
+ include SAXMachine
24
+
25
+ element :string, as: :value
26
+ element :string, value: :language, as: :language
27
+
28
+ def to_s; string; end
29
+ end
30
+
31
+ class CopyrightAndOtherRestrictions
32
+ include SAXMachine
33
+
34
+ element :value
35
+ end
36
+
37
+ class Rights
38
+ include SAXMachine
39
+
40
+ element :description, class: CommonCartridge::Elements::Lom::Description
41
+ element :copyrightAndOtherRestrictions, class: CommonCartridge::Elements::Lom::CopyrightAndOtherRestrictions
42
+ end
43
+
44
+ class General
45
+ include SAXMachine
46
+
47
+ element :title, class: CommonCartridge::Elements::Lom::Title
48
+ element :description, class: CommonCartridge::Elements::Lom::Description
49
+ elements :keyword, as: :keywords, class: CommonCartridge::Elements::Lom::Keyword
50
+ end
51
+
52
+ class Lom
53
+ include SAXMachine
54
+
55
+ element :general, class: CommonCartridge::Elements::Lom::General
56
+ element :rights, class: CommonCartridge::Elements::Lom::Rights
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,24 @@
1
+ module CommonCartridge
2
+ module Elements
3
+ class Manifest
4
+ include SAXMachine
5
+
6
+ element :metadata, class: CommonCartridge::Elements::Metadata
7
+ element :organizations, class: CommonCartridge::Elements::Organizations::RootOrganization, as: :root_organization
8
+ element :resources, class: CommonCartridge::Elements::Resources::RootResource, as: :root_resource
9
+
10
+ def organizations
11
+ root_organization.organizations
12
+ end
13
+
14
+ def resources
15
+ root_resource.resources
16
+ end
17
+
18
+ def organization
19
+ organizations.first
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ module CommonCartridge
2
+ module Elements
3
+ class Metadata
4
+ include SAXMachine
5
+
6
+ element :schema
7
+ element :schemaversion
8
+
9
+ element :lom, class: CommonCartridge::Elements::Lom::Lom
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,42 @@
1
+ module CommonCartridge
2
+ module Elements
3
+ module Organizations
4
+ class Item
5
+ attr_accessor :type
6
+
7
+ include SAXMachine
8
+
9
+ attribute :identifier
10
+ attribute :identifierref
11
+ element :title
12
+
13
+ elements :item, class: self, as: :items
14
+ end
15
+
16
+ class RootItem
17
+ include SAXMachine
18
+
19
+ attribute :identifier
20
+ attribute :identifierref
21
+
22
+ elements :item, class: Item, as: :items
23
+
24
+ # todo: implement 'find_by' method here to quickly scan for particular items
25
+ end
26
+
27
+ class Organization
28
+ include SAXMachine
29
+
30
+ attribute :identifier
31
+ attribute :structure
32
+ element :item, class: RootItem, as: :root_item
33
+ end
34
+
35
+ class RootOrganization
36
+ include SAXMachine
37
+
38
+ elements :organization, class: Organization, as: :organizations
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,10 @@
1
+ require 'common_cartridge/elements/outcomes/outcome'
2
+ require 'common_cartridge/elements/outcomes/outcome_group'
3
+ require 'common_cartridge/elements/outcomes/outcome_root'
4
+ module CommonCartridge
5
+ module Elements
6
+ module Outcomes
7
+ end
8
+ end
9
+ end
10
+
@@ -0,0 +1,15 @@
1
+ module CommonCartridge
2
+ module Elements
3
+ module Outcomes
4
+ class Outcome
5
+ include SAXMachine
6
+
7
+ attribute :identifier
8
+
9
+ element :title
10
+ element :points_possible
11
+ element :mastery_points
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ module CommonCartridge
2
+ module Elements
3
+ module Outcomes
4
+ class OutcomeGroup
5
+ include SAXMachine
6
+
7
+ attribute :identifier
8
+ elements 'learningOutcome', as: :outcomes, class: Outcome
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,11 @@
1
+ module CommonCartridge
2
+ module Elements
3
+ module Outcomes
4
+ class OutcomeRoot
5
+ include SAXMachine
6
+
7
+ elements 'learningOutcomeGroup', as: :outcome_groups, class: OutcomeGroup
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,117 @@
1
+ require 'common_cartridge/elements/resources/attachments'
2
+ require 'common_cartridge/elements/resources/web_link'
3
+ require 'common_cartridge/elements/resources/topic'
4
+ require 'common_cartridge/elements/resources/assignment'
5
+ require 'common_cartridge/elements/resources/assessment'
6
+ require 'common_cartridge/elements/resources/page'
7
+
8
+ module CommonCartridge
9
+ module Elements
10
+ module Resources
11
+
12
+ def self.type_mappings
13
+ {
14
+ Topic.pattern => Topic,
15
+ WebLink.pattern => WebLink,
16
+ Assignment.pattern => Assignment,
17
+ Assessment.pattern => Assessment,
18
+ Page.pattern => Page
19
+ }
20
+ end
21
+
22
+
23
+ class Content
24
+ include SAXMachine
25
+
26
+ element :title
27
+ element :points_possible
28
+ element :type
29
+ end
30
+
31
+ class Dependency
32
+ attr_writer :contents
33
+
34
+ include SAXMachine
35
+ attribute :identifierref
36
+
37
+ def contents
38
+ @contents ||= []
39
+ end
40
+
41
+ def title
42
+ if c = contents.detect { |content| !content.title.to_s.empty? }
43
+ return c.title
44
+ end
45
+ end
46
+
47
+ def points_possible
48
+ if c = contents.detect { |content| !content.points_possible.to_s.empty? }
49
+ return c.points_possible
50
+ end
51
+ end
52
+ end
53
+
54
+ class File
55
+ attr_accessor :content
56
+
57
+ include SAXMachine
58
+ attribute :href
59
+ element :attachments, class: Attachments::RootAttachment, as: :attachment_root
60
+ elements :dependency, class: Dependency, as: :dependencies
61
+
62
+ def attachments; attachment_root.attachments; end
63
+ end
64
+
65
+ class Resource
66
+ attr_accessor :question_count
67
+ attr_writer :title, :points_possible
68
+
69
+ include SAXMachine
70
+ attribute :identifier
71
+ attribute :type
72
+ attribute :href
73
+ attribute :intendeduse
74
+
75
+ elements :file, class: File, as: :files
76
+ elements :dependency, class: Dependency, as: :dependencies
77
+
78
+
79
+ # Switch statement based on 'type'
80
+ def points_possible
81
+ @points_possible ||= if dependency = dependencies.detect { |d| d.points_possible && !d.points_possible.empty? }
82
+ dependency.points_possible
83
+ end
84
+ end
85
+
86
+ def title
87
+ @title ||= if file = files.detect { |f| f.content && f.content.title && !f.content.title.empty? }
88
+ file.content.title
89
+ elsif dependency = dependencies.detect { |d| d.title && !d.title.empty? }
90
+ dependency.title
91
+ end
92
+ end
93
+
94
+ def file_locations
95
+ [
96
+ ::File.join(identifier, "assessment.xml"),
97
+ ::File.join(identifier, "assessment_qti.xml"),
98
+ ::File.join("non_cc_assessments", "#{identifier}.xml"),
99
+ ::File.join("non_cc_assessments", "#{identifier}.xml.qti")
100
+ ]
101
+ end
102
+
103
+ def is_announcement?
104
+ !!dependencies.collect(&:contents).flatten.detect { |c| c.type == 'announcement' }
105
+ end
106
+ end
107
+
108
+ class RootResource
109
+ include SAXMachine
110
+
111
+ elements :resource, class: Resource, as: :resources
112
+
113
+ end
114
+
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,21 @@
1
+ module CommonCartridge
2
+ module Elements
3
+ module Resources
4
+ class Assessment
5
+ attr_accessor :title, :identifier
6
+
7
+ include SAXMachine
8
+
9
+ element :points_possible
10
+
11
+ def self.type
12
+ :quiz
13
+ end
14
+
15
+ def self.pattern
16
+ /assessment|quiz/
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,59 @@
1
+ module CommonCartridge
2
+ module Elements
3
+ module Resources
4
+ class Format
5
+ include SAXMachine
6
+
7
+ attribute :type
8
+ end
9
+
10
+ class SubmissionFormats
11
+ include SAXMachine
12
+
13
+ elements :format, class: Format, as: :formats
14
+ end
15
+
16
+ class Text
17
+ include SAXMachine
18
+
19
+ attribute :href
20
+ attribute :texttype, as: :text_type
21
+ value :value
22
+ end
23
+
24
+ class InstructorText
25
+ include SAXMachine
26
+
27
+ attribute :href
28
+ attribute :texttype, as: :text_type
29
+ value :value
30
+ end
31
+
32
+ class Assignment
33
+ attr_accessor :identifier, :points_possible
34
+
35
+ include SAXMachine
36
+
37
+ element :title
38
+ element :text, class: Text
39
+ element :instructor_text, class: InstructorText
40
+ element :gradable
41
+
42
+ element :submission_formats, class: SubmissionFormats
43
+ element :attachments, class: CommonCartridge::Elements::Resources::Attachments::RootAttachment, as: :attachment_root
44
+
45
+ def attachments
46
+ attachment_root.attachments
47
+ end
48
+
49
+ def self.type
50
+ :assignment
51
+ end
52
+
53
+ def self.pattern
54
+ /assignment|associatedcontent\/imscc_xmlv1p1\/learning\-application\-resource/
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end