Class: Meibo::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/meibo/manifest.rb

Constant Summary collapse

MANIFEST_VERSION =
"1.0"
ONEROSTER_VERSION =
"1.2.1"
PROPERTY_NAME_TO_ATTRIBUTE_MAP =
{
  "manifest.version" => :manifest_version,
  "oneroster.version" => :oneroster_version,
  "file.academicSessions" => :file_academic_sessions,
  "file.categories" => :file_categories,
  "file.classes" => :file_classes,
  "file.classResources" => :file_class_resources,
  "file.courses" => :file_courses,
  "file.courseResources" => :file_course_resources,
  "file.demographics" => :file_demographics,
  "file.enrollments" => :file_enrollments,
  "file.lineItemLearningObjectiveIds" => :file_line_item_learning_objective_ids,
  "file.lineItems" => :file_line_items,
  "file.lineItemScoreScales" => :file_line_item_score_scales,
  "file.orgs" => :file_orgs,
  "file.resources" => :file_resources,
  "file.resultLearningObjectiveIds" => :file_result_learning_objective_ids,
  "file.results" => :file_results,
  "file.resultScoreScales" => :file_result_score_scales,
  "file.roles" => :file_roles,
  "file.scoreScales" => :file_score_scales,
  "file.userProfiles" => :file_user_profiles,
  "file.userResources" => :file_user_resources,
  "file.users" => :file_users,
  "source.systemName" => :source_system_name,
  "source.systemCode" => :source_system_code
}.freeze
ATTRIBUTE_TO_PROPERTY_NAME_MAP =
PROPERTY_NAME_TO_ATTRIBUTE_MAP.to_h do |property_name, attribute|
  [attribute, property_name]
end.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_academic_sessions: ProcessingMode.absent, file_categories: ProcessingMode.absent, file_classes: ProcessingMode.absent, file_class_resources: ProcessingMode.absent, file_courses: ProcessingMode.absent, file_course_resources: ProcessingMode.absent, file_demographics: ProcessingMode.absent, file_enrollments: ProcessingMode.absent, file_line_item_learning_objective_ids: ProcessingMode.absent, file_line_items: ProcessingMode.absent, file_line_item_score_scales: ProcessingMode.absent, file_orgs: ProcessingMode.absent, file_resources: ProcessingMode.absent, file_result_learning_objective_ids: ProcessingMode.absent, file_results: ProcessingMode.absent, file_result_score_scales: ProcessingMode.absent, file_roles: ProcessingMode.absent, file_score_scales: ProcessingMode.absent, file_user_profiles: ProcessingMode.absent, file_user_resources: ProcessingMode.absent, file_users: ProcessingMode.absent, manifest_version: MANIFEST_VERSION, oneroster_version: ONEROSTER_VERSION, source_system_name: nil, source_system_code: nil) ⇒ Manifest

Returns a new instance of Manifest.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/meibo/manifest.rb', line 80

def initialize(
  file_academic_sessions: ProcessingMode.absent,
  file_categories: ProcessingMode.absent,
  file_classes: ProcessingMode.absent,
  file_class_resources: ProcessingMode.absent,
  file_courses: ProcessingMode.absent,
  file_course_resources: ProcessingMode.absent,
  file_demographics: ProcessingMode.absent,
  file_enrollments: ProcessingMode.absent,
  file_line_item_learning_objective_ids: ProcessingMode.absent,
  file_line_items: ProcessingMode.absent,
  file_line_item_score_scales: ProcessingMode.absent,
  file_orgs: ProcessingMode.absent,
  file_resources: ProcessingMode.absent,
  file_result_learning_objective_ids: ProcessingMode.absent,
  file_results: ProcessingMode.absent,
  file_result_score_scales: ProcessingMode.absent,
  file_roles: ProcessingMode.absent,
  file_score_scales: ProcessingMode.absent,
  file_user_profiles: ProcessingMode.absent,
  file_user_resources: ProcessingMode.absent,
  file_users: ProcessingMode.absent,
  manifest_version: MANIFEST_VERSION,
  oneroster_version: ONEROSTER_VERSION,
  source_system_name: nil,
  source_system_code: nil
)
  @manifest_version = manifest_version
  @oneroster_version = oneroster_version
  @file_academic_sessions = file_academic_sessions
  @file_categories = file_categories
  @file_classes = file_classes
  @file_class_resources = file_class_resources
  @file_courses = file_courses
  @file_course_resources = file_course_resources
  @file_demographics = file_demographics
  @file_enrollments = file_enrollments
  @file_line_item_learning_objective_ids = file_line_item_learning_objective_ids
  @file_line_items = file_line_items
  @file_line_item_score_scales = file_line_item_score_scales
  @file_orgs = file_orgs
  @file_resources = file_resources
  @file_result_learning_objective_ids = file_result_learning_objective_ids
  @file_results = file_results
  @file_result_score_scales = file_result_score_scales
  @file_roles = file_roles
  @file_score_scales = file_score_scales
  @file_user_profiles = file_user_profiles
  @file_user_resources = file_user_resources
  @file_users = file_users
  @source_system_name = source_system_name
  @source_system_code = source_system_code
end

Instance Attribute Details

#file_academic_sessionsObject (readonly)

Returns the value of attribute file_academic_sessions.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_academic_sessions
  @file_academic_sessions
end

#file_categoriesObject (readonly)

Returns the value of attribute file_categories.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_categories
  @file_categories
end

#file_class_resourcesObject (readonly)

Returns the value of attribute file_class_resources.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_class_resources
  @file_class_resources
end

#file_classesObject (readonly)

