rudo 0.2.1 → 0.3.0

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.
@@ -0,0 +1,9 @@
1
+ ## 0.3.0 (7 November 2012)
2
+
3
+ - Flesh out List class
4
+ - Deprecate Rudo class, will be removed in next version
5
+
6
+ ## 0.2.1 (7 November 2012)
7
+
8
+ - Clean up readme
9
+ - Refactor executables
@@ -29,10 +29,7 @@ class Rudo
29
29
  end
30
30
 
31
31
  def walk(steps=1)
32
- steps.times do
33
- task = @tasks.shift
34
- @tasks << task
35
- end
32
+ steps.times { @tasks << @tasks.shift }
36
33
  write_tasks
37
34
  end
38
35
 
@@ -47,7 +44,7 @@ class Rudo
47
44
  string << "#{@tasks.length} tasks remaining".green
48
45
  end
49
46
 
50
- private
47
+ private
51
48
 
52
49
  def stars
53
50
  "*" * 40
@@ -1,5 +1,68 @@
1
1
  class Rudo
2
2
  class List
3
-
3
+ attr_accessor :tasks
4
+
5
+ def initialize
6
+ self.file_path = File.expand_path('~/rudo.yml')
7
+ self.tasks = YAML.load(File.read(file_path))
8
+ end
9
+
10
+ def length
11
+ tasks.length
12
+ end
13
+
14
+ def add(task)
15
+ tasks << task
16
+ write_tasks
17
+ end
18
+
19
+ def prepend(task)
20
+ tasks.unshift(task)
21
+ write_tasks
22
+ end
23
+
24
+ def remove(arg=0)
25
+ if arg.to_s =~ /^(\d+)x$/
26
+ $1.to_i.times { tasks.shift }
27
+ else
28
+ tasks.delete_at(arg.to_i)
29
+ end
30
+ write_tasks
31
+ end
32
+
33
+ def walk(count=1)
34
+ count.to_i.times { tasks << tasks.shift }
35
+ write_tasks
36
+ end
37
+
38
+ def last
39
+ tasks.last
40
+ end
41
+
42
+ def first
43
+ tasks.first
44
+ end
45
+
46
+ def to_s
47
+ string = "#{stars}\n"
48
+ tasks.each_with_index do |task, index|
49
+ string << "#{index + 1}: #{task}\n"
50
+ end
51
+
52
+ string << "#{stars}\n"
53
+ string << "#{tasks.length} tasks remaining".green
54
+ end
55
+
56
+ private
57
+
58
+ attr_accessor :file_path
59
+
60
+ def stars
61
+ "*" * 40
62
+ end
63
+
64
+ def write_tasks
65
+ File.write(file_path, tasks.to_yaml)
66
+ end
4
67
  end
5
68
  end
