Class: Daigaku::Course
- Inherits:
-
Object
- Object
- Daigaku::Course
- Defined in:
- lib/daigaku/course.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
readonly
Returns the value of attribute author.
-
#link ⇒ Object
readonly
Returns the value of attribute link.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #chapters ⇒ Object
-
#initialize(path) ⇒ Course
constructor
A new instance of Course.
- #key(key_name) ⇒ Object
- #mastered? ⇒ Boolean
- #started? ⇒ Boolean
Constructor Details
#initialize(path) ⇒ Course
Returns a new instance of Course.
8 9 10 11 12 |
# File 'lib/daigaku/course.rb', line 8 def initialize(path) @path = path @title = File.basename(path).gsub(/\_+/, ' ') @author = QuickStore.store.get(key(:author)) end |
Instance Attribute Details
#author ⇒ Object (readonly)
Returns the value of attribute author.
6 7 8 |
# File 'lib/daigaku/course.rb', line 6 def @author end |
#link ⇒ Object (readonly)
Returns the value of attribute link.
6 7 8 |
# File 'lib/daigaku/course.rb', line 6 def link @link end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/daigaku/course.rb', line 6 def path @path end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
6 7 8 |
# File 'lib/daigaku/course.rb', line 6 def title @title end |
Class Method Details
.unzip(file_path, options = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/daigaku/course.rb', line 41 def unzip(file_path, = {}) target_dir = File.dirname(file_path) course_dir = nil Zip::File.open(file_path) do |zip_file| zip_file.each do |entry| if [:github_repo] first, *others = entry.to_s.split('/') directory = File.join(first.split('-')[0..-2].join('-'), others) else directory = entry.to_s end if course_dir.nil? && directory != '/' course_dir = File.join(target_dir, directory.gsub(/\/$/, '')) if Dir.exist?(course_dir) FileUtils.copy_entry("#{course_dir}/", "#{course_dir}_old/", true) FileUtils.rm_rf("#{course_dir}/.", secure: true) end end zip_file.extract(entry, "#{target_dir}/#{directory}") { true } end end FileUtils.rm(file_path) rescue Exception => e puts e old_dir = "#{course_dir}_old/" FileUtils.copy_entry(old_dir, "#{course_dir}/", true) if Dir.exist?(old_dir) ensure old_dir = "#{course_dir}_old/" FileUtils.rm_r(old_dir) if Dir.exist?(old_dir) return Course.new(course_dir) if course_dir end |
Instance Method Details
#chapters ⇒ Object
14 15 16 |
# File 'lib/daigaku/course.rb', line 14 def chapters @chapters ||= Loading::Chapters.load(@path) end |
#key(key_name) ⇒ Object
26 27 28 |
# File 'lib/daigaku/course.rb', line 26 def key(key_name) Storeable.key(title, prefix: 'courses', suffix: key_name) end |
#mastered? ⇒ Boolean
22 23 24 |
# File 'lib/daigaku/course.rb', line 22 def mastered? chapters.reduce(true) { |mastered, chapter| mastered &&= chapter.mastered? } end |
#started? ⇒ Boolean
18 19 20 |
# File 'lib/daigaku/course.rb', line 18 def started? chapters.reduce(false) { |started, chapter| started ||= chapter.started? } end |