Class: LearningDiary
- Inherits:
-
Object
- Object
- LearningDiary
- Includes:
- Enumerable
- Defined in:
- lib/docfolio/learning_diary.rb
Overview
collection class for paragraphs synonym ‘Topic’ ‘Learning Diary’
Instance Attribute Summary collapse
-
#paragraphs ⇒ Object
readonly
Returns the value of attribute paragraphs.
Instance Method Summary collapse
- #[](index) ⇒ Object
- #credits_total ⇒ Object
- #each(&block) ⇒ Object
- #impact_credits ⇒ Object
- #impact_credits_total ⇒ Object
-
#initialize(file) ⇒ LearningDiary
constructor
A new instance of LearningDiary.
- #standard_credits ⇒ Object
- #standard_credits_total ⇒ Object
Constructor Details
#initialize(file) ⇒ LearningDiary
Returns a new instance of LearningDiary.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/docfolio/learning_diary.rb', line 13 def initialize(file) # preparation # @todo extract to an initialize_vars function, as in the paragraph class Paragraph.reset @console_view = DiaryConsoleView.new @paragraphs = [] @standard_credits_array = [] @impact_credits_array = [] # read the whole txt file in one go f = File.read(file, encoding: 'UTF-8') # iterates through each paragraph f.split(/\n/).each do |p| next if p == '' # ignore if paragraph empty @paragraphs << Paragraph.new(p) # end calc_standard_credits calc_impact_credits end |
Instance Attribute Details
#paragraphs ⇒ Object (readonly)
Returns the value of attribute paragraphs.
10 11 12 |
# File 'lib/docfolio/learning_diary.rb', line 10 def paragraphs @paragraphs end |
Instance Method Details
#[](index) ⇒ Object
38 39 40 |
# File 'lib/docfolio/learning_diary.rb', line 38 def [](index) @paragraphs[index] end |
#credits_total ⇒ Object
54 55 56 |
# File 'lib/docfolio/learning_diary.rb', line 54 def credits_total impact_credits_total + standard_credits_total end |
#each(&block) ⇒ Object
34 35 36 |
# File 'lib/docfolio/learning_diary.rb', line 34 def each(&block) @paragraphs.each { |p| block.call(p) } end |
#impact_credits ⇒ Object
58 59 60 |
# File 'lib/docfolio/learning_diary.rb', line 58 def impact_credits @impact_credits_array end |
#impact_credits_total ⇒ Object
50 51 52 |
# File 'lib/docfolio/learning_diary.rb', line 50 def impact_credits_total @impact_credits_array.reduce(0) { |a, e| a + e[2] } end |
#standard_credits ⇒ Object
46 47 48 |
# File 'lib/docfolio/learning_diary.rb', line 46 def standard_credits @standard_credits_array end |
#standard_credits_total ⇒ Object
42 43 44 |
# File 'lib/docfolio/learning_diary.rb', line 42 def standard_credits_total @standard_credits_array.reduce(0) { |a, e| a + e[2] } end |