meibo 0.16.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -4
  3. data/.rubocop_todo.yml +130 -0
  4. data/Gemfile +2 -0
  5. data/Gemfile.lock +11 -2
  6. data/lib/meibo/academic_session.rb +17 -16
  7. data/lib/meibo/builder/academic_session_builder.rb +2 -2
  8. data/lib/meibo/builder/base_builder.rb +3 -2
  9. data/lib/meibo/builder/classroom_builder.rb +3 -3
  10. data/lib/meibo/builder/course_builder.rb +3 -3
  11. data/lib/meibo/builder/demographic_builder.rb +2 -2
  12. data/lib/meibo/builder/enrollment_builder.rb +3 -3
  13. data/lib/meibo/builder/organization_builder.rb +2 -2
  14. data/lib/meibo/builder/role_builder.rb +3 -3
  15. data/lib/meibo/builder/user_builder.rb +2 -2
  16. data/lib/meibo/builder/user_profile_builder.rb +3 -3
  17. data/lib/meibo/builder.rb +3 -2
  18. data/lib/meibo/classroom.rb +27 -28
  19. data/lib/meibo/classroom_set.rb +1 -3
  20. data/lib/meibo/converter.rb +29 -31
  21. data/lib/meibo/course.rb +15 -16
  22. data/lib/meibo/course_set.rb +1 -3
  23. data/lib/meibo/data_model.rb +6 -9
  24. data/lib/meibo/data_set.rb +17 -8
  25. data/lib/meibo/demographic.rb +30 -29
  26. data/lib/meibo/enrollment.rb +18 -17
  27. data/lib/meibo/factory_bot/academic_session.rb +3 -3
  28. data/lib/meibo/factory_bot/all.rb +11 -11
  29. data/lib/meibo/factory_bot/classroom.rb +4 -4
  30. data/lib/meibo/factory_bot/course.rb +4 -4
  31. data/lib/meibo/factory_bot/demographic.rb +3 -3
  32. data/lib/meibo/factory_bot/enrollment.rb +3 -3
  33. data/lib/meibo/factory_bot/manifest.rb +2 -2
  34. data/lib/meibo/factory_bot/organization.rb +15 -12
  35. data/lib/meibo/factory_bot/role.rb +3 -3
  36. data/lib/meibo/factory_bot/roster.rb +2 -2
  37. data/lib/meibo/factory_bot/user.rb +6 -6
  38. data/lib/meibo/factory_bot/user_profile.rb +7 -7
  39. data/lib/meibo/japan_profile/academic_session.rb +4 -2
  40. data/lib/meibo/japan_profile/classroom.rb +1 -1
  41. data/lib/meibo/japan_profile/course.rb +2 -2
  42. data/lib/meibo/japan_profile/enrollment.rb +9 -8
  43. data/lib/meibo/japan_profile/organization.rb +2 -2
  44. data/lib/meibo/japan_profile/role.rb +3 -3
  45. data/lib/meibo/japan_profile/user.rb +6 -5
  46. data/lib/meibo/japan_profile/user_set.rb +1 -3
  47. data/lib/meibo/japan_profile.rb +2 -2
  48. data/lib/meibo/manifest/processing_mode.rb +6 -5
  49. data/lib/meibo/manifest.rb +47 -41
  50. data/lib/meibo/organization.rb +16 -15
  51. data/lib/meibo/profile.rb +3 -3
  52. data/lib/meibo/reader.rb +11 -7
  53. data/lib/meibo/role.rb +28 -27
  54. data/lib/meibo/role_set.rb +1 -3
  55. data/lib/meibo/roster.rb +64 -41
  56. data/lib/meibo/user.rb +29 -28
  57. data/lib/meibo/user_profile.rb +14 -13
  58. data/lib/meibo/user_set.rb +1 -3
  59. data/lib/meibo/version.rb +1 -1
  60. data/lib/meibo.rb +2 -2
  61. data/meibo.gemspec +2 -0
  62. metadata +19 -3
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'factory_bot'
4
- require 'securerandom'
3
+ require "factory_bot"
4
+ require "securerandom"
5
5
 
6
6
  FactoryBot.define do
7
- factory :meibo_role, class: 'Meibo::Role' do
7
+ factory :meibo_role, class: "Meibo::Role" do
8
8
  initialize_with { new(**attributes) }
9
9
 
10
10
  transient do
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'factory_bot'
3
+ require "factory_bot"
4
4
 
5
5
  FactoryBot.define do
6
- factory :meibo_roster, class: 'Meibo::Roster' do
6
+ factory :meibo_roster, class: "Meibo::Roster" do
7
7
  initialize_with { new(**attributes) }
8
8
  end
9
9
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'factory_bot'
4
- require 'securerandom'
3
+ require "factory_bot"
4
+ require "securerandom"
5
5
 
6
6
  FactoryBot.define do
7
- factory :meibo_user, class: 'Meibo::User' do
7
+ factory :meibo_user, class: "Meibo::User" do
8
8
  initialize_with { new(**attributes) }
9
9
 
10
10
  transient do
@@ -13,9 +13,9 @@ FactoryBot.define do
13
13
  end
14
14
 
15
15
  sourced_id { SecureRandom.uuid }
16
- sequence(:username) {|n| "user#{n}@example.com" }
17
- sequence(:given_name) {|n| "John#{n}" }
18
- sequence(:family_name) {|n| "Doe#{n}" }
16
+ sequence(:username) { |n| "user#{n}@example.com" }
17
+ sequence(:given_name) { |n| "John#{n}" }
18
+ sequence(:family_name) { |n| "Doe#{n}" }
19
19
  agent_sourced_ids { agents&.map(&:sourced_id) }
20
20
  primary_org_sourced_id { primary_organization&.sourced_id }
21
21
 
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'factory_bot'
4
- require 'securerandom'
3
+ require "factory_bot"
4
+ require "securerandom"
5
5
 
6
6
  FactoryBot.define do
7
- factory :meibo_user_profile, class: 'Meibo::UserProfile' do
7
+ factory :meibo_user_profile, class: "Meibo::UserProfile" do
8
8
  initialize_with { new(**attributes) }
9
9
 
10
10
  transient do
@@ -13,10 +13,10 @@ FactoryBot.define do
13
13
 
14
14
  sourced_id { SecureRandom.uuid }
15
15
  user_sourced_id { user&.sourced_id }
16
- profile_type { 'meibo test' }
17
- vendor_id { 'meibo' }
18
- credential_type { 'plain' }
19
- sequence(:username) {|n| "user#{n}"}
16
+ profile_type { "meibo test" }
17
+ vendor_id { "meibo" }
18
+ credential_type { "plain" }
19
+ sequence(:username) { |n| "user#{n}" }
20
20
 
21
21
  trait :jp do
22
22
  initialize_with { Meibo::JapanProfile::UserProfile.new(**attributes) }
@@ -3,7 +3,7 @@
3
3
  module Meibo
4
4
  class JapanProfile < ::Meibo::Profile
5
5
  class AcademicSession < ::Meibo::AcademicSession
6
- TYPES = { school_year: 'schoolYear' }.freeze
6
+ TYPES = { school_year: "schoolYear" }.freeze
7
7
 
