Class: LearningDiary

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/docfolio/learning_diary.rb

Overview

collection class for paragraphs synonym ‘Topic’ ‘Learning Diary’

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ LearningDiary

Returns a new instance of LearningDiary.

Parameters:

  • file (String)

    name of a text file containing text in docfolio DSL



18
19
20
21
22
# File 'lib/docfolio/learning_diary.rb', line 18

def initialize(file)
  initialize_vars
  parse(file)
  calculate_credits
end

Instance Attribute Details

#impact_creditsObject (readonly)

The credit arrays are arrays of elements of type [start_time, end_time, duration], one for each tag in all the paragraphs that earns credit



15
16
17
# File 'lib/docfolio/learning_diary.rb', line 15

def impact_credits
  @impact_credits
end

#paragraphsObject (readonly)

Paragraphs is an array representing the parsed DSL from one file



10
11
12
# File 'lib/docfolio/learning_diary.rb', line 10

def paragraphs
  @paragraphs
end

#standard_creditsObject (readonly)

The credit arrays are arrays of elements of type [start_time, end_time, duration], one for each tag in all the paragraphs that earns credit



15
16
17
# File 'lib/docfolio/learning_diary.rb', line 15

def standard_credits
  @standard_credits
end

Instance Method Details

#[](index) ⇒ Object

Implements [] by indexing the @paragraphs instance variable



31
32
33
# File 'lib/docfolio/learning_diary.rb', line 31

def [](index)
  @paragraphs[index]
end

#credits_totalInteger

Returns The sum of the impact and standard credits in minutes.

Returns:

  • (Integer)

    The sum of the impact and standard credits in minutes



46
47
48
# File 'lib/docfolio/learning_diary.rb', line 46

def credits_total
  impact_credits_total + standard_credits_total
end

#each(&block) ⇒ Object

Implements Enuemerable module by iterating through each paragraph in the learning diary



26
27
28
# File 'lib/docfolio/learning_diary.rb', line 26

def each(&block)
  @paragraphs.each { |p| block.call(p) }
end

#impact_credits_totalInteger

Returns The sum of the impact credits in minutes.

Returns:

  • (Integer)

    The sum of the impact credits in minutes



41
42
43
# File 'lib/docfolio/learning_diary.rb', line 41

def impact_credits_total
  impact_credits.reduce(0) { |a, e| a + e[2] }
end

#significant_event?Boolean

Returns:

  • (Boolean)


50
51
52
53
# File 'lib/docfolio/learning_diary.rb', line 50

def significant_event?
  paragraphs.each { |p| return true if p.significant_event? }
  false
end

#standard_credits_totalInteger

Returns The sum of the standard credits in minutes.

Returns:

  • (Integer)

    The sum of the standard credits in minutes



36
37
38
# File 'lib/docfolio/learning_diary.rb', line 36

def standard_credits_total
  standard_credits.reduce(0) { |a, e| a + e[2] }
end