Class: MorningPagesJournal::Page
- Inherits:
-
Object
- Object
- MorningPagesJournal::Page
- Defined in:
- lib/morning-pages-journal/journal.rb
Instance Attribute Summary collapse
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
Instance Method Summary collapse
- #content ⇒ Object
- #date ⇒ Object
-
#initialize(file_path) ⇒ Page
constructor
A new instance of Page.
- #word_count(hash = Hash.new(0)) ⇒ Object
- #words ⇒ Object
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_path ⇒ Object (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
#content ⇒ Object
33 34 35 |
# File 'lib/morning-pages-journal/journal.rb', line 33 def content File.open(@file_path).read end |
#date ⇒ Object
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 |
#words ⇒ Object
25 26 27 |
# File 'lib/morning-pages-journal/journal.rb', line 25 def words @count ||= `wc -w #{@file_path}`.split(" ")[0] end |