Class: MorningPagesJournal::Journal
- Inherits:
-
Object
- Object
- MorningPagesJournal::Journal
- Defined in:
- lib/morning-pages-journal/journal.rb
Instance Method Summary collapse
- #average_words ⇒ Object
- #each_day(range = :month) ⇒ Object
- #get_page(date) ⇒ Object
-
#initialize(options) ⇒ Journal
constructor
A new instance of Journal.
- #max_date ⇒ Object
- #min_date(range = :month) ⇒ Object
- #pages ⇒ Object
- #pages_from(from, to) ⇒ Object
- #today_file ⇒ Object
- #today_folder ⇒ Object
- #word_count(range = :month) ⇒ Object
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() raise "Base folder is required" unless [:base_folder] @base_folder = [:base_folder] end |
Instance Method Details
#average_words ⇒ Object
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_date ⇒ Object
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 |
#pages ⇒ Object
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_file ⇒ Object
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_folder ⇒ Object
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 |