todo_list 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTU2MmM1NWQ2Njg0YzhiNTk4MzhhNTNkOTM4Njk5YzAxOTk1YTBjZQ==
5
+ data.tar.gz: !binary |-
6
+ ODFmMjQyNDE4YjA3MjVkOGMyM2QzYjY3YWYxMmY1OGI5OGNhZDU5OQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MGQyZWQ1MWIxOTk3N2RmMDRiMzEzNGQ2NjdlNDVkM2YwZDA1MDhkMGVkNTY3
10
+ YjNlYTA4ODdhZDJiMWJiNDc3MzU2NzA4NTQwM2U5OTdkNTIzNDRiYmJlOTEz
11
+ YWNmNGU3OGI2MWQxZTUzMDg5NDliYjBmM2EwYmIzYjRmMDM0NjI=
12
+ data.tar.gz: !binary |-
13
+ MzM1YzQ1MjA3ZTU0ZTZjNWNlOTQyNTI1MWI2NTBjNDViNzI0NmRiNmEyMGQ0
14
+ NGFiNWUxMWFjMmI1MDMzOThiMGU5OGJkNzNiN2IwNTdmYzZkZDZjZGFhYzYx
15
+ MjEyM2EyNGI2ZTdmY2E5NDgyOWRjZGYzNjVhNzA1NTU0ZjY3ZGU=
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
19
+ todo.sav
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in todo_list.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jerome Dalbert
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # TodoList
2
+
3
+ Basic command-line todo-list :
4
+
5
+ - list, add, edit and remove tasks
6
+ - *done* tasks remain displayed (more rewarding) until you clean them
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'todo_list'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install todo_list
21
+
22
+ ## Usage
23
+
24
+ TODO: Write usage instructions here
25
+
26
+ ## Contributing
27
+
28
+ 1. Fork it
29
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
30
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
31
+ 4. Push to the branch (`git push origin my-new-feature`)
32
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/todo ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/todo_list'
3
+
4
+ TodoList::CommandLineInterface.new.run
5
+
6
+
data/lib/todo_list.rb ADDED
@@ -0,0 +1,10 @@
1
+ require_relative "todo_list/version"
2
+ require_relative "todo_list/command_line_interface"
3
+ require_relative "todo_list/task_list"
4
+ require_relative "todo_list/task"
5
+ require_relative "todo_list/core_ext/string"
6
+
7
+ module TodoList
8
+ ROOT_PATH = File.expand_path('../', File.dirname(__FILE__))
9
+ SAVE_PATH = File.join(ROOT_PATH, '/todo.sav')
10
+ end
@@ -0,0 +1,154 @@
1
+ require 'rb-readline'
2
+
3
+ module TodoList
4
+ class CommandLineInterface
5
+
6
+ def run
7
+ command = ARGV[0]
8
+ command ||= "print_list"
9
+
10
+ if respond_to?(command)
11
+ execute(command)
12
+ else
13
+ print_command_error(%(Unknown command #{bold(command)}.))
14
+ end
15
+ end
16
+
17
+ def add
18
+ description = ARGV[1..-1].join(" ")
19
+
20
+ @task_list << Task.new(description) unless description.empty?
21
+
22
+ print_list
23
+ end
24
+
25
+ def edit
26
+ task = get_todo_tasks[get_task_index]
27
+
28
+ if ARGV.size > 2
29
+ task.description = ARGV[2..-1].join(" ")
30
+ else
31
+ RbReadline.prefill_prompt(task.description)
32
+ task.description = Readline.readline("Edit description: ")
33
+ end
34
+
35
+ print_list
36
+ end
37
+
38
+ def done
39
+ get_todo_tasks[get_task_index].done = true
40
+
41
+ print_list
42
+ end
43
+
44
+ def remove
45
+ @task_list.delete(get_todo_tasks[get_task_index])
46
+
47
+ print_list
48
+ end
49
+
50
+ def clean
51
+ @task_list = TaskList.new(get_todo_tasks)
52
+
53
+ print_list
54
+ end
55
+
56
+ def wipe
57
+ @task_list = TaskList.new
58
+
59
+ print_list
60
+ end
61
+
62
+ def print_list
63
+ if @task_list.empty?
64
+ puts %(Nothing to do !\n\nType "help" command for more information.)
65
+ return
66
+ end
67
+
68
+ unless get_todo_tasks.empty?
69
+ puts "[TODO]"
70
+ get_todo_tasks.each_with_index do |e, i|
71
+ puts "#{i + 1} - #{e.description.capitalize}"
72
+ end
73
+ puts unless get_done_tasks.empty?
74
+ end
75
+
76
+ unless get_done_tasks.empty?
77
+ puts "[DONE]"
78
+ get_done_tasks.each do |e|
79
+ puts "- #{e.description.capitalize}"
80
+ end
81
+ end
82
+ end
83
+
84
+ def print_help
85
+ puts <<-ENDTEXT
86
+ Available commands :
87
+ help
88
+ add #{underline("task_description")}
89
+ edit #{underline("task_number")} [#{underline("new_description")}]
90
+ done #{underline("task_number")}
91
+ remove #{underline("task_number")}
92
+ clean
93
+ wipe
94
+ ENDTEXT
95
+ end
96
+
97
+ alias_method :help, :print_help
98
+
99
+ private
100
+
101
+ def execute(command)
102
+ @task_list = TaskList.load(SAVE_PATH)
103
+
104
+ send(command)
105
+
106
+ @task_list.save(SAVE_PATH)
107
+ end
108
+
109
+ def get_done_tasks
110
+ @task_list.select { |e| e.done? }
111
+ end
112
+
113
+ def get_todo_tasks
114
+ @task_list.select { |e| !e.done? }
115
+ end
116
+
117
+ def print_command_error(error_message)
118
+ print("#{error_message}\n\n")
119
+
120
+ print_help
121
+ end
122
+
123
+ def underline(string)
124
+ "\033[4m#{string}\033[0m"
125
+ end
126
+
127
+ def bold(string)
128
+ "\033[1m#{string}\033[0m"
129
+ end
130
+
131
+ def get_task_index
132
+ task_index = ARGV[1].to_i - 1
133
+
134
+ unless task_index.between?(0, get_todo_tasks.size - 1)
135
+ puts "Please type a valid task number."
136
+ exit
137
+ end
138
+
139
+ task_index
140
+ end
141
+ end
142
+ end
143
+
144
+ module RbReadline
145
+ def self.prefill_prompt(str)
146
+ @rl_prefill = str
147
+ @rl_startup_hook = :rl_prefill_hook
148
+ end
149
+
150
+ def self.rl_prefill_hook
151
+ rl_insert_text @rl_prefill if @rl_prefill
152
+ @rl_startup_hook = nil
153
+ end
154
+ end
@@ -0,0 +1,7 @@
1
+ class String
2
+
3
+ def to_b
4
+ self == "true"
5
+ end
6
+
7
+ end
@@ -0,0 +1,13 @@
1
+ module TodoList
2
+ class Task
3
+
4
+ attr_accessor :description, :done
5
+ alias_method :done?, :done
6
+
7
+ def initialize(description, done = false)
8
+ self.description = description
9
+ self.done = done
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ module TodoList
2
+ class TaskList < Array
3
+
4
+ SEPARATOR = " _;_ "
5
+
6
+ def self.load(file_name)
7
+ todolist = TaskList.new
8
+
9
+ if File.exists?(file_name)
10
+ File.foreach(file_name) do |line|
11
+ description, done = line.chomp.split(SEPARATOR)
12
+
13
+ todolist << Task.new(description, done.to_b)
14
+ end
15
+ end
16
+
17
+ todolist
18
+ end
19
+
20
+ def save(file_name)
21
+ File.open(file_name, "w") do |file|
22
+ self.each { |e| file.puts("#{e.description}#{SEPARATOR}#{e.done?}") }
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module TodoList
2
+ VERSION = "0.1.1"
3
+ end
data/todo_list.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'todo_list/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "todo_list"
8
+ spec.version = TodoList::VERSION
9
+ spec.authors = ["Jerome Dalbert"]
10
+ spec.email = ["jerome.dalbert@gmail.com"]
11
+ spec.description = %q{Basic command-line todo-list}
12
+ spec.summary = %q{List, add, edit and remove tasks. Done tasks remain displayed (more rewarding) until you clean them.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency "rb-readline"
24
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: todo_list
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Jerome Dalbert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rb-readline
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Basic command-line todo-list
56
+ email:
57
+ - jerome.dalbert@gmail.com
58
+ executables:
59
+ - todo
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - bin/todo
69
+ - lib/todo_list.rb
70
+ - lib/todo_list/command_line_interface.rb
71
+ - lib/todo_list/core_ext/string.rb
72
+ - lib/todo_list/task.rb
73
+ - lib/todo_list/task_list.rb
74
+ - lib/todo_list/version.rb
75
+ - todo_list.gemspec
76
+ homepage: ''
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.0.3
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: List, add, edit and remove tasks. Done tasks remain displayed (more rewarding)
100
+ until you clean them.
101
+ test_files: []