todorb 0.2.0 → 0.2.1

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.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/todorb.rb +32 -17
  3. metadata +4 -15
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
data/lib/todorb.rb CHANGED
@@ -37,7 +37,9 @@ class Todo
37
37
  def init_vars
38
38
  @todo_default_action = "list"
39
39
  @todo_file_path = @options[:file] || "TODO2.txt"
40
- @archive_path = "archive.txt" # should take path of todo and put there TODO:
40
+ #@todo_serial_path = File.expand_path("~/serial_numbers")
41
+ @todo_serial_path = "serial_numbers"
42
+ @archive_path = "todo_archive.txt" # should take path of todo and put there TODO:
41
43
  @todo_delim = "\t"
42
44
  @appname = File.basename( Dir.getwd ) #+ ".#{$0}"
43
45
  t = Time.now
@@ -90,22 +92,22 @@ class Todo
90
92
  if text.empty?
91
93
  exit 1
92
94
  end
93
- Kernel.print("You gave me '#{text}'")
95
+ Kernel.print("You gave me '#{text}'") if @verbose
94
96
  else
95
97
  text = args.join " "
96
- Kernel.print("I got '#{text}'")
98
+ Kernel.print("I got '#{text}'") if @verbose
97
99
  end
98
100
  # convert actual newline to C-a. slash n's are escapes so echo -e does not muck up.
99
101
  text.tr! "\n", ''
100
- Kernel.print("Got '#{text}'\n")
102
+ Kernel.print("Got '#{text}'\n") if @verbose
101
103
  item = _get_serial_number
102
104
  paditem = _paditem(item)
103
- print "item no is:#{paditem}:\n"
105
+ print "item no is:#{paditem}:\n" if @verbose
104
106
  priority = @options[:priority] ? " (#{@options[:priority]})" : ""
105
107
  project = @options[:project] ? " +#{@options[:project]}" : ""
106
108
  component = @options[:component] ? " @#{@options[:component]}" : ""
107
109
  newtext="#{paditem}#{@todo_delim}[ ]#{priority}#{project}#{component} #{text} (#{@today})"
108
- puts "Adding"
110
+ puts "Adding:"
109
111
  puts newtext
110
112
  File.open(@todo_file_path, "a") { | file| file.puts newtext }
111
113
 
@@ -116,13 +118,15 @@ class Todo
116
118
  def _get_serial_number
117
119
  require 'fileutils'
118
120
  appname = @appname
119
- filename = "/Users/rahul/serial_numbers"
121
+ filename = @todo_serial_path
120
122
  h = {}
121
- File.open(filename).each { |line|
122
- #sn = $1 if line.match regex
123
- x = line.split ":"
124
- h[x[0]] = x[1].chomp
125
- }
123
+ if File.exists?(filename)
124
+ File.open(filename).each { |line|
125
+ #sn = $1 if line.match regex
126
+ x = line.split ":"
127
+ h[x[0]] = x[1].chomp
128
+ }
129
+ end
126
130
  sn = h[appname] || 1
127
131
  # update the sn in file
128
132
  nsn = sn.to_i + 1
@@ -139,7 +143,7 @@ class Todo
139
143
  def _set_serial_number number
140
144
  appname = @appname
141
145
  pattern = Regexp.new "^#{appname}:.*$"
142
- filename = "/Users/rahul/serial_numbers"
146
+ filename = @todo_serial_path
143
147
  _backup filename
144
148
  change_row filename, pattern, "#{appname}:#{number}"
145
149
  end
@@ -147,6 +151,13 @@ class Todo
147
151
  require 'fileutils'
148
152
  FileUtils.cp filename, "#{filename}.org"
149
153
  end
154
+ def check_file filename=@todo_file_path
155
+ File.exists?(filename) or die "#{filename} does not exist in this dir. Use 'add' to create an item first."
156
+ end
157
+ def die text
158
+ $stderr.puts text
159
+ exit 1
160
+ end
150
161
  ##
151
162
  # for historical reasons, I pad item to 3 spaces in text file.
152
163
  # It used to help me in printing straight off without any formatting in unix shell
@@ -154,6 +165,7 @@ class Todo
154
165
  return sprintf("%3s", item)
155
166
  end
156
167
  def populate
168
+ check_file
157
169
  @ctr = 0
158
170
  @total = 0
159
171
  #CSV.foreach(@file,:col_sep => "\t") do |row| # 1.9 2009-10-05 11:12
@@ -431,7 +443,8 @@ class Todo
431
443
  print_red "Status #{stat} is invalid!"
432
444
  exit 1
433
445
  end
434
- change_items(items, /(\[.\])/, "[#{newstatus}]")
446
+ ctr = change_items(items, /(\[.\])/, "[#{newstatus}]")
447
+ puts "Changed status of #{ctr} items"
435
448
  #change_items items do |item, line|
436
449
  #puts line if @verbose
437
450
  #line.sub!(/(\[.\])/, "[#{newstatus}]")
@@ -518,18 +531,21 @@ class Todo
518
531
  # yields lines from file that match the given item
519
532
  # We do not need to now parse and match the item in each method
520
533
  def change_items args, pattern=nil, replacement=nil
534
+ changed_ctr = 0
521
535
  change_file @todo_file_path do |line|
522
536
  item = line.match(/^ *([0-9]+)/)
523
537
  if args.include? item[1]
524
538
  if pattern
525
539
  puts line if @verbose
526
- line.sub!(pattern, replacement)
540
+ ret = line.sub!(pattern, replacement)
541
+ changed_ctr += 1 if ret
527
542
  print_red line if @verbose
528
543
  else
529
544
  yield item[1], line
530
545
  end
531
546
  end
532
547
  end
548
+ return changed_ctr
533
549
  end
534
550
  ##
535
551
  # Redoes the numbering in the file.
@@ -577,7 +593,7 @@ class Todo
577
593
  when "H","hold"
578
594
  status="hold"
579
595
  newstatus = "H"
580
- when "u","uns","unst","unstart","unstarted"
596
+ when "u","uns","unst","unstart","unstarted","open"
581
597
  status="unstarted"
582
598
  newstatus = " "
583
599
  end
@@ -679,7 +695,6 @@ class Todo
679
695
  end
680
696
  end.parse!(args)
681
697
 
682
- #options[:file] ||= "rbcurse/TODO2.txt"
683
698
  options[:file] ||= "TODO2.txt"
684
699
  if options[:verbose]
685
700
  p options
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Rahul Kumar
@@ -16,19 +16,8 @@ cert_chain: []
16
16
 
17
17
  date: 2010-06-14 00:00:00 +05:30
18
18
  default_executable: todorb
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: thoughtbot-shoulda
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- version: "0"
30
- type: :development
31
- version_requirements: *id001
19
+ dependencies: []
20
+
32
21
  description: "command-line program that manages a todo list text file "
33
22
  email: sentinel1879@gmail.com
34
23
  executables: