morning-pages 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/morning-pages +1 -1
- data/features/step_definitions/steps.rb +1 -1
- data/features/writing_words.feature +1 -1
- data/lib/morning-pages/version.rb +1 -1
- data/lib/morning-pages.rb +18 -2
- data/morning-pages.gemspec +1 -1
- data/spec/stats_spec.rb +21 -4
- metadata +2 -2
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
|
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
|
|
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 =
|
16
|
-
|
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
|
data/morning-pages.gemspec
CHANGED
@@ -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
|
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
|
-
|
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
|
-
|
13
|
-
|
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.
|
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
|
-
|
99
|
+
-h` for more info."
|
100
100
|
email:
|
101
101
|
- chris.p@rsons.org
|
102
102
|
executables:
|