qer 0.2.6 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  = qer
2
2
 
3
- * http://github.com/j05h-qer
3
+ * http://github.com/j05h/qer
4
4
 
5
5
  == DESCRIPTION:
6
6
 
@@ -24,6 +24,16 @@ Example Output:
24
24
  (4) Deploy Qer to github. > 15 sec ago
25
25
  ----------------------------------------------------------------------------
26
26
 
27
+ Config file:
28
+
29
+ Qer supports a simple config file for a few options. Qer will look for a YAML
30
+ config at $HOME/.qer. Here's a sample config file with the available flags.
31
+
32
+ ---
33
+ queue_file: ~/Dropbox/.qer-queue # default: ~/.qer-queue
34
+ page_width: 100 # default: 80
35
+ history_length: 45 # default: 30
36
+
27
37
  == SYNOPSIS:
28
38
 
29
39
  Qer supports various operation for manipulating your Todo list.
@@ -85,4 +95,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
85
95
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
86
96
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
87
97
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
88
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
98
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/lib/qer.rb CHANGED
@@ -1,9 +1,12 @@
1
- $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) ||
3
+ $:.include?(File.expand_path(File.dirname(__FILE__)))
2
4
 
3
5
  require 'time'
6
+ require 'yaml'
4
7
  require 'qer/todo'
5
8
  module Qer
6
- VERSION = '0.2.6'
9
+ VERSION = '0.3.0'
7
10
  end
8
11
 
9
12
  class Time
@@ -14,16 +17,19 @@ class Time
14
17
  distance_in_seconds = ((to_time - from_time).abs).round
15
18
 
16
19
  case distance_in_minutes
17
- when 0..1 then "> #{distance_in_seconds} sec ago"
18
- when 2..44 then "> #{distance_in_minutes} min ago"
19
- when 45..89 then "~ 1 hr ago"
20
- when 90..1439 then "~ #{(distance_in_minutes.to_f / 60.0).round} hrs ago"
21
- when 1440..2879 then "~ 1 day ago"
22
- when 2880..43199 then "~ #{(distance_in_minutes / 1440).round} days ago"
23
- when 43200..86399 then "~ 1 month ago"
24
- when 86400..525599 then "~ #{(distance_in_minutes / 43200).round} months ago"
25
- when 525600..1051199 then "~ 1 year ago"
26
- else "> #{(distance_in_minutes / 525600).round} years ago"
20
+ when 0..1 then "> #{distance_in_seconds} sec ago"
21
+ when 2..44 then "> #{distance_in_minutes} min ago"
22
+ when 45..89 then "~ 1 hr ago"
23
+ when 90..1439 then
24
+ "~ #{(distance_in_minutes.to_f / 60.0).round} hrs ago"
25
+ when 1440..2879 then "~ 1 day ago"
26
+ when 2880..43199 then "~ #{(distance_in_minutes / 1440).round} days ago"
27
+ when 43200..86399 then "~ 1 month ago"
28
+ when 86400..525599 then
29
+ "~ #{(distance_in_minutes / 43200).round} months ago"
30
+ when 525600..1051199 then "~ 1 year ago"
31
+ else
32
+ "> #{(distance_in_minutes / 525600).round} years ago"
27
33
  end
28
34
  end
29
35
  end
@@ -1,5 +1,8 @@
1
1
  module Qer
2
2
  class ToDo
3
+
4
+ CONFIG_PATH = File.expand_path("~/.qer")
5
+
3
6
  class << self
4
7
  attr_accessor :quiet
5
8
  end
@@ -7,9 +10,8 @@ module Qer
7
10
  attr_accessor :queue
8
11
  attr_accessor :history
9
12
 
10
- def initialize(filename = File.expand_path("~/.qer-queue"))
11
- @filename = filename
12
- @history_filename = "#{filename}-history"
13
+ def initialize(config_file = CONFIG_PATH)
14
+ load_config(config_file)
13
15
 
