Class: Daigaku::Course

Inherits:
Object
  • Object
show all
Defined in:
lib/daigaku/course.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Course

Returns a new instance of Course.



6
7
8
9
10
# File 'lib/daigaku/course.rb', line 6

def initialize(path)
  @path = path
  @title = File.basename(path).gsub(/\_+/, ' ')
  @author = QuickStore.store.get(key(:author))
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



4
5
6
# File 'lib/daigaku/course.rb', line 4

def author
  @author
end

Returns the value of attribute link.



4
5
6
# File 'lib/daigaku/course.rb', line 4

def link
  @link
end

#pathObject (readonly)

Returns the value of attribute path.



4
5
6
# File 'lib/daigaku/course.rb', line 4

def path
  @path
end

#titleObject (readonly)

Returns the value of attribute title.



4
5
6
# File 'lib/daigaku/course.rb', line 4

def title
  @title
end

Instance Method Details

#chaptersObject



12
13
14
# File 'lib/daigaku/course.rb', line 12

def chapters
  @chapters ||= Loading::Chapters.load(@path)
end

#key(key_name) ⇒ Object



24
25
26
# File 'lib/daigaku/course.rb', line 24

def key(key_name)
  Storeable.key(title, prefix: 'courses', suffix: key_name)
end

#mastered?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/daigaku/course.rb', line 20

def mastered?
  chapters.reduce(true) { |mastered, chapter| mastered &&= chapter.mastered? }
end

#started?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/daigaku/course.rb', line 16

def started?
  chapters.reduce(false) { |started, chapter| started ||= chapter.started? }
end