Class: MorningPagesJournal::Page

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ Page

Returns a new instance of Page.



9
10
11
# File 'lib/morning-pages-journal/journal.rb', line 9

def initialize(file_path)
  @file_path = file_path
end

Instance Attribute Details

#file_pathObject (readonly)

Returns the value of attribute file_path.



7
8
9
# File 'lib/morning-pages-journal/journal.rb', line 7

def file_path
  @file_path
end

Instance Method Details

#contentObject



33
34
35
# File 'lib/morning-pages-journal/journal.rb', line 33

def content
  File.open(@file_path).read
end

#dateObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/morning-pages-journal/journal.rb', line 13

def date
  return @date if @date

  s = @file_path.split("/")

  year_month = s[s.size-2]
  day = s[s.size-1].split(".")[0]

  @date = Date.parse("#{year_month}-#{day}")
  @date
end

#word_count(hash = Hash.new(0)) ⇒ Object



29
30
31
# File 'lib/morning-pages-journal/journal.rb', line 29

def word_count(hash = Hash.new(0))
  content.split.inject(hash) { |h,v| h[v] += 1; h }
end

#wordsObject



25
26
27
# File 'lib/morning-pages-journal/journal.rb', line 25

def words
  @count ||= `wc -w #{@file_path}`.split(" ")[0]
end