14
16
  file {|f| self.queue = Marshal.load(f) } rescue self.queue= []
15
17
  history_file {|f| self.history = Marshal.load(f) } rescue self.history= []
@@ -69,7 +71,7 @@ module Qer
69
71
  end
70
72
 
71
73
  def print_history(string = nil)
72
- dump self.history, string, history_title
74
+ dump self.history.last(history_limit), string, history_title
73
75
  end
74
76
 
75
77
  def write
@@ -80,24 +82,37 @@ module Qer
80
82
  history_file("w+") {|f| Marshal.dump(self.history, f) }
81
83
  end
82
84
 
85
+ def history_limit
86
+ @config["history_limit"] || 30
87
+ end
88
+
83
89
  def file(mode = "r", &block)
84
- File.open(@filename, mode) do |f|
85
- yield f
86
- end
90
+ File.open(filename, mode) { |f| yield f }
87
91
  end
88
92
 
89
93
  def history_file(mode = "r", &block)
90
- File.open(@history_filename, mode) do |f|
91
- yield f
92
- end
94
+ File.open(history_filename, mode) { |f| yield f }
93
95
  end
94
96
 
95
- def size
96
- self.queue.size
97
+ def width
98
+ @config["page_width"] || 80
97
99
  end
98
100
 
99
- def width
100
- 80
101
+ def load_config(path)
102
+ @config = {}
103
+ return unless File.exist?(path)
104
+ @config = YAML.load_file(path)
105
+ rescue StandardError => e
106
+ puts "Error during config file loading."
107
+ puts "Error: #{e.name} - #{e.message}"
108
+ end
109
+
110
+ def filename
111
+ @filename ||= File.expand_path(@config["queue_file"] || "~/.qer-queue")
112
+ end
113
+
114
+ def history_filename
115
+ @history_filename ||= "#{filename}-history"
101
116
  end
102
117
 
103
118
  def title
@@ -116,19 +131,19 @@ module Qer
116
131
  Time.time_ago(Time.parse(t))
117
132
  end
118
133
 
119
- def process_line(index, item)
134
+ def print_line(index, item)
120
135
  return unless item
121
- item.size == 2 ? process_queue_line(index,item) : process_history_line(item)
136
+ item.size == 2 ? print_queue_line(index,item) : print_history_line(item)
122
137
  end
123
138
 
124
- def process_queue_line(index, item)
139
+ def print_queue_line(index, item)
125
140
  time, task = item
126
141
  left = "(#{index}) #{task}"
127
142
  right = tf(time).rjust(width - left.length)
128
143
  right.insert(0, left)
129
144
  end
130
145
 
131
- def process_history_line(item)
146
+ def print_history_line(item)
132
147
  end_time, time, task = item
133
148
  right = "#{tf(time)} | #{tf(end_time)}".rjust(width-task.length)
134
149
  right.insert(0, task)
@@ -141,7 +156,7 @@ module Qer
141
156
  out << hl
142
157
  unless queue.empty?
143
158
  queue.each_with_index do |item, index|
144
- out << process_line(index, item)
159
+ out << print_line(index, item)
145
160
  end
146
161
  else
147
162
  out << "Nothing in this queue!"
@@ -1,7 +1,7 @@
1
1
  require 'stringio'
2
2
  require 'test/unit'
3
3
  require 'shoulda'
4
- require File.dirname(__FILE__) + '/../lib/qer'
4
+ require 'qer'
5
5
 
6
6
  Qer::ToDo.quiet = true
7
7
 
@@ -10,10 +10,22 @@ class Test::Unit::TestCase
10
10
  def assert_output matcher
11
11
  assert_match matcher, read_stdout
12
12
  end
13
-
13
+
14
14
  def read_stdout
15
15
  @output.rewind
16
16
  @output.read
17
17
  end
18
18
 
