Class: MorningPagesJournal::Journal

Inherits:
Object
  • Object
show all
Defined in:
lib/morning-pages-journal/journal.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Journal

Returns a new instance of Journal.



41
42
43
44
# File 'lib/morning-pages-journal/journal.rb', line 41

def initialize(options)
  raise "Base folder is required" unless options[:base_folder]
  @base_folder = options[:base_folder]
end

Instance Method Details

#average_wordsObject



91
92
93
94
# File 'lib/morning-pages-journal/journal.rb', line 91

def average_words
  w = pages.collect {|p| p.words.to_i}
  w.inject(0.0) { |sum, el| sum + el } / w.size
end

#each_day(range = :month) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/morning-pages-journal/journal.rb', line 64

def each_day(range = :month)
  return if pages.empty?
  max = pages.last.date
  min = date_starting_at(max, range)

  min.upto(max).each do |date|
    yield date
  end
end

#get_page(date) ⇒ Object



60
61
62
# File 'lib/morning-pages-journal/journal.rb', line 60

def get_page(date)
  @pages.select {|p| p.date == date }.first
end

#max_dateObject



79
80
81
# File 'lib/morning-pages-journal/journal.rb', line 79

def max_date
  pages.last.date
end

#min_date(range = :month) ⇒ Object



74
75
76
77
# File 'lib/morning-pages-journal/journal.rb', line 74

def min_date(range = :month)
  # pages.first.date
  date_starting_at(max_date,range)
end

#pagesObject



56
57
58
# File 'lib/morning-pages-journal/journal.rb', line 56

def pages
  @pages ||= pages_files.collect { |path| Page.new(path) }.sort { |a, b| a.date <=> a.date }
end

#pages_from(from, to) ⇒ Object



96
97
98
99
100
# File 'lib/morning-pages-journal/journal.rb', line 96

def pages_from(from,to)
  pages.select do |p|
    p.date >= from && p.date <= to
  end
end

#today_fileObject



51
52
53
54
# File 'lib/morning-pages-journal/journal.rb', line 51

def today_file
  file_name = Date.today.strftime("%d")
  File.join(today_folder,"#{file_name}.txt")
end

#today_folderObject



46
47
48
49
# File 'lib/morning-pages-journal/journal.rb', line 46

def today_folder
   folder = Date.today.strftime("%Y-%m")
   File.join(@base_folder,folder)
end

#word_count(range = :month) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/morning-pages-journal/journal.rb', line 83

def word_count(range=:month)
  hash = Hash.new(0)
  pages_from(min_date(range),max_date).each do |p|
    p.word_count(hash)
  end
  hash
end