rbdo 1.0.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,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d744a28b339d02cef31dfc068d3f1d40e43b0c04551c28d41358cbf9404e221e
4
+ data.tar.gz: a4d4bdac96106fcd77448156d6d02f3a29e34ef6b9894fd36b47fd369b2486d9
5
+ SHA512:
6
+ metadata.gz: 26795c12853b448179231193f1862d7f737daab54ef12ee70959bd1d0b04af5ecb9fd783aa0e00e0bc4fc2b1d4412b6520200996cc2bd2ded8e0acd526259aee
7
+ data.tar.gz: f95c8ea82d2c17f345ad13e786d4bf2fb7db0fffbd80a4ea55e2e9eedbca026731756968f0670b3f73586899b696f71767935d6bdbfe4de860762f4e82620f07
@@ -0,0 +1 @@
1
+ * text=auto eol=lf
@@ -0,0 +1,26 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Documentation cache and generated files:
14
+ /.yardoc/
15
+ /_yardoc/
16
+ /doc/
17
+ /rdoc/
18
+
19
+ ## Environment normalization:
20
+ /.bundle/
21
+ /vendor/bundle
22
+ /lib/bundler/man/
23
+
24
+ # for a library or gem, you might want to ignore these files since the code is
25
+ # intended to run in multiple environments; otherwise, check them in:
26
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 personinblack <berkay@tuta.io>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software
6
+ and associated documentation files (the "Software"), to deal in the Software without restriction,
7
+ including without limitation the rights to use, copy, modify, merge, publish, distribute,
8
+ sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or
12
+ substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
15
+ BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # rbdo: a simple todo app in cli
2
+
3
+ ## commands
4
+
5
+ ### .add
6
+
7
+ `./rbdo.rb add --text="netflix and chill" --date=28/01/2019 --time=18:03`
8
+
9
+ ### .ls
10
+
11
+ `./rbdo.rb ls` or `./rbdo.rb ls --date=28/01/2019`
12
+
13
+ ### .rm
14
+
15
+ `./rbdo.rb rm --index=5`
16
+
17
+ ## arguments
18
+
19
+ ### --text
20
+
21
+ text/content of the todo entry.
22
+
23
+ `./rbdo.rb add --text="netflix and chill"`
24
+
25
+ ### --date
26
+
27
+ date of the todo entry. (year and month are optional)
28
+
29
+ `./rbdo.rb ls --date=28/01/2019`
30
+
31
+ ### --time
32
+
33
+ time of the todo entry. (minute and second are optional)
34
+
35
+ `./rbdo.rb add --text=todo --time=18:03:08`
36
+
37
+ ### --index
38
+
39
+ index of the todo entry required for the rm command.
40
+
41
+ `./rbdo.rb rm --index=5`
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright (c) 2018 personinblack <berkay@tuta.io>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'bundler/setup'
24
+ require 'rbdo'
25
+ require 'irb'
26
+
27
+ IRB.start(__FILE__)
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Copyright (c) 2018 personinblack <berkay@tuta.io>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ set -euo pipefail
24
+ IFS=$'\n\t'
25
+ set -vx
26
+
27
+ bundle install
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright (c) 2018 personinblack <berkay@tuta.io>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require 'rbdo'
@@ -0,0 +1,63 @@
1
+ # Copyright (c) 2018 personinblack <berkay@tuta.io>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require_relative 'rbdo/version'
22
+ require_relative 'rbdo/todo/todo'
23
+ require_relative 'rbdo/todo/todos'
24
+ require_relative 'rbdo/command/command'
25
+ require_relative 'rbdo/command/command_add'
26
+ require_relative 'rbdo/command/command_rm'
27
+ require_relative 'rbdo/command/command_ls'
28
+ require_relative 'rbdo/command/command_help'
29
+
30
+ #
31
+ # RBDO - main module
32
+ #
33
+ module RBDO
34
+ class Error < StandardError
35
+ end
36
+
37
+ DEF_DATA_LOCATION = "#{ENV['XDG_CONFIG_HOME']}/rbdo/data.yml".freeze
38
+
39
+ todos = Todos.new
40
+ todos.load!(DEF_DATA_LOCATION)
41
+
42
+ handled = false
43
+
44
+ [
45
+ CommandAdd.new(todos), CommandLS.new(todos),
46
+ CommandRM.new(todos), CommandHelp.new
47
+ ].each do |command|
48
+ if command.handle(ARGV)
49
+ handled = true
50
+ puts unless command.is_a?(CommandLS)
51
+ end
52
+ end
53
+
54
+ unless handled
55
+ CommandHelp.new.handle(['help'])
56
+ puts
57
+ end
58
+ CommandLS.new(todos).handle(['ls'])
59
+
60
+ todos.save!(DEF_DATA_LOCATION)
61
+
62
+ # TODO: return the help message if none of the commands handled the ARGV
63
+ end
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 2018 personinblack <berkay@tuta.io>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ module RBDO
22
+ #
23
+ # argument_date.rb - argument for parsing dates
24
+ #
25
+ class ArgumentDate
26
+ def initialize(val)
27
+ @val = val
28
+ end
29
+
30
+ def parsed
31
+ return Time.now unless
32
+ @val.instance_of?(String) &&
33
+ @val.match?(%r{^([0-9]){2}(/([0-9]){2}(/([0-9]){4}){0,1}){0,1}$})
34
+
35
+ date_a = @val.split('/')
36
+ Time.new(
37
+ date_a[2] || Time.now.year, date_a[1] || Time.now.month, date_a[0]
38
+ )
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,40 @@
1
+ # Copyright (c) 2018 personinblack <berkay@tuta.io>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ module RBDO
22
+ #
23
+ # argument_index.rb - argument for validating indexes
24
+ #
25
+ class ArgumentIndex
26
+ def initialize(val, todos, default = todos.size - 1)
27
+ @val = val
28
+ @todos = todos
29
+ @default = default
30
+ end
31
+
32
+ def parsed
33
+ if @val.nil? || !@val.is_a?(Numeric) || @val > @todos.size - 1
34
+ @default
35
+ else
36
+ @val
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,35 @@
1
+ # Copyright (c) 2018 personinblack <berkay@tuta.io>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ module RBDO
22
+ #
23
+ # argument_text.rb - argument for validating texts
24
+ #
25
+ class ArgumentText
26
+ def initialize(val, default = 'unspecified')
27
+ @val = val
28
+ @default = default
29
+ end
30
+
31
+ def parsed
32
+ @val.nil? || @val.empty? ? @default : @val
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,44 @@
1
+ # Copyright (c) 2018 personinblack <berkay@tuta.io>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require_relative 'argument_date'
22
+
23
+ module RBDO
24
+ #
25
+ # argument_time.rb - argument for parsing times
26
+ #
27
+ class ArgumentTime
28
+ def initialize(val)
29
+ @val = val
30
+ end
31
+
32
+ def parsed(date = ArgumentDate.new(nil))
33
+ date = date.parsed
34
+ return date unless @val.instance_of?(String) &&
35
+ @val.match?(/^([0-9]){2}(:([0-9]){2}){0,2}$/)
36
+
37
+ time_a = @val.split(':')
38
+ Time.new(
39
+ date.year.to_i, date.month.to_i, date.day.to_i,
40
+ time_a[0], time_a[1], time_a[2]
41
+ )
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,54 @@
1
+ # Copyright (c) 2018 personinblack <berkay@tuta.io>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ module RBDO
22
+ #
23
+ # command.rb - cli command
24
+ #
25
+ class Command
26
+ def initialize(name)
27
+ @name = name
28
+ end
29
+
30
+ def handle(argv)
31
+ name = Command.split_name(argv)
32
+ arguments = Command.split_arguments(argv)
33
+ return arguments if name == @name
34
+ end
35
+
36
+ def self.split_name(argv)
37
+ argv.each do |part|
38
+ return part unless part.start_with?('--')
39
+ end
40
+ end
41
+
42
+ def self.split_arguments(argv)
43
+ arguments = {}
44
+ argv.each do |part|
45
+ next unless part.start_with?('--')
46
+
47
+ argument = part[2, part.size]
48
+ arguments[argument.split('=')[0]] = argument.split('=')[1] unless
49
+ argument.empty?
50
+ end
51
+ arguments
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,52 @@
1
+ # Copyright (c) 2018 personinblack <berkay@tuta.io>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require_relative 'command'
22
+ require_relative '../todo/todo'
23
+ require_relative '../argument/argument_date'
24
+ require_relative '../argument/argument_time'
25
+ require_relative '../argument/argument_text'
26
+
27
+ module RBDO
28
+ #
29
+ # command_add.rb - command for adding todo entries to the todo list
30
+ #
31
+ class CommandAdd
32
+ def initialize(todos)
33
+ @todos = todos
34
+ @command = Command.new('add')
35
+ end
36
+
37
+ def handle(argv)
38
+ arguments = @command.handle(argv)
39
+
40
+ return false unless arguments.instance_of?(Hash)
41
+
42
+ @todos << Todo.new(
43
+ ArgumentText.new(arguments['text']).parsed,
44
+ ArgumentTime.new(arguments['time']).parsed(
45
+ ArgumentDate.new(arguments['date'])
46
+ )
47
+ )
48
+
49
+ true
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,40 @@
1
+ # Copyright (c) 2018 personinblack <berkay@tuta.io>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require 'tty-markdown'
22
+ require_relative 'command'
23
+
24
+ module RBDO
25
+ #
26
+ # command_help.rb - command for showing off the usage
27
+ #
28
+ class CommandHelp
29
+ def initialize
30
+ @command = Command.new('help')
31
+ end
32
+
33
+ def handle(argv)
34
+ return false unless @command.handle(argv).instance_of?(Hash)
35
+
36
+ puts TTY::Markdown.parse_file("#{__dir__}/../../../README.md")
37
+ true
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,43 @@
1
+ # Copyright (c) 2018 personinblack <berkay@tuta.io>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require_relative 'command'
22
+
23
+ module RBDO
24
+ #
25
+ # command_ls.rb - command for listing todo entries
26
+ #
27
+ class CommandLS
28
+ def initialize(todos)
29
+ @todos = todos
30
+ @command = Command.new('ls')
31
+ end
32
+
33
+ def handle(argv)
34
+ arguments = @command.handle(argv)
35
+
36
+ return false unless arguments.instance_of?(Hash)
37
+
38
+ @todos.display
39
+
40
+ true
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,44 @@
1
+ # Copyright (c) 2018 personinblack <berkay@tuta.io>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require_relative 'command'
22
+ require_relative '../argument/argument_index'
23
+
24
+ module RBDO
25
+ #
26
+ # command_rm.rb - command for removing todo entries from the todo list
27
+ #
28
+ class CommandRM
29
+ def initialize(todos)
30
+ @todos = todos
31
+ @command = Command.new('rm')
32
+ end
33
+
34
+ def handle(argv)
35
+ arguments = @command.handle(argv)
36
+
37
+ return false unless arguments.instance_of?(Hash)
38
+
39
+ @todos.rm!(ArgumentIndex.new(arguments['index'].to_i, @todos).parsed)
40
+
41
+ true
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,48 @@
1
+ # Copyright (c) 2018 personinblack <berkay@tuta.io>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ module RBDO
22
+ #
23
+ # todo.rb - todo
24
+ #
25
+ class Todo
26
+ def initialize(text, time)
27
+ @text = text
28
+ @time = time
29
+ end
30
+
31
+ def print(todos)
32
+ todos << { 'text' => @text, 'time' => @time }
33
+ end
34
+
35
+ def load(todo_as_hash)
36
+ Todo.new(todo_as_hash['text'], todo_as_hash['time'])
37
+ end
38
+
39
+ def display
40
+ remaining_days = (@time - Time.now).to_f
41
+ printf "#{@text} in #{remaining_days.to_i / 86_400} days" \
42
+ " (#{@time.strftime('%d/%m/%Y %H:%M:%S')})"
43
+
44
+ printf ' <I hope you didn\'t miss it...>' if remaining_days < 0
45
+ puts
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,87 @@
1
+ # Copyright (c) 2018 personinblack <berkay@tuta.io>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ require 'yaml'
22
+ require 'pathname'
23
+ require 'fileutils'
24
+
25
+ module RBDO
26
+ #
27
+ # todos.rb - todos
28
+ #
29
+ class Todos
30
+ def initialize
31
+ @todo_list = []
32
+ end
33
+
34
+ def <<(todo)
35
+ @todo_list << todo
36
+ printf 'ADDED: '
37
+ todo.display
38
+ end
39
+
40
+ def rm!(index)
41
+ @todo_list.fetch(index) do
42
+ puts 'nothing to delete'
43
+ return false
44
+ end
45
+ printf 'DELETED: '
46
+ @todo_list.delete_at(index).display
47
+ end
48
+
49
+ def display
50
+ return if @displayed
51
+
52
+ @displayed = true
53
+
54
+ if @todo_list.empty?
55
+ puts 'nothing to show'
56
+ return
57
+ end
58
+
59
+ @todo_list.each_with_index do |todo, i|
60
+ printf("#{i}. ")
61
+ todo.display
62
+ end
63
+ end
64
+
65
+ def load!(file_name)
66
+ return false unless FileTest.exist?(file_name)
67
+
68
+ loaded_data = YAML.load_file(file_name)
69
+ @todo_list = loaded_data if loaded_data.instance_of?(Array)
70
+ end
71
+
72
+ def save!(file_name)
73
+ unless FileTest.exist?(file_name)
74
+ FileUtils.mkdir_p(Pathname.new(file_name).parent)
75
+ File.new(file_name, 'w+')
76
+ end
77
+
78
+ File.open(file_name, 'w+') do |file|
79
+ file.write(@todo_list.to_yaml)
80
+ end
81
+ end
82
+
83
+ def size
84
+ @todo_list.size
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,23 @@
1
+ # Copyright (c) 2018 personinblack <berkay@tuta.io>
2
+ #
3
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ # of this software and associated documentation files (the "Software"), to deal
5
+ # in the Software without restriction, including without limitation the rights
6
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ # copies of the Software, and to permit persons to whom the Software is
8
+ # furnished to do so, subject to the following conditions:
9
+ #
10
+ # The above copyright notice and this permission notice shall be included in all
11
+ # copies or substantial portions of the Software.
12
+ #
13
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ # SOFTWARE.
20
+
21
+ module RBDO
22
+ VERSION = '1.0.0'.freeze
23
+ end
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'rbdo/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'rbdo'
7
+ spec.version = RBDO::VERSION
8
+ spec.authors = ['personinblack']
9
+ spec.email = 'berkay@tuta.io'
10
+
11
+ spec.summary = 'a simple todo app in cli'
12
+ spec.homepage = 'https://github.com/personinblack/rbdo'
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
16
+ `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ end
20
+ spec.bindir = 'exe'
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ['lib']
23
+
24
+ spec.required_ruby_version = '>= 2.2'
25
+ spec.add_runtime_dependency 'tty-markdown', '~> 0'
26
+ spec.add_development_dependency 'bundler', '~> 1.17'
27
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbdo
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - personinblack
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tty-markdown
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ description:
42
+ email: berkay@tuta.io
43
+ executables:
44
+ - rbdo
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitattributes"
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE
52
+ - README.md
53
+ - bin/console
54
+ - bin/setup
55
+ - exe/rbdo
56
+ - lib/rbdo.rb
57
+ - lib/rbdo/argument/argument_date.rb
58
+ - lib/rbdo/argument/argument_index.rb
59
+ - lib/rbdo/argument/argument_text.rb
60
+ - lib/rbdo/argument/argument_time.rb
61
+ - lib/rbdo/command/command.rb
62
+ - lib/rbdo/command/command_add.rb
63
+ - lib/rbdo/command/command_help.rb
64
+ - lib/rbdo/command/command_ls.rb
65
+ - lib/rbdo/command/command_rm.rb
66
+ - lib/rbdo/todo/todo.rb
67
+ - lib/rbdo/todo/todos.rb
68
+ - lib/rbdo/version.rb
69
+ - rbdo.gemspec
70
+ homepage: https://github.com/personinblack/rbdo
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '2.2'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.7.7
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: a simple todo app in cli
94
+ test_files: []