8
8
  DataModel.define(
9
9
  self,
@@ -18,7 +18,9 @@ module Meibo
18
18
  # - typeはschoolYear固定
19
19
  # - start_dateは対象年度の開始日固定
20
20
  # - end_dateは対象年度の終了日固定
21
- def initialize(school_year:, title: "#{school_year}年度", type: TYPES[:school_year], start_date: Date.new(school_year, 4, 1), end_date: Date.new(school_year + 1, 3, 31), **other_fields)
21
+ def initialize(school_year:, title: "#{school_year}年度", type: TYPES[:school_year],
22
+ start_date: Date.new(school_year, 4,
23
+ 1), end_date: Date.new(school_year + 1, 3, 31), **other_fields)
22
24
  super(school_year: school_year, title: title, type: type, start_date: start_date, end_date: end_date, **other_fields)
23
25
  end
24
26
  end
@@ -6,7 +6,7 @@ module Meibo
6
6
  DataModel.define(
7
7
  self,
8
8
  attribute_name_to_header_field_map: superclass.attribute_name_to_header_field_map.merge(
9
- special_needs: 'metadata.jp.specialNeeds'
9
+ special_needs: "metadata.jp.specialNeeds"
10
10
  ).freeze,
11
11
  converters: superclass.converters.merge(
12
12
  boolean: [:special_needs].freeze,
@@ -6,11 +6,11 @@ module Meibo
6
6
  DataModel.define(
7
7
  self,
8
8
  attribute_name_to_header_field_map: superclass.attribute_name_to_header_field_map,
9
- converters: superclass.converters.merge(enum: { course_code: [''].freeze }.freeze)
9
+ converters: superclass.converters.merge(enum: { course_code: [""].freeze }.freeze)
10
10
  )
11
11
 
12
12
  # NOTE: courseCodeは空文字固定
13
- def initialize(course_code: '', **other_fields)
13
+ def initialize(course_code: "", **other_fields)
14
14
  super(course_code: course_code, **other_fields)
15
15
  end
16
16
  end
@@ -4,17 +4,17 @@ module Meibo
4
4
  class JapanProfile < ::Meibo::Profile
5
5
  class Enrollment < ::Meibo::Enrollment
6
6
  ROLES = {
7
- student: 'student',
8
- teacher: 'teacher',
9
- administrator: 'administrator',
10
- guardian: 'guardian'
7
+ student: "student",
8
+ teacher: "teacher",
9
+ administrator: "administrator",
10
+ guardian: "guardian"
11
11
  }.freeze
12
12
 
13
13
  DataModel.define(
14
14
  self,
15
- attribute_name_to_header_field_map: superclass.attribute_name_to_header_field_map.merge(
16
- shusseki_no: 'metadata.jp.ShussekiNo',
17
- public_flg: 'metadata.jp.PublicFlg'
15
+ attribute_name_to_header_field_map: superclass.attribute_name_to_header_field_map.merge(
16
+ shusseki_no: "metadata.jp.ShussekiNo",
17
+ public_flg: "metadata.jp.PublicFlg"
18
18
  ).freeze,
19
19
  converters: superclass.converters.merge(
20
20
  boolean: [*superclass.converters[:boolean], :public_flg].freeze,
@@ -25,7 +25,8 @@ module Meibo
25
25
 
26
26
  # NOTE: 児童生徒の場合primaryはfalse固定
27
27
  # MEMO: 保護者の場合もそうでは?
28
- def initialize(shusseki_no: nil, public_flg: nil, role:, primary: (role == ROLES[:student] ? false : nil), **other_fields)
28
+ def initialize(role:, shusseki_no: nil, public_flg: nil, primary: (role == ROLES[:student] ? false : nil),
29
+ **other_fields)
29
30
  super(role: role, primary: primary, **other_fields)
30
31
  @shusseki_no = shusseki_no
31
32
  @public_flg = public_flg
@@ -4,8 +4,8 @@ module Meibo
4
4
  class JapanProfile < ::Meibo::Profile
5
5
  class Organization < ::Meibo::Organization
6
6
  TYPES = {
7
- district: 'district',
8
- school: 'school'
7
+ district: "district",
8
+ school: "school"
9
9
  }.freeze
10
10
 
11
11
  DataModel.define(
@@ -9,9 +9,9 @@ module Meibo
9
9
  # - 保護者の場合guardian
10
10
  # MEMO: enrollments.csvの方ではadministratorとguardianも許可されているがズレてないか
11
11
  ROLES = {
12
- teacher: 'teacher',
13
- student: 'student',
14
- guardian: 'guardian'
12
+ teacher: "teacher",
13
+ student: "student",
14
+ guardian: "guardian"
15
15
  }.freeze
16
16
 
17
17
  DataModel.define(
@@ -6,16 +6,17 @@ module Meibo
6
6
  DataModel.define(
7
7
  self,
8
8
  attribute_name_to_header_field_map: superclass.attribute_name_to_header_field_map.merge(
9
- kana_given_name: 'metadata.jp.kanaGivenName',
10
- kana_family_name: 'metadata.jp.kanaFamilyName',
11
- kana_middle_name: 'metadata.jp.kanaMiddleName',
12
- home_class: 'metadata.jp.homeClass'
9
+ kana_given_name: "metadata.jp.kanaGivenName",
10
+ kana_family_name: "metadata.jp.kanaFamilyName",
11
+ kana_middle_name: "metadata.jp.kanaMiddleName",
12
+ home_class: "metadata.jp.homeClass"
13
13
  ).freeze,
14
14
  converters: superclass.converters
15
15
  )
16
16
 
17
17
  # NOTE: enabled_userは必須ではないが固定
18
- def initialize(enabled_user: true, kana_given_name: nil, kana_family_name: nil, kana_middle_name: nil, home_class: nil, **other_fields)
18
+ def initialize(enabled_user: true, kana_given_name: nil, kana_family_name: nil, kana_middle_name: nil,
19
+ home_class: nil, **other_fields)
19
20
  super(enabled_user: enabled_user, **other_fields)
20
21
  @kana_given_name = kana_given_name
21
22
  @kana_family_name = kana_family_name
@@ -6,9 +6,7 @@ module Meibo
6
6
  def check_semantically_consistent
7
7
  super
8
8
  each do |user|
9
- if user.home_class
10
- roster.classes.find(user.home_class)
11
- end
9
+ roster.classes.find(user.home_class) if user.home_class
12
10
  end
13
11
  end
14
12
  end
@@ -12,7 +12,7 @@ module Meibo
12
12
  role: Builder::RoleBuilder.create(Role),
13
13
  user: Builder::UserBuilder.create(User),
14
14
  user_profile: Builder::UserProfileBuilder.create(UserProfile)
15
- }
15
+ }.freeze
16
16
 
17
17
  DATA_MODELS = {
18
18
  file_academic_sessions: AcademicSession,
@@ -24,7 +24,7 @@ module Meibo
24
24
  file_roles: Role,
25
25
  file_user_profiles: UserProfile,
26
26
  file_users: User
27
- }
27
+ }.freeze
28
28
 
29
29
  DATA_SET = ::Meibo::Profile::DATA_SET.merge(
30
30
  users: UserSet
@@ -11,21 +11,22 @@ module Meibo
11
11
  end
12
12
 
13
13
  def absent?
14
- @mode == 'absent'
14
+ @mode == "absent"
15
15
  end
16
16
 
17
17
  def bulk?
18
- @mode == 'bulk'
18
+ @mode == "bulk"
19
19
  end
20
20
 
21
21
  def delta?
22
- @mode == 'delta'
22
+ @mode == "delta"
23
23
  end
24
24
 
25
25
  def ==(other)
26
- if other.is_a?(ProcessingMode)
26
+ case other
27
+ when ProcessingMode
27
28
  @mode == other.mode
28
- elsif other.is_a?(String)
29
+ when String
29
30
  to_s == other
30
31
  else
31
32
  false
@@ -2,43 +2,45 @@
2
2
 
3
3
  module Meibo
4
4
  class Manifest
5
- MANIFEST_VERSION = '1.0'
6
- ONEROSTER_VERSION = '1.2'
5
+ MANIFEST_VERSION = "1.0"
6
+ ONEROSTER_VERSION = "1.2"
7
7
 
8
8
  PROCESSING_MODES = {
9
- absent: ProcessingMode.new('absent'),
10
- bulk: ProcessingMode.new('bulk'),
11
- delta: ProcessingMode.new('delta')
9
+ absent: ProcessingMode.new("absent"),
10
+ bulk: ProcessingMode.new("bulk"),
11
+ delta: ProcessingMode.new("delta")
12
12
  }.freeze
13
13
 
14
14
  PROPERTY_NAME_TO_ATTRIBUTE_MAP = {
15
- 'manifest.version' => :manifest_version,
16
- 'oneroster.version' => :oneroster_version,
17
- 'file.academicSessions' => :file_academic_sessions,
18
- 'file.categories' => :file_categories,
19
- 'file.classes' => :file_classes,
20
- 'file.classResources' => :file_class_resources,
21
- 'file.courses' => :file_courses,
22
- 'file.courseResources' => :file_course_resources,
23
- 'file.demographics' => :file_demographics,
24
- 'file.enrollments' => :file_enrollments,
25
- 'file.lineItemLearningObjectiveIds' => :file_line_item_learning_objective_ids,
26
- 'file.lineItems' => :file_line_items,
27
- 'file.lineItemScoreScales' => :file_line_item_score_scales,
28
- 'file.orgs' => :file_orgs,
29
- 'file.resources' => :file_resources,
30
- 'file.resultLearningObjectiveIds' => :file_result_learning_objective_ids,
31
- 'file.results' => :file_results,
32
- 'file.resultScoreScales' => :file_result_score_scales,
33
- 'file.roles' => :file_roles,
34
- 'file.scoreScales' => :file_score_scales,
35
- 'file.userProfiles' => :file_user_profiles,
36
- 'file.userResources' => :file_user_resources,
37
- 'file.users' => :file_users,
38
- 'source.systemName' => :source_system_name,
39
- 'source.systemCode' => :source_system_code
15
+ "manifest.version" => :manifest_version,
16
+ "oneroster.version" => :oneroster_version,
17
+ "file.academicSessions" => :file_academic_sessions,
18
+ "file.categories" => :file_categories,
19
+ "file.classes" => :file_classes,
20
+ "file.classResources" => :file_class_resources,
21
+ "file.courses" => :file_courses,
22
+ "file.courseResources" => :file_course_resources,
23
+ "file.demographics" => :file_demographics,
24
+ "file.enrollments" => :file_enrollments,
25
+ "file.lineItemLearningObjectiveIds" => :file_line_item_learning_objective_ids,
26
+ "file.lineItems" => :file_line_items,
27
+ "file.lineItemScoreScales" => :file_line_item_score_scales,
28
+ "file.orgs" => :file_orgs,
29
+ "file.resources" => :file_resources,
30
+ "file.resultLearningObjectiveIds" => :file_result_learning_objective_ids,
31
+ "file.results" => :file_results,
32
+ "file.resultScoreScales" => :file_result_score_scales,
33
+ "file.roles" => :file_roles,
34
+ "file.scoreScales" => :file_score_scales,
35
+ "file.userProfiles" => :file_user_profiles,
36
+ "file.userResources" => :file_user_resources,
37
+ "file.users" => :file_users,
38
+ "source.systemName" => :source_system_name,
39
+ "source.systemCode" => :source_system_code
40
40
  }.freeze
41
- ATTRIBUTE_TO_PROPERTY_NAME_MAP = PROPERTY_NAME_TO_ATTRIBUTE_MAP.to_h {|property_name, attribute| [attribute, property_name] }.freeze
41
+ ATTRIBUTE_TO_PROPERTY_NAME_MAP = PROPERTY_NAME_TO_ATTRIBUTE_MAP.to_h do |property_name, attribute|
42
+ [attribute, property_name]
43
+ end.freeze
42
44
 
43
45
  # NOTE: 想定値
44
46
  DEFAULT_VALUES = {
@@ -67,19 +69,20 @@ module Meibo
67
69
  file_users: PROCESSING_MODES[:bulk]
68
70
  }.freeze
69
71
 
70
- attr_reader :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, :source_system_code
72
+ attr_reader :manifest_version, :oneroster_version, :file_academic_sessions, :file_categories, :file_classes,
73
+ :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, :source_system_code
71
74
 
72
75
  def self.build_from_default(**custom_properties)
73
76
  new(**Manifest::DEFAULT_VALUES.merge(custom_properties))
74
77
  end
75
78
 
76
79
  def self.filename
77
- 'manifest.csv'
80
+ "manifest.csv"
78
81
  end
79
82
 
80
83
  attribute_name_to_header_field_map = {
81
- property_name: 'propertyName',
82
- value: 'value'
84
+ property_name: "propertyName",
85
+ value: "value"
83
86
  }
84
87
  header_fields = attribute_name_to_header_field_map.values
85
88
  define_singleton_method(:header_fields) { header_fields }
@@ -92,17 +95,20 @@ module Meibo
92
95
  def self.filename_for(attribute)
93
96
  property_name = attribute_to_property_name(attribute)
94
97
 
95
- raise Meibo::Error, "#{property_name}はファイルのプロパティではありません" unless property_name.start_with?('file.')
98
+ raise Meibo::Error, "#{property_name}はファイルのプロパティではありません" unless property_name.start_with?("file.")
96
99
 
97
- property_name.split('file.', 2).last + '.csv'
100
+ "#{property_name.split("file.", 2).last}.csv"
98
101
  end
99
102
 
100
103
  def self.parse(csv)
101
104
  properties = CSV.parse(csv, encoding: Meibo::CSV_ENCODING, headers: true, header_converters: header_converters)
102
- new(**properties.to_h {|property| [PROPERTY_NAME_TO_ATTRIBUTE_MAP.fetch(property[:property_name]), property[:value]] })
105
+ new(**properties.to_h do |property|
106
+ [PROPERTY_NAME_TO_ATTRIBUTE_MAP.fetch(property[:property_name]), property[:value]]
107
+ end)
103
108
  end
104
109
 
105
- 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)
110
+ def initialize(manifest_version:, oneroster_version:, file_academic_sessions:, file_categories:, file_classes:,
111
+ 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)
106
112
  @manifest_version = manifest_version
107
113
  @oneroster_version = oneroster_version
108
114
  @file_academic_sessions = file_academic_sessions
@@ -138,7 +144,7 @@ module Meibo
138
144
 
139
145
  def file_attributes(processing_mode:)
140
146
  PROPERTY_NAME_TO_ATTRIBUTE_MAP.values.filter_map do |attribute|
141
- attribute.start_with?('file_') && public_send(attribute) == processing_mode.to_s && attribute
147
+ attribute.start_with?("file_") && public_send(attribute) == processing_mode.to_s && attribute
142
148
  end
143
149
  end
144
150
 
@@ -157,7 +163,7 @@ module Meibo
157
163
  end
158
164
 
159
165
  def to_h
160
- PROPERTY_NAME_TO_ATTRIBUTE_MAP.values.to_h {|attribute| [attribute, public_send(attribute)] }
166
+ PROPERTY_NAME_TO_ATTRIBUTE_MAP.values.to_h { |attribute| [attribute, public_send(attribute)] }
161
167
  end
162
168
  end
163
169
  end
@@ -3,34 +3,35 @@
3
3
  module Meibo
4
4
  class Organization
5
5
  TYPES = {
6
- department: 'department',
7
- school: 'school',
8
- district: 'district',
9
- local: 'local',
10
- state: 'state',
11
- national: 'national'
6
+ department: "department",
7
+ school: "school",
8
+ district: "district",
9
+ local: "local",
10
+ state: "state",
11
+ national: "national"
12
12
  }.freeze
13
13
 
14
14
  DataModel.define(
15
15
  self,
16
16
  attribute_name_to_header_field_map: {
17
- sourced_id: 'sourcedId',
18
- status: 'status',
19
- date_last_modified: 'dateLastModified',
20
- name: 'name',
21
- type: 'type',
22
- identifier: 'identifier',
23
- parent_sourced_id: 'parentSourcedId'
17
+ sourced_id: "sourcedId",
18
+ status: "status",
19
+ date_last_modified: "dateLastModified",
20
+ name: "name",
21
+ type: "type",
22
+ identifier: "identifier",
23
+ parent_sourced_id: "parentSourcedId"
24
24
  },
25
25
  converters: {
26
26
  datetime: [:date_last_modified],
27
27
  enum: { type: [*TYPES.values, ENUM_EXT_PATTERN].freeze },
28
- required: [:sourced_id, :name, :type],
28
+ required: %i[sourced_id name type],
29
29
  status: [:status]
30
30
  }
31
31
  )
32
32
 
33
- def initialize(sourced_id:, status: nil, date_last_modified: nil, name:, type:, identifier: nil, parent_sourced_id: (type == TYPES[:district] ? 'NULL' : nil), **extension_fields)
33
+ def initialize(sourced_id:, name:, type:, status: nil, date_last_modified: nil, identifier: nil,
34
+ parent_sourced_id: (type == TYPES[:district] ? "NULL" : nil), **extension_fields)
34
35
  @sourced_id = sourced_id
35
36
  @status = status
36
37
  @date_last_modified = date_last_modified
data/lib/meibo/profile.rb CHANGED
@@ -12,7 +12,7 @@ module Meibo
12
12
  role: Builder::RoleBuilder.create(Role),
13
13
  user: Builder::UserBuilder.create(User),
14
14
  user_profile: Builder::UserProfileBuilder.create(UserProfile)
15
- }
15
+ }.freeze
16
16
 
17
17
  DATA_MODELS = {
18
18
  file_academic_sessions: Meibo::AcademicSession,
@@ -24,7 +24,7 @@ module Meibo
24
24
  file_roles: Meibo::Role,
25
25
  file_user_profiles: Meibo::UserProfile,
26
26
  file_users: Meibo::User
27
- }
27
+ }.freeze
28
28
 
29
29
  DATA_SET = {
30
30
  academic_sessions: Meibo::AcademicSessionSet,
@@ -36,7 +36,7 @@ module Meibo
36
36
  roles: Meibo::RoleSet,
37
37
  user_profiles: Meibo::UserProfileSet,
38
38
  users: Meibo::UserSet
39
- }
39
+ }.freeze
40
40
 
41
41
  attr_reader :builders, :data_models, :data_set
42
42
 
data/lib/meibo/reader.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'csv'
4
- require 'zip'
3
+ require "csv"
4
+ require "zip"
5
5
 
6
6
  module Meibo
7
7
  class Reader
@@ -11,6 +11,12 @@ module Meibo
11
11
  end
12
12
  end
13
13
 
14
+ def self.open_buffer(io, profile: Meibo.default_profile)
15
+ Zip::File.open_buffer(io) do |zipfile|
16
+ yield new(zipfile: zipfile, profile: profile)
17
+ end
18
+ end
19
+
14
20
  attr_reader :profile, :zipfile
15
21
 
16
22
  def initialize(zipfile:, profile:)
@@ -112,11 +118,9 @@ module Meibo
112
118
  file_roles: :roles,
113
119
  file_users: :users,
114
120
  file_user_profiles: :user_profiles
115
- }.filter_map {|file_attribute, data_method|
116
- if bulk_file_attributes.include?(file_attribute)
117
- [data_method, public_send(data_method).to_a]
118
- end
119
- }.to_h
121
+ }.filter_map do |file_attribute, data_method|
122
+ [data_method, public_send(data_method).to_a] if bulk_file_attributes.include?(file_attribute)
123
+ end.to_h
120
124
  end