Returns the value of attribute file_classes.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_classes
  @file_classes
end

#file_course_resourcesObject (readonly)

Returns the value of attribute file_course_resources.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_course_resources
  @file_course_resources
end

#file_coursesObject (readonly)

Returns the value of attribute file_courses.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_courses
  @file_courses
end

#file_demographicsObject (readonly)

Returns the value of attribute file_demographics.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_demographics
  @file_demographics
end

#file_enrollmentsObject (readonly)

Returns the value of attribute file_enrollments.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_enrollments
  @file_enrollments
end

#file_line_item_learning_objective_idsObject (readonly)

Returns the value of attribute file_line_item_learning_objective_ids.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_line_item_learning_objective_ids
  @file_line_item_learning_objective_ids
end

#file_line_item_score_scalesObject (readonly)

Returns the value of attribute file_line_item_score_scales.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_line_item_score_scales
  @file_line_item_score_scales
end

#file_line_itemsObject (readonly)

Returns the value of attribute file_line_items.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_line_items
  @file_line_items
end

#file_orgsObject (readonly)

Returns the value of attribute file_orgs.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_orgs
  @file_orgs
end

#file_resourcesObject (readonly)

Returns the value of attribute file_resources.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_resources
  @file_resources
end

#file_result_learning_objective_idsObject (readonly)

Returns the value of attribute file_result_learning_objective_ids.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_result_learning_objective_ids
  @file_result_learning_objective_ids
end

#file_result_score_scalesObject (readonly)

Returns the value of attribute file_result_score_scales.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_result_score_scales
  @file_result_score_scales
end

#file_resultsObject (readonly)

Returns the value of attribute file_results.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_results
  @file_results
end

#file_rolesObject (readonly)

Returns the value of attribute file_roles.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_roles
  @file_roles
end

#file_score_scalesObject (readonly)

Returns the value of attribute file_score_scales.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_score_scales
  @file_score_scales
end

#file_user_profilesObject (readonly)

Returns the value of attribute file_user_profiles.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_user_profiles
  @file_user_profiles
end

#file_user_resourcesObject (readonly)

Returns the value of attribute file_user_resources.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_user_resources
  @file_user_resources
end

#file_usersObject (readonly)

Returns the value of attribute file_users.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def file_users
  @file_users
end

#manifest_versionObject (readonly)

Returns the value of attribute manifest_version.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def manifest_version
  @manifest_version
end

#oneroster_versionObject (readonly)

Returns the value of attribute oneroster_version.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def oneroster_version
  @oneroster_version
end

#source_system_codeObject (readonly)

Returns the value of attribute source_system_code.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def source_system_code
  @source_system_code
end

#source_system_nameObject (readonly)

Returns the value of attribute source_system_name.



39
40
41
# File 'lib/meibo/manifest.rb', line 39

def source_system_name
  @source_system_name
end

Class Method Details

.attribute_to_property_name(attribute) ⇒ Object



61
62
63
# File 'lib/meibo/manifest.rb', line 61

def self.attribute_to_property_name(attribute)
  ATTRIBUTE_TO_PROPERTY_NAME_MAP.fetch(attribute)
end

.filenameObject



45
46
47
# File 'lib/meibo/manifest.rb', line 45

def self.filename
  "manifest.csv"
end

.filename_for(attribute) ⇒ Object

Raises:



65
66
67
68
69
70
71
# File 'lib/meibo/manifest.rb', line 65

def self.filename_for(attribute)
  property_name = attribute_to_property_name(attribute)

  raise Meibo::Error, "#{property_name}はファイルのプロパティではありません" unless property_name.start_with?("file.")

  "#{property_name.split("file.", 2).last}.csv"
end

.parse(csv) ⇒ Object



73
74
75
76
77
78
# File 'lib/meibo/manifest.rb', line 73

def self.parse(csv)
  properties = CSV.parse(csv, encoding: Meibo::CSV_ENCODING, headers: true, header_converters: header_converters)
  new(**properties.to_h do |property|
          [PROPERTY_NAME_TO_ATTRIBUTE_MAP.fetch(property[:property_name]), property[:value]]
        end)
end

Instance Method Details

#deconstructObject



146
147
148
# File 'lib/meibo/manifest.rb', line 146

def deconstruct
  to_a
end

#deconstruct_keys(_keys) ⇒ Object



150
151
152
# File 'lib/meibo/manifest.rb', line 150

def deconstruct_keys(_keys)
  to_h
end

#file_attributes(processing_mode:) ⇒ Object



140
141
142
143
144
# File 'lib/meibo/manifest.rb', line 140

def file_attributes(processing_mode:)
  PROPERTY_NAME_TO_ATTRIBUTE_MAP.values.filter_map do |attribute|
    attribute.start_with?("file_") && public_send(attribute) == processing_mode.to_s && attribute
  end
end

#filenames(processing_mode:) ⇒ Object



134
135
136
137
138
# File 'lib/meibo/manifest.rb', line 134

def filenames(processing_mode:)
  file_attributes(processing_mode: processing_mode).map do |attribute|
    self.class.filename_for(attribute)
  end
end

#to_aObject



154
155
156
157
158
# File 'lib/meibo/manifest.rb', line 154

def to_a
  PROPERTY_NAME_TO_ATTRIBUTE_MAP.map do |property_name, attribute|
    [property_name, public_send(attribute)]
  end
end

#to_hObject



160
161
162
# File 'lib/meibo/manifest.rb', line 160

def to_h
  PROPERTY_NAME_TO_ATTRIBUTE_MAP.values.to_h { |attribute| [attribute, public_send(attribute)] }
end