Class: Meibo::Reader
- Inherits:
-
Object
- Object
- Meibo::Reader
- Defined in:
- lib/meibo/reader.rb
Instance Attribute Summary collapse
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
-
#zipfile ⇒ Object
readonly
Returns the value of attribute zipfile.
Class Method Summary collapse
- .open(file_path, profile: Meibo.current_profile) ⇒ Object
- .open_buffer(io, profile: Meibo.current_profile) ⇒ Object
Instance Method Summary collapse
- #academic_sessions ⇒ Object
- #classes ⇒ Object
- #courses ⇒ Object
- #demographics ⇒ Object
- #each_academic_session(&block) ⇒ Object
- #each_class(&block) ⇒ Object
- #each_course(&block) ⇒ Object
- #each_demographic(&block) ⇒ Object
- #each_enrollment(&block) ⇒ Object
- #each_organization(&block) ⇒ Object
- #each_role(&block) ⇒ Object
- #each_user(&block) ⇒ Object
- #each_user_profile(&block) ⇒ Object
- #enrollments ⇒ Object
- #file_entry?(filename) ⇒ Boolean
-
#initialize(zipfile:, profile:) ⇒ Reader
constructor
A new instance of Reader.
- #load_bulk_files ⇒ Object
- #manifest ⇒ Object
- #organizations ⇒ Object
- #roles ⇒ Object
- #user_profiles ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(zipfile:, profile:) ⇒ Reader
Returns a new instance of Reader.
22 23 24 25 |
# File 'lib/meibo/reader.rb', line 22 def initialize(zipfile:, profile:) @profile = profile @zipfile = zipfile end |
Instance Attribute Details
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
20 21 22 |
# File 'lib/meibo/reader.rb', line 20 def profile @profile end |
#zipfile ⇒ Object (readonly)
Returns the value of attribute zipfile.
20 21 22 |
# File 'lib/meibo/reader.rb', line 20 def zipfile @zipfile end |
Class Method Details
.open(file_path, profile: Meibo.current_profile) ⇒ Object
8 9 10 11 12 |
# File 'lib/meibo/reader.rb', line 8 def self.open(file_path, profile: Meibo.current_profile) Zip::File.open(file_path) do |zipfile| yield new(zipfile: zipfile, profile: profile) end end |
.open_buffer(io, profile: Meibo.current_profile) ⇒ Object
14 15 16 17 18 |
# File 'lib/meibo/reader.rb', line 14 def self.open_buffer(io, profile: Meibo.current_profile) Zip::File.open_buffer(io) do |zipfile| yield new(zipfile: zipfile, profile: profile) end end |
Instance Method Details
#academic_sessions ⇒ Object
27 28 29 |
# File 'lib/meibo/reader.rb', line 27 def academic_sessions each_academic_session.to_a end |
#classes ⇒ Object
31 32 33 |
# File 'lib/meibo/reader.rb', line 31 def classes each_class.to_a end |
#courses ⇒ Object
35 36 37 |
# File 'lib/meibo/reader.rb', line 35 def courses each_course.to_a end |
#demographics ⇒ Object
39 40 41 |
# File 'lib/meibo/reader.rb', line 39 def demographics each_demographic.to_a end |
#each_academic_session(&block) ⇒ Object
63 64 65 |
# File 'lib/meibo/reader.rb', line 63 def each_academic_session(&block) read_data(:file_academic_sessions, &block) end |
#each_class(&block) ⇒ Object
67 68 69 |
# File 'lib/meibo/reader.rb', line 67 def each_class(&block) read_data(:file_classes, &block) end |
#each_course(&block) ⇒ Object
71 72 73 |
# File 'lib/meibo/reader.rb', line 71 def each_course(&block) read_data(:file_courses, &block) end |
#each_demographic(&block) ⇒ Object
75 76 77 |
# File 'lib/meibo/reader.rb', line 75 def each_demographic(&block) read_data(:file_demographics, &block) end |
#each_enrollment(&block) ⇒ Object
79 80 81 |
# File 'lib/meibo/reader.rb', line 79 def each_enrollment(&block) read_data(:file_enrollments, &block) end |
#each_organization(&block) ⇒ Object
83 84 85 |
# File 'lib/meibo/reader.rb', line 83 def each_organization(&block) read_data(:file_orgs, &block) end |
#each_role(&block) ⇒ Object
87 88 89 |
# File 'lib/meibo/reader.rb', line 87 def each_role(&block) read_data(:file_roles, &block) end |
#each_user(&block) ⇒ Object
95 96 97 |
# File 'lib/meibo/reader.rb', line 95 def each_user(&block) read_data(:file_users, &block) end |
#each_user_profile(&block) ⇒ Object
91 92 93 |
# File 'lib/meibo/reader.rb', line 91 def each_user_profile(&block) read_data(:file_user_profiles, &block) end |
#enrollments ⇒ Object
43 44 45 |
# File 'lib/meibo/reader.rb', line 43 def enrollments each_enrollment.to_a end |
#file_entry?(filename) ⇒ Boolean
126 127 128 129 130 |
# File 'lib/meibo/reader.rb', line 126 def file_entry?(filename) @zipfile.get_entry(filename).file? rescue Errno::ENOENT false end |
#load_bulk_files ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/meibo/reader.rb', line 109 def load_bulk_files bulk_file_attributes = manifest.file_attributes(processing_mode: Meibo::Manifest::PROCESSING_MODES[:bulk]) { file_academic_sessions: :academic_sessions, file_classes: :classes, file_courses: :courses, file_demographics: :demographics, file_enrollments: :enrollments, file_orgs: :organizations, file_roles: :roles, file_users: :users, file_user_profiles: :user_profiles }.filter_map do |file_attribute, data_method| [data_method, public_send(data_method).to_a] if bulk_file_attributes.include?(file_attribute) end.to_h end |
#manifest ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/meibo/reader.rb', line 99 def manifest @manifest ||= begin filename = Meibo::Manifest.filename raise CsvFileNotFoundError, "#{filename} not found" unless file_entry?(filename) csv = @zipfile.read(filename) Meibo::Manifest.parse(csv) end end |
#organizations ⇒ Object
47 48 49 |
# File 'lib/meibo/reader.rb', line 47 def organizations each_organization.to_a end |
#roles ⇒ Object
51 52 53 |
# File 'lib/meibo/reader.rb', line 51 def roles each_role.to_a end |
#user_profiles ⇒ Object
59 60 61 |
# File 'lib/meibo/reader.rb', line 59 def user_profiles each_user_profile.to_a end |
#users ⇒ Object
55 56 57 |
# File 'lib/meibo/reader.rb', line 55 def users each_user.to_a end |