121
125
 
122
126
  def file_entry?(filename)
data/lib/meibo/role.rb CHANGED
@@ -3,43 +3,43 @@
3
3
  module Meibo
4
4
  class Role
5
5
  TYPES = {
6
- primary: 'primary',
7
- secondary: 'secondary'
6
+ primary: "primary",
7
+ secondary: "secondary"
8
8
  }.freeze
9
9
 
10
10
  ROLES = {
11
- aide: 'aide',
12
- counselor: 'counselor',
13
- district_administrator: 'districtAdministrator',
14
- guardian: 'guardian',
15
- parent: 'parent',
16
- principal: 'principal',
17
- proctor: 'proctor',
18
- relative: 'relative',
19
- site_administrator: 'siteAdministrator',
20
- student: 'student',
21
- system_administrator: 'systemAdministrator',
22
- teacher: 'teacher'
11
+ aide: "aide",
12
+ counselor: "counselor",
13
+ district_administrator: "districtAdministrator",
14
+ guardian: "guardian",
15
+ parent: "parent",
16
+ principal: "principal",
17
+ proctor: "proctor",
18
+ relative: "relative",
19
+ site_administrator: "siteAdministrator",
20
+ student: "student",
21
+ system_administrator: "systemAdministrator",
22
+ teacher: "teacher"
23
23
  }.freeze