19
+ def with_config(config)
20
+ tmp_config = 'test/tmp-config'
21
+
22
+ File.open(tmp_config, 'w') do |f|
23
+ f << YAML.dump(config)
24
+ end
25
+
26
+ yield Qer::ToDo.new(tmp_config)
27
+
28
+ ensure
29
+ File.delete(tmp_config) if File.exist?(tmp_config)
30
+ end
19
31
  end
@@ -1,11 +1,13 @@
1
- require File.dirname(__FILE__) + '/test_helper.rb'
1
+ require 'test_helper.rb'
2
2
 
3
3
  class TestQer < Test::Unit::TestCase
4
4
 
5
5
  def setup
6
- @file = File.join(File.dirname(__FILE__), 'testqueue.tmp')
7
- File.delete(@file) if File.exists?(@file)
8
- @todo = Qer::ToDo.new(@file)
6
+ queue = File.join(File.dirname(__FILE__), 'testqueue.tmp')
7
+ File.delete(queue) if File.exists?(queue)
8
+
9
+ @config = File.join(File.dirname(__FILE__), 'config')
10
+ @todo = Qer::ToDo.new(@config)
9
11
  end
10
12
 
11
13
  context "push" do
@@ -14,12 +16,12 @@ class TestQer < Test::Unit::TestCase
14
16
  end
15
17
 
16
18
  should "have one item" do
17
- assert_equal 1, @todo.size
19
+ assert_equal 1, @todo.queue.size
18
20
  end
19
21
 
20
22
  should "have two items" do
21
23
  @todo.push("Some Other Task")
22
- assert_equal 2, @todo.size
24
+ assert_equal 2, @todo.queue.size
23
25
  end
24
26
  end
25
27
 
@@ -35,7 +37,7 @@ class TestQer < Test::Unit::TestCase
35
37
  end
36
38
 
37
39
  should "have one item" do
38
- assert_equal 1, @todo.size
40
+ assert_equal 1, @todo.queue.size
39
41
  end
40
42
  end
41
43
 
@@ -45,12 +47,12 @@ class TestQer < Test::Unit::TestCase
45
47
  end
46
48
 
47
49
  should "have one item" do
48
- assert_equal 1, @todo.size
50
+ assert_equal 1, @todo.queue.size
49
51
  end
50
52
 
51
53
  should "have two items" do
52
54
  @todo.add("Some Other Task")
53
- assert_equal 2, @todo.size
55
+ assert_equal 2, @todo.queue.size
54
56
  end
55
57
  end
56
58
 
@@ -66,7 +68,7 @@ class TestQer < Test::Unit::TestCase
66
68
  end
67
69
 
68
70
  should "have one item" do
69
- assert_equal 1, @todo.size
71
+ assert_equal 1, @todo.queue.size
70
72
  end
71
73
 
72
74
  should "not error out when an invalid index is removed" do
@@ -84,7 +86,7 @@ class TestQer < Test::Unit::TestCase
84
86
  end
85
87
 
86
88
  should "have no items" do
87
- assert_equal 0, @todo.size
89
+ assert_equal 0, @todo.queue.size
88
90
  end
89
91
  end
90
92
 
@@ -100,7 +102,7 @@ class TestQer < Test::Unit::TestCase
100
102
  end
101
103
 
102
104
  should "have one item" do
103
- assert_equal 1, @todo.size
105
+ assert_equal 1, @todo.queue.size
104
106
  end
105
107
  end
106
108
 
@@ -130,12 +132,12 @@ class TestQer < Test::Unit::TestCase
130
132
 
131
133
  context "read" do
132
134
  setup do
133
- @file = File.join(File.dirname(__FILE__), 'test_queue')
134
- @todo = Qer::ToDo.new(@file)
135
+ config = File.join(File.dirname(__FILE__), 'static-config')
136
+ @todo = Qer::ToDo.new(config)
135
137
  end
136
138
 
137
139
  should "have 5 items" do