@@ -1,4 +1,148 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Rudo::List do
4
+ let(:tasks) { ["buy groceries", "wax the dog", "feed the elephant"] }
5
+ let(:file_path) { File.expand_path('~/rudo.yml') }
6
+ let(:yaml) { tasks.to_yaml }
7
+ let(:list) { Rudo::List.new }
8
+
9
+ before(:each) do
10
+ File.stub(:read).and_return(yaml)
11
+ File.stub(:write)
12
+ end
13
+
14
+ describe '#add' do
15
+ it "adds the task to the end of the list" do
16
+ expect {
17
+ list.add("do laundry")
18
+ }.to change(list, :length).by(1)
19
+ list.last.should eq "do laundry"
20
+ end
21
+
22
+ it "writes the tasks to a file" do
23
+ new_tasks = tasks + ["do laundry"]
24
+ File.should_receive(:write).with(file_path, new_tasks.to_yaml)
25
+ list.add("do laundry")
26
+ end
27
+ end
28
+
29
+ describe '#prepend' do
30
+ it "adds the task to the beginning of the list" do
31
+ expect {
32
+ list.prepend("do laundry")
33
+ }.to change(list, :length).by(1)
34
+ list.first.should eq "do laundry"
35
+ end
36
+
37
+ it "writes the tasks to a file" do
38
+ new_tasks = ["do laundry"] + tasks
39
+ File.should_receive(:write).with(file_path, new_tasks.to_yaml)
40
+ list.prepend("do laundry")
41
+ end
42
+ end
43
+
44
+ describe '#remove' do
45
+ context "when position is some number followed by an 'x'" do
46
+ it "removes the first n items" do
47
+ expect {
48
+ list.remove('2x')
49
+ }.to change(list, :length).by(-2)
50
+ list.first.should eq "feed the elephant"
51
+ end
52
+ end
53
+
54
+ context "when the position is a number" do
55
+ it "removes the item specified" do
56
+ expect {
57
+ list.remove('2')
58
+ }.to change(list, :length).by(-1)
59
+ expected_tasks = tasks.dup
60
+ expected_tasks.delete_at(2)
61
+ list.tasks.should eq expected_tasks
62
+ end
63
+ end
64
+
65
+ context "when the position is trash text" do
66
+ it "removes the first item in the list" do
67
+ expect {
68
+ list.remove('trash')
69
+ }.to change(list, :length).by(-1)
70
+ list.tasks.should eq tasks[1..-1]
71
+ end
72
+ end
73
+
74
+ context "when the position is nil" do
75
+ it "removes the first item in the list" do
76
+ expect {
77
+ list.remove(nil)
78
+ }.to change(list, :length).by(-1)
79
+ list.tasks.should eq tasks[1..-1]
80
+ end
81
+ end
82
+
83
+ context "when the position is not given" do
84
+ it "removes the first item in the list" do
85
+ expect {
86
+ list.remove
87
+ }.to change(list, :length).by(-1)
88
+ list.tasks.should eq tasks[1..-1]
89
+ end
90
+ end
91
+
92
+ it "writes the tasks to a file" do
93
+ new_tasks = tasks[1..-1]
94
+ File.should_receive(:write).with(file_path, new_tasks.to_yaml)
95
+ list.remove
96
+ end
97
+ end
98
+
99
+ describe '#walk' do
100
+ it "moves the first task from the list to the end" do
101
+ expect {
102
+ list.walk
103
+ }.to change(list, :last).from(list.last).to(list.first)
104
+ end
105
+
106
+ it "writes to a file" do
107
+ new_tasks = tasks[1..-1] << tasks.first
108
+ File.should_receive(:write).with(file_path, new_tasks.to_yaml)
109
+ list.walk
110
+ end
111
+
112
+ context "given an integer value" do
113
+ it "moves that many elements to the end" do
114
+ expected_tasks = tasks.dup
115
+ 2.times { expected_tasks << expected_tasks.shift }
116
+ expect {
117
+ list.walk(2)
118
+ }.to change(list, :tasks).to(expected_tasks)
119
+ end
120
+ end
121
+ end
122
+
123
+ describe '#to_s' do
124
+ let(:stars) { '*' * 40 }
125
+
126
+ context "when there are no tasks" do
127
+ let(:yaml) { [].to_yaml }
128
+
129
+ it "returns two lines of stars and 0 tasks remaining" do
130
+ expected = "#{stars}\n#{stars}\n#{"0 tasks remaining".green}"
131
+ list.to_s.should eq expected
132
+ end
133
+ end
134
+
135
+ context 'when there are tasks' do
136
+ it "returns the task with the count in green" do
137
+ expected = "#{stars}\n"
138
+ expected << "1: buy groceries\n"
139
+ expected << "2: wax the dog\n"
140
+ expected << "3: feed the elephant\n"
141
+ expected << "#{stars}\n"
142
+ expected << "3 tasks remaining".green
143
+ list.to_s.should eq expected
144
+ end
145
+ end
146
+ end
147
+
4
148
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rudo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -53,21 +53,22 @@ executables:
53
53
  extensions: []
54
54
  extra_rdoc_files: []
55
55
  files:
56
- - lib/rudo/list.rb
57
56
  - lib/rudo.rb
58
- - spec/rudo_spec.rb
57
+ - lib/rudo/list.rb
59
58
  - spec/spec_helper.rb
59
+ - spec/rudo/list_spec.rb
60
60
  - spec/fixtures/tasks.yml
61
61
  - spec/fixtures/empty.yml
62
- - spec/rudo/list_spec.rb
63
- - bin/dun
62
+ - spec/rudo_spec.rb
64
63
  - bin/walk
65
- - bin/rudo
64
+ - bin/dun
66
65
  - bin/rad
67
- - README.md
66
+ - bin/rudo
68
67
  - MIT-LICENSE
69
- - Gemfile
68
+ - README.md
69
+ - CHANGELOG.md
70
70
  - Rakefile
71
+ - Gemfile
71
72
  homepage: https://github.com/mockdeep/rudo
72
73
  licenses: []
73
74
  post_install_message: