morning-pages 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/morning-pages CHANGED
@@ -2,13 +2,13 @@
2
2
  $: << File.dirname(__FILE__) + '/../lib'
3
3
 
4
4
  require 'trollop'
5
- require 'fileutils'
6
5
  require 'morning-pages'
7
6
 
8
7
  opts = Trollop.options do
9
8
  opt :dir, "Words directory", :required => false, :type => :string, :default => "~/words"
10
9
  end
11
10
 
11
+ opts[:dir] = File.expand_path(opts[:dir])
12
12
  MorningPages.setup(opts)
13
13
 
14
14
  path = MorningPages.today_path(opts[:dir])
@@ -9,7 +9,7 @@ Then /^I should be able to write my words$/ do
9
9
  check_exact_file_content "#{@dir}/#{Time.now.strftime("%Y\-%m\-%d")}", "fake editor output"
10
10
  end
11
11
 
12
- Then /^I see my current word count after I finish$/ do
12
+ Then /^I see my current word stats after I finish$/ do
13
13
  all_output.should match(/3 words/)
14
14
  end
15
15
 
@@ -6,4 +6,4 @@ Feature: writing words
6
6
  Scenario:
7
7
  When I run 'morning-pages'
8
8
  Then I should be able to write my words
9
- And I see my current word count after I finish
9
+ And I see my current word stats after I finish
@@ -1,3 +1,3 @@
1
1
  module MorningPages
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
data/lib/morning-pages.rb CHANGED
@@ -1,9 +1,14 @@
1
1
  require "morning-pages/version"
2
+ require 'fileutils'
2
3
 
3
4
  class Array
4
5
  def mean
5
6
  inject(0, &:+) / count.to_f
6
7
  end
8
+
9
+ def average_length
10
+ map(&:length).mean
11
+ end
7
12
  end
8
13
 
9
14
  module MorningPages
@@ -12,11 +17,22 @@ module MorningPages
12
17
  end
13
18
 
14
19
  def self.stats_for_today(dir)
15
- words = File.read(today_path(dir)).split(" ")
16
- "You have written #{words.count} words today. Average word length: %.2f" % [ words.map(&:length).mean ]
20
+ words = get_words_for(today_path(dir)).split(" ")
21
+ [
22
+ "You have written #{words.count} words today.",
23
+ average_word_length(words)
24
+ ].join(" ")
25
+ end
26
+
27
+ def self.average_word_length(words)
28
+ words.empty? ? "" : "Average word length: %.2f" % [ words.average_length ]
17
29
  end
18
30
 
19
31
  def self.today_path(dir)
20
32
  File.expand_path([dir, Time.now.strftime("%Y\-%m\-%d")].join('/'))
21
33
  end
34
+
35
+ def self.get_words_for(path)
36
+ File.exists?(path) ? File.read(path) : ""
37
+ end
22
38
  end
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.summary = %q{Command line helper to write your morning pages}
12
12
  s.description = %q{I've long been fascinated by the morning pages habit of writing three pages (or about 750 words) of whatever comes into your head each day - it's like taking a mental showers and helps to clear your head, ready for the day. There are great sites out there like http://750words.com, but I live on the command line and like to keep my words on my own computer.
13
13
 
14
- When installed, type `morning-pages help` for more info.}
14
+ When installed, type `morning-pages -h` for more info.}
15
15
 
16
16
  s.rubyforge_project = "morning-pages"
17
17
 
data/spec/stats_spec.rb CHANGED
@@ -3,14 +3,31 @@ require 'morning-pages'
3
3
  module MorningPages
4
4
  describe 'stats' do
5
5
  context 'for today' do
6
+ before(:each) do
7
+ File.stub(:exists? => true)
8
+ File.stub(:read => "foo ba")
9
+ end
10
+
6
11
  it 'prints out the word count' do
7
- File.stub(:read => "foo bar")
8
- MorningPages.stats_for_today("/tmp").should match(/2 words/)
12
+ MorningPages.stats_for_today("foo").should match(/2 words/)
9
13
  end
10
14
 
11
15
  it 'prints the average word length' do
12
- File.stub(:read => "foo ba")
13
- MorningPages.stats_for_today("/tmp").should match(/2\.5/)
16
+ MorningPages.stats_for_today("foo").should match(/2\.5/)
17
+ end
18
+
19
+ context 'when today has no words yet' do
20
+ before do
21
+ File.stub(:exists? => false)
22
+ end
23
+
24
+ it "shows a message to that effect" do
25
+ MorningPages.stats_for_today("foo").should match(/0 words/)
26
+ end
27
+
28
+ it "does not show average" do
29
+ MorningPages.stats_for_today("foo").should_not match(/NaN/)
30
+ end
14
31
  end
15
32
  end
16
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: morning-pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -96,7 +96,7 @@ description: ! "I've long been fascinated by the morning pages habit of writing
96
96
  taking a mental showers and helps to clear your head, ready for the day. There are
97
97
  great sites out there like http://750words.com, but I live on the command line and
98
98
  like to keep my words on my own computer.\n \n When installed, type `morning-pages
99
- help` for more info."
99
+ -h` for more info."
100
100
  email:
101
101
  - chris.p@rsons.org
102
102
  executables: