ptm 0.1.0.a
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/.rubocop.yml +74 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +25 -0
- data/README.md +69 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/ptm +4 -0
- data/lib/ptm.rb +15 -0
- data/lib/ptm/cli.rb +81 -0
- data/lib/ptm/completed_task.rb +27 -0
- data/lib/ptm/decorator_helper.rb +50 -0
- data/lib/ptm/file_helper.rb +67 -0
- data/lib/ptm/pending_task.rb +27 -0
- data/lib/ptm/task.rb +90 -0
- data/lib/ptm/task_decorato.rb +4 -0
- data/lib/ptm/tasks.yml.sample +11 -0
- data/lib/ptm/version.rb +4 -0
- data/ptm.gemspec +42 -0
- data/test.rb +3 -0
- metadata +186 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0721b22df34781a15f4d7b7ef1394240f6ed03cf
|
4
|
+
data.tar.gz: 3aad2975e28e610d1e5d160d9462abb789f4ccee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 817239c5ce046d4f9e9d44c00d4abaa582fa1ef72e437447493ac280a94291bc3f56e2290def81ff5796062f756c0fd89901aef2ef0651b9badbea0a84055eef
|
7
|
+
data.tar.gz: 8d88f40cd3d7cc08df99127ee5f5883af49e23a7863e86951f90b45a94adbdfe215e1c60c10f467f5d9cd815ce17e3ac449ba16b760bee10c36b6f89d4c8676c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.4
|
3
|
+
Exclude:
|
4
|
+
# Autogenerated binstubs should not be subject to style guide.
|
5
|
+
- "bin/**/*"
|
6
|
+
- "vendor/ruby/**/*"
|
7
|
+
- "tmp/**/*"
|
8
|
+
- "ptm.gemspec"
|
9
|
+
|
10
|
+
# Certain folders do not class-level comments
|
11
|
+
Documentation:
|
12
|
+
Exclude:
|
13
|
+
- "spec/**/*"
|
14
|
+
|
15
|
+
Metrics/AbcSize:
|
16
|
+
Exclude:
|
17
|
+
- "ptm.gemspec"
|
18
|
+
Metrics/BlockLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Metrics/ClassLength:
|
22
|
+
Max: 120
|
23
|
+
Exclude:
|
24
|
+
- "ptm.gemspec"
|
25
|
+
Metrics/LineLength:
|
26
|
+
Max: 80
|
27
|
+
Exclude:
|
28
|
+
- "ptm.gemspec"
|
29
|
+
|
30
|
+
# The ABC metrics, like `AbcSize` are more useful than the line-counting
|
31
|
+
# metrics. There should be *some* upper limit on lines per-method, but the
|
32
|
+
# default, 10, is not practical.
|
33
|
+
Metrics/MethodLength:
|
34
|
+
Max: 30
|
35
|
+
Exclude:
|
36
|
+
- "ptm.gemspec"
|
37
|
+
# The default ModuleLength (and ClassLength) of 100 is satisfactory for
|
38
|
+
# production code, but is not a useful number for tests, which are often
|
39
|
+
# longer than the code they test.
|
40
|
+
Metrics/ModuleLength:
|
41
|
+
Exclude:
|
42
|
+
- "test/**/*"
|
43
|
+
- "ptm.gemspec"
|
44
|
+
# The fixed indentation style is rational. To align with the first parameters
|
45
|
+
# is arguably friendly, but makes for long lines and obscures control flow.
|
46
|
+
Style/AlignParameters:
|
47
|
+
EnforcedStyle: with_fixed_indentation
|
48
|
+
|
49
|
+
# Both the leading and trailing styles can be argued for. RPL Team has
|
50
|
+
# chosen the trailing style.
|
51
|
+
Style/DotPosition:
|
52
|
+
EnforcedStyle: trailing
|
53
|
+
|
54
|
+
# I prefer conditionals to mid-method `return` calls, which this cop encourages.
|
55
|
+
Style/GuardClause:
|
56
|
+
Enabled: false
|
57
|
+
|
58
|
+
# The "modifier style" conditional (aka. trailing conditional) should only
|
59
|
+
# be used on *very* short lines, otherwise it is hard to see at a glance.
|
60
|
+
Style/IfUnlessModifier:
|
61
|
+
MaxLineLength: 60
|
62
|
+
|
63
|
+
Style/MultilineMethodCallIndentation:
|
64
|
+
EnforcedStyle: indented
|
65
|
+
|
66
|
+
Style/MultilineOperationIndentation:
|
67
|
+
EnforcedStyle: indented
|
68
|
+
|
69
|
+
# This cop doesn't work correctly when snake_case variable names end in a number
|
70
|
+
Style/VariableNumber:
|
71
|
+
Enabled: false
|
72
|
+
|
73
|
+
Style/FrozenStringLiteralComment:
|
74
|
+
Enabled: false
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.0
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at hasanuzzaman.sumon@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# personal task manager
|
2
|
+
This is simple commandline application using thor that I intend to using for managing my personal task.
|
3
|
+
|
4
|
+
## License
|
5
|
+
The MIT License (MIT)
|
6
|
+
|
7
|
+
Copyright (c) 2017 engr-hasanuzzaman
|
8
|
+
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
11
|
+
in the Software without restriction, including without limitation the rights
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
14
|
+
furnished to do so, subject to the following conditions:
|
15
|
+
|
16
|
+
The above copyright notice and this permission notice shall be included in
|
17
|
+
all copies or substantial portions of the Software.
|
18
|
+
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
25
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Ptm
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ptm`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ptm'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ptm
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
### show all task list
|
25
|
+
`ptm list`
|
26
|
+
|
27
|
+
### add new task
|
28
|
+
add new task with default 'default' category
|
29
|
+
`ptm add_task 'this is test title'`
|
30
|
+
|
31
|
+
add new task with under 'test_category' category
|
32
|
+
`ptm add_task 'this is test title' -c='test_category'`
|
33
|
+
|
34
|
+
### remove all tasks
|
35
|
+
`ptm remove_tasks`
|
36
|
+
|
37
|
+
### remove task by provide id
|
38
|
+
`ptm remove_tasks --id=1` # this id has been uesed during show list
|
39
|
+
|
40
|
+
|
41
|
+
## Development
|
42
|
+
|
43
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
44
|
+
|
45
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
46
|
+
|
47
|
+
## Contributing
|
48
|
+
|
49
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ptm. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
50
|
+
|
51
|
+
|
52
|
+
## License
|
53
|
+
|
54
|
+
Copyright (C) 2017 Hasanuzzaman Sumon
|
55
|
+
|
56
|
+
This program is free software; you can redistribute it and/or modify
|
57
|
+
it under the terms of the GNU General Public License as published by
|
58
|
+
the Free Software Foundation; either version 2 of the License, or
|
59
|
+
(at your option) any later version.
|
60
|
+
|
61
|
+
This program is distributed in the hope that it will be useful,
|
62
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
63
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
64
|
+
GNU General Public License for more details.
|
65
|
+
|
66
|
+
You should have received a copy of the GNU General Public License along
|
67
|
+
with this program; if not, write to the Free Software Foundation, Inc.,
|
68
|
+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
69
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'ptm'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/ptm
ADDED
data/lib/ptm.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'rainbow/ext/string'
|
3
|
+
require 'ptm/decorator_helper'
|
4
|
+
require 'ptm/task'
|
5
|
+
require 'ptm/task_decorato'
|
6
|
+
require 'ptm/completed_task'
|
7
|
+
require 'ptm/pending_task'
|
8
|
+
require 'ptm/version'
|
9
|
+
require 'ptm/file_helper'
|
10
|
+
require 'ptm/cli'
|
11
|
+
|
12
|
+
# top level module
|
13
|
+
module Ptm
|
14
|
+
# Your code goes here...
|
15
|
+
end
|
data/lib/ptm/cli.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
# wrapper module
|
4
|
+
module Ptm
|
5
|
+
# thor command container class
|
6
|
+
class Command < Thor
|
7
|
+
desc 'list', 'This will show all of your tasks'
|
8
|
+
def list
|
9
|
+
print_table(table(Task.load_tasks))
|
10
|
+
end
|
11
|
+
map :'-l' => :list
|
12
|
+
|
13
|
+
desc 'add_task TITLE', 'add new task with given title.'
|
14
|
+
method_option :category, aliases: '-c', type: :string, default: 'general'
|
15
|
+
method_option :completed_status, aliases: '-s', type: :boolean, default: false
|
16
|
+
def add_task(title)
|
17
|
+
task = {}
|
18
|
+
task[:title] = title
|
19
|
+
task[:category] = options[:category]
|
20
|
+
task[:created_at] = Time.now
|
21
|
+
task[:completed_at] = Time.now if options[:completed_status]
|
22
|
+
task[:complete] = options[:completed_status]
|
23
|
+
|
24
|
+
# check valid task data
|
25
|
+
return unless Task.valid_task?(task)
|
26
|
+
FileHelper.append_to_file(FileHelper::YML_PATH, task)
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'remove_tasks', 'remove task with given id.'
|
30
|
+
method_option :id, aliases: 'i', type: :numeric, default: 0
|
31
|
+
def remove_tasks
|
32
|
+
if options[:id].zero?
|
33
|
+
Task.remove_all_tasks
|
34
|
+
else
|
35
|
+
Task.remove_task(options[:id])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
desc 'complete_tasks', 'make task complete for given task id'
|
40
|
+
method_option :id, aliases: 'i', type: :numeric, default: 0
|
41
|
+
def complete_tasks
|
42
|
+
if options[:id].zero?
|
43
|
+
Task.complete_all_tasks
|
44
|
+
else
|
45
|
+
Task.complete_task(options[:id])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# this will not be treated as command
|
50
|
+
no_commands do
|
51
|
+
# create table from data
|
52
|
+
def table(tasks)
|
53
|
+
table = []
|
54
|
+
table_header = [
|
55
|
+
header_col('Id'),
|
56
|
+
header_col('title'),
|
57
|
+
header_col('category'),
|
58
|
+
header_col('created at'),
|
59
|
+
header_col('complete'),
|
60
|
+
header_col('completed at')
|
61
|
+
]
|
62
|
+
table << table_header
|
63
|
+
|
64
|
+
tasks.each do |task|
|
65
|
+
decorated_task = if task.complete
|
66
|
+
CompletedTask.new(task)
|
67
|
+
else
|
68
|
+
PendingTask.new(task)
|
69
|
+
end
|
70
|
+
table << decorated_task.attrs_val
|
71
|
+
end
|
72
|
+
|
73
|
+
table
|
74
|
+
end
|
75
|
+
|
76
|
+
def header_col(val)
|
77
|
+
val.color(:white)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# decorator class
|
2
|
+
module Ptm
|
3
|
+
class CompletedTask < TaskDecorator
|
4
|
+
#
|
5
|
+
# include
|
6
|
+
#
|
7
|
+
|
8
|
+
include DecoratorHelper
|
9
|
+
|
10
|
+
#
|
11
|
+
# instance method
|
12
|
+
#
|
13
|
+
|
14
|
+
def font_color
|
15
|
+
:cyan
|
16
|
+
end
|
17
|
+
|
18
|
+
def bg_color
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def underline?
|
23
|
+
false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Ptm
|
2
|
+
# help to decorate task decorator
|
3
|
+
module DecoratorHelper
|
4
|
+
def title
|
5
|
+
apply_color(super.to_s)
|
6
|
+
end
|
7
|
+
|
8
|
+
def category
|
9
|
+
apply_color(super.to_s)
|
10
|
+
end
|
11
|
+
|
12
|
+
def created_at
|
13
|
+
apply_color(super.to_s)
|
14
|
+
end
|
15
|
+
|
16
|
+
def complete
|
17
|
+
apply_color(super.to_s)
|
18
|
+
end
|
19
|
+
|
20
|
+
def completed_at
|
21
|
+
apply_color(super.to_s)
|
22
|
+
end
|
23
|
+
|
24
|
+
def id
|
25
|
+
apply_color(super.to_s)
|
26
|
+
end
|
27
|
+
|
28
|
+
def attrs_val
|
29
|
+
[
|
30
|
+
id,
|
31
|
+
title,
|
32
|
+
category,
|
33
|
+
created_at,
|
34
|
+
complete,
|
35
|
+
completed_at
|
36
|
+
]
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def apply_color(temp_val)
|
42
|
+
temp_val = temp_val.color(font_color) if font_color
|
43
|
+
temp_val = temp_val.background(bg_color) if bg_color
|
44
|
+
temp_val = temp_val.underline if underline?
|
45
|
+
|
46
|
+
# make sure return title
|
47
|
+
temp_val
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Ptm
|
4
|
+
module FileHelper
|
5
|
+
YML_PATH = File.expand_path('../tasks.yml', __FILE__).freeze
|
6
|
+
SAMPLE_YML_PATH = File.expand_path('../tasks.yml.sample', __FILE__).freeze
|
7
|
+
|
8
|
+
#
|
9
|
+
# module methods
|
10
|
+
#
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def read_yml(file_path)
|
14
|
+
unless valid_yml?(file_path)
|
15
|
+
create_task_file
|
16
|
+
end
|
17
|
+
|
18
|
+
YAML.load(File.read(file_path)) || []
|
19
|
+
end
|
20
|
+
|
21
|
+
def append_to_file(file_path, data)
|
22
|
+
# make sure tasks.yml exist
|
23
|
+
# create new if one does not exist
|
24
|
+
unless valid_yml?(file_path)
|
25
|
+
create_new_file(file_path)
|
26
|
+
end
|
27
|
+
new_data = read_yml(file_path) || []
|
28
|
+
new_data << data
|
29
|
+
write_to_file(file_path, new_data.to_yaml)
|
30
|
+
end
|
31
|
+
|
32
|
+
def valid_yml?(path)
|
33
|
+
File.file?(path) && File.extname(path) == '.yml'
|
34
|
+
end
|
35
|
+
|
36
|
+
def valid_sample?(path)
|
37
|
+
File.file?(path) && File.extname(path) == '.sample'
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# private methods
|
42
|
+
#
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def create_task_file
|
47
|
+
if valid_sample?(SAMPLE_YML_PATH)
|
48
|
+
copy_task_file_from_sample(SAMPLE_YML_PATH, YML_PATH)
|
49
|
+
else
|
50
|
+
create_new_file(YML_PATH)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def copy_task_file_from_sample(s_file, d_file)
|
55
|
+
FileUtils.cp(s_file, d_file)
|
56
|
+
end
|
57
|
+
|
58
|
+
def create_new_file(path)
|
59
|
+
File.open(path, 'w')
|
60
|
+
end
|
61
|
+
|
62
|
+
def write_to_file(file_path, data)
|
63
|
+
File.write(file_path, data)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# decorator class
|
2
|
+
module Ptm
|
3
|
+
class PendingTask < TaskDecorator
|
4
|
+
#
|
5
|
+
# include
|
6
|
+
#
|
7
|
+
|
8
|
+
include DecoratorHelper
|
9
|
+
|
10
|
+
#
|
11
|
+
# instance method
|
12
|
+
#
|
13
|
+
|
14
|
+
def font_color
|
15
|
+
:yellow
|
16
|
+
end
|
17
|
+
|
18
|
+
def bg_color
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def underline?
|
23
|
+
false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
data/lib/ptm/task.rb
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
module Ptm
|
2
|
+
class Task
|
3
|
+
# class obj that will use to generate obj id
|
4
|
+
@@obj_id = 1
|
5
|
+
|
6
|
+
# accessor methods
|
7
|
+
attr_accessor :title, :id, :category, :created_at, :complete, :completed_at
|
8
|
+
|
9
|
+
def initialize(attrs)
|
10
|
+
return unless attrs.is_a?(Hash)
|
11
|
+
|
12
|
+
self.title = attrs[:title]
|
13
|
+
self.category = attrs[:category]
|
14
|
+
self.created_at = attrs[:created_at]
|
15
|
+
self.complete = attrs[:complete]
|
16
|
+
self.completed_at = attrs[:completed_at]
|
17
|
+
self.id = @@obj_id
|
18
|
+
|
19
|
+
# increment class variable for next obj
|
20
|
+
@@obj_id += 1
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_hash
|
24
|
+
hash = {}
|
25
|
+
instance_variables.each do |var|
|
26
|
+
key = var.to_s.delete('@').to_sym
|
27
|
+
hash[key] = instance_variable_get(var) unless key == :id # skip id
|
28
|
+
end
|
29
|
+
|
30
|
+
hash
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# class methods
|
35
|
+
#
|
36
|
+
|
37
|
+
class << self
|
38
|
+
# load task data from YAML file &
|
39
|
+
# make task object
|
40
|
+
def load_tasks
|
41
|
+
FileHelper.read_yml(FileHelper::YML_PATH).map do |task_attrs|
|
42
|
+
Ptm::Task.new(task_attrs)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def remove_task(id)
|
47
|
+
tasks = load_tasks
|
48
|
+
tasks.reject! { |task| task.id == id }
|
49
|
+
new_data = tasks_hash(tasks)
|
50
|
+
FileHelper.write_to_file(FileHelper::YML_PATH, new_data.to_yaml)
|
51
|
+
end
|
52
|
+
|
53
|
+
def remove_all_tasks
|
54
|
+
new_data = []
|
55
|
+
FileHelper.write_to_file(FileHelper::YML_PATH, new_data.to_yaml)
|
56
|
+
end
|
57
|
+
|
58
|
+
def complete_all_tasks
|
59
|
+
tasks = load_tasks
|
60
|
+
tasks.each { |task| task.complete = true }
|
61
|
+
new_data = tasks_hash(tasks)
|
62
|
+
FileHelper.write_to_file(FileHelper::YML_PATH, new_data.to_yaml)
|
63
|
+
end
|
64
|
+
|
65
|
+
def complete_task(id)
|
66
|
+
tasks = load_tasks
|
67
|
+
tasks.each { |task| task.complete = true if task.id == id.to_i }
|
68
|
+
new_data = tasks_hash(tasks)
|
69
|
+
FileHelper.write_to_file(FileHelper::YML_PATH, new_data.to_yaml)
|
70
|
+
end
|
71
|
+
|
72
|
+
def valid_task?(task)
|
73
|
+
# binding.pry
|
74
|
+
task && task.is_a?(Hash) && !task[:title].nil?
|
75
|
+
end
|
76
|
+
|
77
|
+
#
|
78
|
+
# private class methods
|
79
|
+
#
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def tasks_hash(tasks)
|
84
|
+
tasks.map do |task|
|
85
|
+
task.to_hash
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
---
|
2
|
+
- :title: this is sample completed task
|
3
|
+
:category: sample
|
4
|
+
:created_at: 2017-04-27 12:05:50.565892971 +06:00
|
5
|
+
:complete: true
|
6
|
+
:completed_at: 2017-05-27 12:05:50.565892971 +06:00
|
7
|
+
- :title: this is sample task
|
8
|
+
:category: sample
|
9
|
+
:created_at: 2017-04-27 12:05:50.565892971 +06:00
|
10
|
+
:complete:
|
11
|
+
:completed_at:
|
data/lib/ptm/version.rb
ADDED
data/ptm.gemspec
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'ptm/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'ptm'
|
9
|
+
spec.version = Ptm::VERSION
|
10
|
+
spec.authors = ['engr-hasanuzzaman']
|
11
|
+
spec.email = ['hasanuzzaman.sumon@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = <<-DESC
|
14
|
+
Personal task manager(ptm) is a command line application build for managing personal tasks list.'
|
15
|
+
DESC
|
16
|
+
|
17
|
+
spec.description = <<-DESCRIPTION
|
18
|
+
Personal task manager(ptm) is a command line application implemented in Ruby using Thor. Using this app you can manage
|
19
|
+
your task list, like add new task, make complete existing task, remove task etc. Please visit homepage for knowing
|
20
|
+
about available functionality.
|
21
|
+
DESCRIPTION
|
22
|
+
spec.homepage = 'https://github.com/engr-hasanuzzaman/ptm'
|
23
|
+
spec.license = 'MIT'
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = 'exe'
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
|
32
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
33
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
34
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
35
|
+
spec.add_development_dependency 'rubocop'
|
36
|
+
spec.add_development_dependency 'pry', '~> 0.10.4'
|
37
|
+
|
38
|
+
# runtime dependency
|
39
|
+
spec.add_dependency 'thor', '~> 0.19.4'
|
40
|
+
spec.add_dependency 'httparty', '~> 0.14.0'
|
41
|
+
spec.add_dependency 'rainbow', '~> 2.2.2'
|
42
|
+
end
|
data/test.rb
ADDED
metadata
ADDED
@@ -0,0 +1,186 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ptm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.a
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- engr-hasanuzzaman
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-30 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.14'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.10.4
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.10.4
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: thor
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.19.4
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.19.4
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: httparty
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.14.0
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.14.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rainbow
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 2.2.2
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 2.2.2
|
125
|
+
description: |2
|
126
|
+
Personal task manager(ptm) is a command line application implemented in Ruby using Thor. Using this app you can manage
|
127
|
+
your task list, like add new task, make complete existing task, remove task etc. Please visit homepage for knowing
|
128
|
+
about available functionality.
|
129
|
+
email:
|
130
|
+
- hasanuzzaman.sumon@gmail.com
|
131
|
+
executables:
|
132
|
+
- ptm
|
133
|
+
extensions: []
|
134
|
+
extra_rdoc_files: []
|
135
|
+
files:
|
136
|
+
- ".gitignore"
|
137
|
+
- ".rspec"
|
138
|
+
- ".rubocop.yml"
|
139
|
+
- ".ruby-version"
|
140
|
+
- ".travis.yml"
|
141
|
+
- CODE_OF_CONDUCT.md
|
142
|
+
- Gemfile
|
143
|
+
- LICENSE.txt
|
144
|
+
- README.md
|
145
|
+
- Rakefile
|
146
|
+
- bin/console
|
147
|
+
- bin/setup
|
148
|
+
- exe/ptm
|
149
|
+
- lib/ptm.rb
|
150
|
+
- lib/ptm/cli.rb
|
151
|
+
- lib/ptm/completed_task.rb
|
152
|
+
- lib/ptm/decorator_helper.rb
|
153
|
+
- lib/ptm/file_helper.rb
|
154
|
+
- lib/ptm/pending_task.rb
|
155
|
+
- lib/ptm/task.rb
|
156
|
+
- lib/ptm/task_decorato.rb
|
157
|
+
- lib/ptm/tasks.yml.sample
|
158
|
+
- lib/ptm/version.rb
|
159
|
+
- ptm.gemspec
|
160
|
+
- test.rb
|
161
|
+
homepage: https://github.com/engr-hasanuzzaman/ptm
|
162
|
+
licenses:
|
163
|
+
- MIT
|
164
|
+
metadata: {}
|
165
|
+
post_install_message:
|
166
|
+
rdoc_options: []
|
167
|
+
require_paths:
|
168
|
+
- lib
|
169
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - ">"
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: 1.3.1
|
179
|
+
requirements: []
|
180
|
+
rubyforge_project:
|
181
|
+
rubygems_version: 2.6.8
|
182
|
+
signing_key:
|
183
|
+
specification_version: 4
|
184
|
+
summary: Personal task manager(ptm) is a command line application build for managing
|
185
|
+
personal tasks list.'
|
186
|
+
test_files: []
|