24
24
 
25
25
  DataModel.define(
26
26
  self,
27
27
  attribute_name_to_header_field_map: {
28
- sourced_id: 'sourcedId',
29
- status: 'status',
30
- date_last_modified: 'dateLastModified',
31
- user_sourced_id: 'userSourcedId',
32
- role_type: 'roleType',
33
- role: 'role',
34
- begin_date: 'beginDate',
35
- end_date: 'endDate',
36
- org_sourced_id: 'orgSourcedId',
37
- user_profile_sourced_id: 'userProfileSourcedId'
28
+ sourced_id: "sourcedId",
29
+ status: "status",
30
+ date_last_modified: "dateLastModified",
31
+ user_sourced_id: "userSourcedId",
32
+ role_type: "roleType",
33
+ role: "role",
34
+ begin_date: "beginDate",
35
+ end_date: "endDate",
36
+ org_sourced_id: "orgSourcedId",
37
+ user_profile_sourced_id: "userProfileSourcedId"
38
38
  }.freeze,
39
39
  converters: {
40
- date: [:begin_date, :end_date].freeze,
40
+ date: %i[begin_date end_date].freeze,
41
41
  datetime: [:date_last_modified].freeze,
42
- required: [:sourced_id, :user_sourced_id, :role_type, :role, :org_sourced_id].freeze,
42
+ required: %i[sourced_id user_sourced_id role_type role org_sourced_id].freeze,
43
43
  enum: {
44
44
  role: [*ROLES.values, ENUM_EXT_PATTERN].freeze,
45
45
  role_type: TYPES.values.freeze
@@ -48,7 +48,8 @@ module Meibo
48
48
  }.freeze
49
49
  )
50
50
 
51
- def initialize(sourced_id:, status: nil, date_last_modified: nil, user_sourced_id:, role_type:, role:, begin_date: nil, end_date: nil, org_sourced_id:, user_profile_sourced_id: nil, **extension_fields)
51
+ def initialize(sourced_id:, user_sourced_id:, role_type:, role:, org_sourced_id:, status: nil, date_last_modified: nil,
52
+ begin_date: nil, end_date: nil, user_profile_sourced_id: nil, **extension_fields)
52
53
  @sourced_id = sourced_id
53
54
  @status = status
54
55
  @date_last_modified = date_last_modified
@@ -9,9 +9,7 @@ module Meibo
9
9
  roster.organizations.find(role.org_sourced_id)
10
10
  roster.users.find(role.user_sourced_id)
11
11
 
12
- if role.user_profile_sourced_id
13
- roster.user_profiles.find(role.user_profile_sourced_id)
14
- end
12
+ roster.user_profiles.find(role.user_profile_sourced_id) if role.user_profile_sourced_id
15
13
  end
16
14
  end
17
15