morning-pages 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/morning-pages +10 -2
- data/features/step_definitions/steps.rb +5 -1
- data/features/writing_words.feature +1 -0
- data/lib/morning-pages/version.rb +1 -1
- data/lib/morning-pages.rb +18 -0
- data/spec/setup_spec.rb +16 -0
- data/spec/stats_spec.rb +17 -0
- metadata +6 -4
- data/spec/write_spec.rb +0 -7
data/bin/morning-pages
CHANGED
@@ -1,10 +1,18 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
$: << File.dirname(__FILE__) + '/../lib'
|
2
3
|
|
3
4
|
require 'trollop'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'morning-pages'
|
4
7
|
|
5
8
|
opts = Trollop.options do
|
6
9
|
opt :dir, "Words directory", :required => false, :type => :string, :default => "~/Documents/words"
|
7
10
|
end
|
8
11
|
|
9
|
-
|
10
|
-
|
12
|
+
MorningPages.setup(opts)
|
13
|
+
|
14
|
+
path = MorningPages.today_path(opts[:dir])
|
15
|
+
|
16
|
+
system "$EDITOR #{path}"
|
17
|
+
|
18
|
+
puts MorningPages.stats_for_today(opts[:dir])
|
@@ -9,8 +9,12 @@ 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
|
13
|
+
all_output.should match(/3 words/)
|
14
|
+
end
|
15
|
+
|
12
16
|
Before do
|
13
|
-
@dir = Dir.mktmpdir
|
17
|
+
@dir = Dir.mktmpdir + "/words/foo"
|
14
18
|
end
|
15
19
|
|
16
20
|
After do
|
data/lib/morning-pages.rb
CHANGED
@@ -1,4 +1,22 @@
|
|
1
1
|
require "morning-pages/version"
|
2
2
|
|
3
|
+
class Array
|
4
|
+
def mean
|
5
|
+
inject(0, &:+) / count.to_f
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
3
9
|
module MorningPages
|
10
|
+
def self.setup(options)
|
11
|
+
FileUtils.mkdir_p(options[:dir]) unless File.exists?(options[:dir])
|
12
|
+
end
|
13
|
+
|
14
|
+
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 ]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.today_path(dir)
|
20
|
+
File.expand_path([dir, Time.now.strftime("%Y\-%m\-%d")].join('/'))
|
21
|
+
end
|
4
22
|
end
|
data/spec/setup_spec.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'morning-pages'
|
2
|
+
|
3
|
+
describe 'setup' do
|
4
|
+
context 'with a new folder' do
|
5
|
+
it 'creates the folder' do
|
6
|
+
FileUtils.should_receive(:mkdir_p)
|
7
|
+
MorningPages.setup(:dir => 'new-folder')
|
8
|
+
end
|
9
|
+
end
|
10
|
+
context 'with an existing folder' do
|
11
|
+
it 'does nothing' do
|
12
|
+
FileUtils.should_not_receive(:mkdir_p)
|
13
|
+
MorningPages.setup(:dir => '.')
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/spec/stats_spec.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'morning-pages'
|
2
|
+
|
3
|
+
module MorningPages
|
4
|
+
describe 'stats' do
|
5
|
+
context 'for today' do
|
6
|
+
it 'prints out the word count' do
|
7
|
+
File.stub(:read => "foo bar")
|
8
|
+
MorningPages.stats_for_today("/tmp").should match(/2 words/)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'prints the average word length' do
|
12
|
+
File.stub(:read => "foo ba")
|
13
|
+
MorningPages.stats_for_today("/tmp").should match(/2\.5/)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
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.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: trollop
|
@@ -118,7 +118,8 @@ files:
|
|
118
118
|
- lib/morning-pages.rb
|
119
119
|
- lib/morning-pages/version.rb
|
120
120
|
- morning-pages.gemspec
|
121
|
-
- spec/
|
121
|
+
- spec/setup_spec.rb
|
122
|
+
- spec/stats_spec.rb
|
122
123
|
homepage: http://github.com/chrismdp/morning-pages
|
123
124
|
licenses: []
|
124
125
|
post_install_message:
|
@@ -149,4 +150,5 @@ test_files:
|
|
149
150
|
- features/support/driver.rb
|
150
151
|
- features/support/env.rb
|
151
152
|
- features/writing_words.feature
|
152
|
-
- spec/
|
153
|
+
- spec/setup_spec.rb
|
154
|
+
- spec/stats_spec.rb
|