Class: Meibo::Manifest

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

Defined Under Namespace

Classes: ProcessingMode

Constant Summary collapse

MANIFEST_VERSION =
"1.0"
ONEROSTER_VERSION =
"1.2"
PROCESSING_MODES =
{
  absent: ProcessingMode.new("absent"),
  bulk: ProcessingMode.new("bulk"),
  delta: ProcessingMode.new("delta")
}.freeze
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
DEFAULT_VALUES =

NOTE: 想定値

{
  manifest_version: MANIFEST_VERSION,
  oneroster_version: ONEROSTER_VERSION,
  file_academic_sessions: PROCESSING_MODES[:bulk],
  file_categories: PROCESSING_MODES[:absent],
  file_classes: PROCESSING_MODES[:bulk],
  file_class_resources: PROCESSING_MODES[:absent],
  file_courses: PROCESSING_MODES[:bulk],
  file_course_resources: PROCESSING_MODES[:absent],
  file_demographics: PROCESSING_MODES[:bulk],
  file_enrollments: PROCESSING_MODES[:bulk],
  file_line_item_learning_objective_ids: PROCESSING_MODES[:absent],
  file_line_items: PROCESSING_MODES[:absent],
  file_line_item_score_scales: PROCESSING_MODES[:absent],
  file_orgs: PROCESSING_MODES[:bulk],
  file_resources: PROCESSING_MODES[:absent],
  file_result_learning_objective_ids: PROCESSING_MODES[:absent],
  file_results: PROCESSING_MODES[:absent],
  file_result_score_scales: PROCESSING_MODES[:absent],
  file_roles: PROCESSING_MODES[:bulk],
  file_score_scales: PROCESSING_MODES[:absent],
  file_user_profiles: PROCESSING_MODES[:bulk],
  file_user_resources: PROCESSING_MODES[:absent],
  file_users: PROCESSING_MODES[:bulk]
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Manifest.



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/meibo/manifest.rb', line 110

def initialize(manifest_version:, oneroster_version:, file_academic_sessions:, file_categories:, file_classes:,
               file_class_resources:, file_courses:, file_course_resources:, file_demographics:, file_enrollments:, file_line_item_learning_objective_ids:, file_line_items:, file_line_item_score_scales:, file_orgs:, file_resources:, file_result_learning_objective_ids:, file_results:, file_result_score_scales:, file_roles:, file_score_scales:, file_user_profiles:, file_user_resources:, file_users:, 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.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def file_academic_sessions
  @file_academic_sessions
end

#file_categoriesObject (readonly)

Returns the value of attribute file_categories.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def file_categories
  @file_categories
end

#file_class_resourcesObject (readonly)

Returns the value of attribute file_class_resources.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def file_class_resources
  @file_class_resources
end

#file_classesObject (readonly)

Returns the value of attribute file_classes.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def file_classes
  @file_classes
end

#file_course_resourcesObject (readonly)

Returns the value of attribute file_course_resources.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def file_course_resources
  @file_course_resources
end

#file_coursesObject (readonly)

Returns the value of attribute file_courses.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def file_courses
  @file_courses
end

#file_demographicsObject (readonly)

Returns the value of attribute file_demographics.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def file_demographics
  @file_demographics
end

#file_enrollmentsObject (readonly)

Returns the value of attribute file_enrollments.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def file_enrollments
  @file_enrollments
end

#file_line_item_learning_objective_idsObject (readonly)

Returns the value of attribute file_line_item_learning_objective_ids.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

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.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def file_line_item_score_scales
  @file_line_item_score_scales
end

#file_line_itemsObject (readonly)

Returns the value of attribute file_line_items.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def file_line_items
  @file_line_items
end

#file_orgsObject (readonly)

Returns the value of attribute file_orgs.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def file_orgs
  @file_orgs
end

#file_resourcesObject (readonly)

Returns the value of attribute file_resources.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def file_resources
  @file_resources
end

#file_result_learning_objective_idsObject (readonly)

Returns the value of attribute file_result_learning_objective_ids.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

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.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def file_result_score_scales
  @file_result_score_scales
end

#file_resultsObject (readonly)

Returns the value of attribute file_results.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def file_results
  @file_results
end

#file_rolesObject (readonly)

Returns the value of attribute file_roles.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def file_roles
  @file_roles
end

#file_score_scalesObject (readonly)

Returns the value of attribute file_score_scales.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def file_score_scales
  @file_score_scales
end

#file_user_profilesObject (readonly)

Returns the value of attribute file_user_profiles.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def file_user_profiles
  @file_user_profiles
end

#file_user_resourcesObject (readonly)

Returns the value of attribute file_user_resources.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def file_user_resources
  @file_user_resources
end

#file_usersObject (readonly)

Returns the value of attribute file_users.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def file_users
  @file_users
end

#manifest_versionObject (readonly)

Returns the value of attribute manifest_version.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def manifest_version
  @manifest_version
end

#oneroster_versionObject (readonly)

Returns the value of attribute oneroster_version.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def oneroster_version
  @oneroster_version
end

#source_system_codeObject (readonly)

Returns the value of attribute source_system_code.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def source_system_code
  @source_system_code
end

#source_system_nameObject (readonly)

Returns the value of attribute source_system_name.



72
73
74
# File 'lib/meibo/manifest.rb', line 72

def source_system_name
  @source_system_name
end

Class Method Details

.attribute_to_property_name(attribute) ⇒ Object



91
92
93
# File 'lib/meibo/manifest.rb', line 91

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

.build_from_default(**custom_properties) ⇒ Object



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

def self.build_from_default(**custom_properties)
  new(**Manifest::DEFAULT_VALUES.merge(custom_properties))
end

.filenameObject



79
80
81
# File 'lib/meibo/manifest.rb', line 79

def self.filename
  "manifest.csv"
end

.filename_for(attribute) ⇒ Object

Raises:



95
96
97
98
99
100
101
# File 'lib/meibo/manifest.rb', line 95

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



103
104
105
106
107
108
# File 'lib/meibo/manifest.rb', line 103

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



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

def deconstruct
  to_a
end

#deconstruct_keys(_keys) ⇒ Object



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

def deconstruct_keys(_keys)
  to_h
end

#file_attributes(processing_mode:) ⇒ Object



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

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



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

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

#to_aObject



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

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

#to_hObject



165
166
167
# File 'lib/meibo/manifest.rb', line 165

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