class Senkyoshi::SenkyoshiFile
Constants
- FILE_BLACKLIST
Attributes
location[RW]
path[RW]
xid[RW]
Public Class Methods
belongs_to_scorm_package?(package_paths, file)
click to toggle source
Determine whether or not a file is a part of a scorm package
# File lib/senkyoshi/models/file.rb, line 101 def self.belongs_to_scorm_package?(package_paths, file) package_paths.any? do |path| File.dirname(file.name).start_with? path end end
blacklisted?(file)
click to toggle source
Determine if a file is on the blacklist
# File lib/senkyoshi/models/file.rb, line 77 def self.blacklisted?(file) FILE_BLACKLIST.any? { |list_item| File.fnmatch?(list_item, file.name) } end
metadata_file?(entry_names, file)
click to toggle source
Determine whether or not a file is a metadata file or not
# File lib/senkyoshi/models/file.rb, line 84 def self.metadata_file?(entry_names, file) if File.extname(file.name) == ".xml" # Detect and skip metadata files. non_meta_file = File.join( File.dirname(file.name), File.basename(file.name, ".xml"), ) entry_names.include?(non_meta_file) else false end end
new(zip_entry)
click to toggle source
# File lib/senkyoshi/models/file.rb, line 27 def initialize(zip_entry) begin entry_name = zip_entry.name.encode("UTF-8") rescue Encoding::UndefinedConversionError entry_name = zip_entry.name.force_encoding("UTF-8") end @path = strip_xid entry_name @location = extract_file(zip_entry) # Location of file on local filesystem base_name = File.basename(entry_name) @xid = base_name[/__(xid-[0-9]+_[0-9]+)/, 1] || Senkyoshi.create_random_hex end
valid_file?(entry_names, scorm_paths, file)
click to toggle source
Determine if a file should be included in course files or not
# File lib/senkyoshi/models/file.rb, line 110 def self.valid_file?(entry_names, scorm_paths, file) return false if SenkyoshiFile.blacklisted? file return false if SenkyoshiFile.metadata_file? entry_names, file return false if SenkyoshiFile.belongs_to_scorm_package? scorm_paths, file true end
Public Instance Methods
canvas_conversion(course, _resources = nil)
click to toggle source
# File lib/senkyoshi/models/file.rb, line 56 def canvas_conversion(course, _resources = nil) file = CanvasCc::CanvasCC::Models::CanvasFile.new file.identifier = @xid file.file_location = @location file.file_path = @path file.hidden = false course.files << file course end
cleanup()
click to toggle source
Remove temporary files
# File lib/senkyoshi/models/file.rb, line 70 def cleanup FileUtils.rm_r @dir unless @dir.nil? end
extract_file(entry)
click to toggle source
# File lib/senkyoshi/models/file.rb, line 46 def extract_file(entry) @dir ||= Dir.mktmpdir name = "#{@dir}/#{entry.name}" path = File.dirname(name) FileUtils.mkdir_p path unless Dir.exist? path entry.extract(name) name end
matches_xid?(xid)
click to toggle source
# File lib/senkyoshi/models/file.rb, line 42 def matches_xid?(xid) @xid == xid end