138
- assert_equal 5, @todo.size
140
+ assert_equal 5, @todo.queue.size
139
141
  end
140
142
  end
141
143
 
@@ -143,11 +145,10 @@ class TestQer < Test::Unit::TestCase
143
145
  setup do
144
146
  @todo.add("Some Task")
145
147
  @todo.add("Some Other Task")
146
- @other_todo = Qer::ToDo.new(@file)
147
148
  end
148
149
 
149
150
  should "have 2 items" do
150
- assert_equal 2, @todo.size
151
+ assert_equal 2, @todo.queue.size
151
152
  end
152
153
  end
153
154
 
@@ -167,13 +168,13 @@ class TestQer < Test::Unit::TestCase
167
168
 
168
169
  should "add" do
169
170
  @todo.command(%w(add some stuff))
170
- assert_equal 2, @todo.size
171
+ assert_equal 2, @todo.queue.size
171
172
  assert_output(/Adding: some stuff/)
172
173
  end
173
174
 
174
175
  should "remove" do
175
176
  assert_equal "Some Task", @todo.command(%w(remove 0)).last
176
- assert_equal 0, @todo.size
177
+ assert_equal 0, @todo.queue.size
177
178
  assert_output "Removed: Some Task"
178
179
  end
179
180
 
@@ -184,31 +185,31 @@ class TestQer < Test::Unit::TestCase
184
185
 
185
186
  should "push" do
186
187
  @todo.command(%w(push some stuff))
187
- assert_equal 2, @todo.size
188
+ assert_equal 2, @todo.queue.size
188
189
  assert_output "Pushed to the top: some stuff"
189
190
  end
190
191
 
191
192
  should "pop" do
192
193
  assert_equal "Some Task", @todo.command(%w(pop)).last
193
- assert_equal 0, @todo.size
194
+ assert_equal 0, @todo.queue.size
194
195
  assert_output "Removed: Some Task"
195
196
  end
196
197
 
197
198
  should "clear" do
198
199
  @todo.command(%w(clear))
199
- assert_equal 0, @todo.size
200
+ assert_equal 0, @todo.queue.size
200
201
  assert_output(/list cleared/)
201
202
  end
202
203
 
203
204
  should "help" do
204
205
  @todo.command(%w(help))
205
- assert_equal 1, @todo.size
206
+ assert_equal 1, @todo.queue.size
206
207
  assert_output(/Help for Qer/)
207
208
  end
208
209
 
209
210
  should "print" do
210
211
  @todo.command([])
211
- assert_equal 1, @todo.size
212
+ assert_equal 1, @todo.queue.size
212
213
  assert_output "Stuff on the Hopper"
213
214
  end
214
215
 
@@ -289,4 +290,24 @@ class TestQer < Test::Unit::TestCase
289
290
  assert_equal @todo.width, @todo.hl.size
290
291
  end
291
292
  end
293
+
294
+ context "config" do
295
+ should "set #filename" do
296
+ with_config('queue_file' => 'foo') do |todo|
297
+ assert_equal File.expand_path('foo'), todo.filename
298
+ end
299
+ end
300
+
301
+ should "set #width" do
302
+ with_config('page_width' => 120) do |todo|
303
+ assert_equal 120, todo.width
304
+ end
305
+ end
306
+
307
+ should "set #history_limit" do
308
+ with_config('history_limit' => 40) do |todo|
309
+ assert_equal 40, todo.history_limit
310
+ end
311
+ end
312
+ end
292
313
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Kleinpeter
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2010-03-22 00:00:00 -07:00
14
+ date: 2010-05-18 00:00:00 -07:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
@@ -32,7 +32,7 @@ dependencies:
32
32
  requirements:
33
33
  - - ">="
34
34
  - !ruby/object:Gem::Version
35
- version: 2.3.3
35
+ version: 2.5.0
36
36
  version:
37
37
  description: Qer is an easy command-line todo list.
38
38
  email: