ruby-pomodoro 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/ruby.yml +24 -0
  3. data/.gitignore +12 -0
  4. data/.rspec +3 -0
  5. data/.ruby-version +1 -0
  6. data/CHANGELOG.md +78 -0
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/Gemfile +8 -0
  9. data/Gemfile.lock +67 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +46 -0
  12. data/Rakefile +6 -0
  13. data/bin/console +14 -0
  14. data/bin/setup +8 -0
  15. data/exe/ruby-pomodoro +5 -0
  16. data/lib/ruby/pomodoro/cmd/base.rb +40 -0
  17. data/lib/ruby/pomodoro/cmd/choose_task.rb +33 -0
  18. data/lib/ruby/pomodoro/cmd/edit_list.rb +15 -0
  19. data/lib/ruby/pomodoro/cmd/error_handler.rb +17 -0
  20. data/lib/ruby/pomodoro/cmd/main.rb +15 -0
  21. data/lib/ruby/pomodoro/cmd/pause.rb +27 -0
  22. data/lib/ruby/pomodoro/cmd/quit.rb +19 -0
  23. data/lib/ruby/pomodoro/cmd/stop.rb +12 -0
  24. data/lib/ruby/pomodoro/command_controller.rb +42 -0
  25. data/lib/ruby/pomodoro/notification.rb +40 -0
  26. data/lib/ruby/pomodoro/notification_observer.rb +32 -0
  27. data/lib/ruby/pomodoro/printer.rb +56 -0
  28. data/lib/ruby/pomodoro/progressbar.rb +32 -0
  29. data/lib/ruby/pomodoro/task.rb +25 -0
  30. data/lib/ruby/pomodoro/tasks/editor.rb +65 -0
  31. data/lib/ruby/pomodoro/tasks/entity.rb +27 -0
  32. data/lib/ruby/pomodoro/tasks/resource.rb +42 -0
  33. data/lib/ruby/pomodoro/terminal_notifier_channel.rb +13 -0
  34. data/lib/ruby/pomodoro/time_converter.rb +27 -0
  35. data/lib/ruby/pomodoro/time_helpers.rb +11 -0
  36. data/lib/ruby/pomodoro/version.rb +5 -0
  37. data/lib/ruby/pomodoro/worker.rb +78 -0
  38. data/lib/ruby/pomodoro.rb +86 -0
  39. data/lib/view/main.txt.erb +13 -0
  40. data/ruby-pomodoro.gemspec +31 -0
  41. metadata +156 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 667bcaf784b502e99b2a7c12c9191e9111d9021169536780ea0dd18d8183a10e
4
+ data.tar.gz: c65ec77cb4230982371ac2a873661b7c18bfc7db7825986c64a51772c45c877e
5
+ SHA512:
6
+ metadata.gz: e59e0cd9616c20f6615f7c306db7b4c952c90a686cf6891b65d707c588faf1dc3f5af26c12d4f77c8717d5c3dd03e3ddec60c100c5034e757e4be02b9ef4dea6
7
+ data.tar.gz: a9c725792d947809e0ded09b83e53a00d9e8d64bc967b09113e36aafb7701f940c894d04f22fad53862cd1087c9d97a26c2dad8ace8fa21084fd56d908595023
@@ -0,0 +1,24 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ build:
11
+
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Set up Ruby 2.6
17
+ uses: actions/setup-ruby@v1
18
+ with:
19
+ ruby-version: 2.6.x
20
+ - name: Build and test with Rake
21
+ run: |
22
+ gem install bundler
23
+ bundle install --jobs 4 --retry 3
24
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .idea
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.6.3
data/CHANGELOG.md ADDED
@@ -0,0 +1,78 @@
1
+ # Change log
2
+
3
+ ## master
4
+
5
+ ## 0.4.0 (2021-11-18)
6
+
7
+ - Adds Ruby 3 support
8
+ - Fixes saving tasks
9
+ - Fixes notifications
10
+
11
+ ## 0.3.4 (2020-04-04)
12
+
13
+ - add fast numbers keys, select task on type number
14
+
15
+ ## 0.3.3 (2020-03-23)
16
+
17
+ - add colors
18
+ - activate terminal on click
19
+
20
+ ## 0.3.2 (2020-03-23)
21
+
22
+ - fix edit tasks
23
+
24
+ ## 0.3.1 (2020-03-23)
25
+
26
+ - fix total time
27
+ - add error handler
28
+ - add russian keys support
29
+
30
+
31
+ ## 0.3.0 (2020-03-21)
32
+
33
+ - improved UI
34
+ - move logic to command modules
35
+
36
+ ## 0.2.3 (2020-03-18)
37
+
38
+ - can choose task all time
39
+ - can edit tasks all time
40
+ - show pause message
41
+ - fix mini bugs
42
+
43
+ ## 0.2.2 (2020-03-16)
44
+
45
+ - add summary time
46
+ - fix bugs
47
+ - repeat task
48
+
49
+ ## 0.2.1 (2020-03-15)
50
+
51
+ - fix bugs
52
+
53
+ ## 0.2.0 (2020-03-15)
54
+
55
+ - Add task editor
56
+ - Add save tasks to disc
57
+
58
+ ## 0.1.3 (2020-03-15)
59
+
60
+ - Fix output bugs
61
+
62
+ ## 0.1.2 (2020-03-15)
63
+
64
+ - Fix bug, choose task if list of tasks is empty
65
+ - Improvement output
66
+ - Add print task spent time
67
+
68
+ ## 0.1.1 (2020-03-14)
69
+
70
+ - Notification after finish pomodoro
71
+ - Improvement stability
72
+
73
+ ## 0.1.0 (2020-03-13)
74
+
75
+ - Base MVP.
76
+
77
+
78
+
@@ -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 skiline.alex@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 [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in ruby-pomodoro.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "rspec", "~> 3.0"
8
+ gem "debug", ">= 1.0.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,67 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ruby-pomodoro (0.3.4)
5
+ aasm (~> 5)
6
+ pastel (~> 0.8)
7
+ terminal-notifier
8
+ tty-cursor (~> 0.6)
9
+ tty-editor (~> 0.7)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ aasm (5.2.0)
15
+ concurrent-ruby (~> 1.0)
16
+ concurrent-ruby (1.1.9)
17
+ debug (1.3.4)
18
+ irb (>= 1.3.6)
19
+ reline (>= 0.2.7)
20
+ diff-lcs (1.4.4)
21
+ io-console (0.5.9)
22
+ irb (1.3.7)
23
+ reline (>= 0.2.7)
24
+ pastel (0.8.0)
25
+ tty-color (~> 0.5)
26
+ rake (12.3.3)
27
+ reline (0.2.7)
28
+ io-console (~> 0.5)
29
+ rspec (3.10.0)
30
+ rspec-core (~> 3.10.0)
31
+ rspec-expectations (~> 3.10.0)
32
+ rspec-mocks (~> 3.10.0)
33
+ rspec-core (3.10.1)
34
+ rspec-support (~> 3.10.0)
35
+ rspec-expectations (3.10.1)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.10.0)
38
+ rspec-mocks (3.10.2)
39
+ diff-lcs (>= 1.2.0, < 2.0)
40
+ rspec-support (~> 3.10.0)
41
+ rspec-support (3.10.3)
42
+ terminal-notifier (2.0.0)
43
+ tty-color (0.6.0)
44
+ tty-cursor (0.7.1)
45
+ tty-editor (0.7.0)
46
+ tty-prompt (~> 0.22)
47
+ tty-prompt (0.23.1)
48
+ pastel (~> 0.8)
49
+ tty-reader (~> 0.8)
50
+ tty-reader (0.9.0)
51
+ tty-cursor (~> 0.7)
52
+ tty-screen (~> 0.8)
53
+ wisper (~> 2.0)
54
+ tty-screen (0.8.1)
55
+ wisper (2.0.1)
56
+
57
+ PLATFORMS
58
+ ruby
59
+
60
+ DEPENDENCIES
61
+ debug (>= 1.0.0)
62
+ rake (~> 12.0)
63
+ rspec (~> 3.0)
64
+ ruby-pomodoro!
65
+
66
+ BUNDLED WITH
67
+ 2.2.22
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Alexander Shvaykin
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ ![Ruby](https://github.com/AlexanderShvaykin/pomodoro-tracker/workflows/Ruby/badge.svg?branch=master)
2
+
3
+ # Ruby::Pomodoro
4
+
5
+ [Pomodoro](https://en.wikipedia.org/wiki/Pomodoro_Technique) CLI task tracker
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ruby-pomodoro'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install ruby-pomodoro
22
+
23
+ ## Usage
24
+
25
+ $ ruby-pomodoro
26
+
27
+ Then you will see an interactive interface where you can add and perform tasks.
28
+
29
+ ## Development
30
+
31
+ 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.
32
+
33
+ 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).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ruby-pomodoro. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/ruby-pomodoro/blob/master/CODE_OF_CONDUCT.md).
38
+
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
43
+
44
+ ## Code of Conduct
45
+
46
+ Everyone interacting in the Ruby::Pomodoro project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/ruby-pomodoro/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruby/pomodoro"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/ruby-pomodoro ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "ruby/pomodoro"
4
+
5
+ Ruby::Pomodoro.start
@@ -0,0 +1,40 @@
1
+ # Commands for each user action
2
+ module Ruby
3
+ module Pomodoro
4
+ module Cmd
5
+ class Base
6
+ include TimeHelpers
7
+
8
+ # @param [Ruby::Pomodoro::Printer] printer
9
+ # @param prompt [Object]
10
+ def initialize(printer: Ruby::Pomodoro::Printer.new, prompt: TTY::Prompt.new, worker: Ruby::Pomodoro::Worker.instance)
11
+ @printer = printer
12
+ @prompt = prompt
13
+ @worker = worker
14
+ end
15
+
16
+ # @abstract
17
+ # @return [Symbol, NilClass]
18
+ def call; end
19
+
20
+ private
21
+
22
+ attr_reader :prompt, :worker
23
+
24
+ def print(clear: true, **options)
25
+ @printer.clear_terminal if clear
26
+
27
+ type, value = options.first
28
+ case type
29
+ when :template
30
+ @printer.print_template(value, binding)
31
+ when :text
32
+ @printer.print(value, color: options[:color])
33
+ else
34
+ nil
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,33 @@
1
+ module Ruby
2
+ module Pomodoro
3
+ module Cmd
4
+ # Select task and start worker
5
+ class ChooseTask < Base
6
+ # @param [Ruby::Pomodoro::Worker] worker
7
+ def call
8
+ worker.pause if worker.working?
9
+ print
10
+ task = Ruby::Pomodoro::Tasks::Resource.find(select_task(worker.current_task))
11
+ Main.new.call
12
+ if task
13
+ worker.stop
14
+ worker.start(task)
15
+ else
16
+ worker.resume if worker.paused?
17
+ end
18
+ :ok
19
+ end
20
+
21
+ private
22
+
23
+ def select_task(current_task)
24
+ options = Ruby::Pomodoro::Tasks::Resource.all.map do |task|
25
+ disable = task == current_task ? "(The task in progress)" : nil
26
+ { value: task.id, name: task.name, disabled: disable }
27
+ end
28
+ prompt.select("Select task", [*options, { name: "exit", value: 0 }])
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,15 @@
1
+ module Ruby
2
+ module Pomodoro
3
+ module Cmd
4
+ class EditList < Base
5
+ def call(editor)
6
+ print
7
+ worker.stop
8
+ editor.save
9
+ editor.edit
10
+ Main.new.call
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ module Ruby
2
+ module Pomodoro
3
+ module Cmd
4
+ class ErrorHandler < Base
5
+ def call(error)
6
+ path = File.join(Dir.home, ".ruby-pomodoro", "log")
7
+ Logger.new(path).error(error.message)
8
+ print text: "Oops! Error! Detail info in the log file (~/.ruby-pomodoro/log)\n", color: :red
9
+ prompt.keypress(
10
+ "Press any key to continue, resumes automatically in 3 seconds ...", timeout: 3
11
+ )
12
+ Main.new.call
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,15 @@
1
+ module Ruby
2
+ module Pomodoro
3
+ # Print tasks list and commands list
4
+ module Cmd
5
+ class Main < Base
6
+ # @return [Symbol] signal for controller
7
+ def call
8
+ @tasks = Ruby::Pomodoro::Tasks::Resource.all
9
+ print template: :main
10
+ :ok
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,27 @@
1
+ module Ruby
2
+ module Pomodoro
3
+ module Cmd
4
+ class Pause < Base
5
+ def call
6
+ if worker.working?
7
+ Main.new.call
8
+ worker.pause
9
+ choices = [
10
+ { key: 'y', name: "Resume this task", value: true },
11
+ { key: 'n', name: 'Stop this task', value: false },
12
+ ]
13
+ print text: "#{worker.current_task.name} was paused\n", color: :yellow, clear: false
14
+ if prompt.expand("Resume?", choices)
15
+ Main.new.call
16
+ worker.resume
17
+ else
18
+ Stop.new.call
19
+ end
20
+ else
21
+ Main.new.call
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,19 @@
1
+ module Ruby
2
+ module Pomodoro
3
+ module Cmd
4
+ # Save tasks and stop program
5
+ class Quit < Base
6
+ # @param [Ruby::Pomodoro::Tasks::Editor] editor
7
+ # @return [Symbol]
8
+ def call(editor)
9
+ worker.delete_observers
10
+ worker.stop
11
+ editor.save
12
+ Main.new.call
13
+ print text: "Bye!\n", color: :green, clear: false
14
+ :quit
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ module Ruby
2
+ module Pomodoro
3
+ module Cmd
4
+ class Stop < Base
5
+ def call
6
+ worker.stop
7
+ Main.new.call
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,42 @@
1
+ module Ruby
2
+ module Pomodoro
3
+ module CommandController
4
+ class << self
5
+ def call(event)
6
+ signal =
7
+ case event.value
8
+ when 'q', 'й'
9
+ Cmd::Quit.new.call(Pomodoro.editor)
10
+ when 'c', 'с'
11
+ Cmd::ChooseTask.new.call
12
+ when 'e', 'у'
13
+ Cmd::EditList.new.call(Pomodoro.editor)
14
+ when 'p', 'з'
15
+ Cmd::Pause.new.call
16
+ when 's', 'ы'
17
+ Cmd::Stop.new.call
18
+ when 'R', 'К'
19
+ Worker.instance.then do |worker|
20
+ task = worker.current_task
21
+ worker.start(task) if task
22
+ Cmd::Main.new.call
23
+ end
24
+ when /[1-9]/
25
+ Worker.instance.then do |worker|
26
+ task = Ruby::Pomodoro::Tasks::Resource.find(event.value.to_i)
27
+ return if task.nil? || task.id == worker.current_task&.id
28
+
29
+ Cmd::Main.new.call
30
+ worker.stop
31
+ worker.start(task)
32
+ end
33
+ else
34
+ Cmd::Main.new.call
35
+ end
36
+ abort if signal == :quit
37
+ end
38
+ alias_method :keypress, :call
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,40 @@
1
+ module Ruby
2
+ module Pomodoro
3
+ class Notification
4
+ attr_reader :message
5
+
6
+ # @param message [String] Message
7
+ # @param channel [Object, Module] Channel to push message
8
+ def initialize(message, channel)
9
+ @message = message
10
+ @channel = channel
11
+ end
12
+
13
+ # @param repeat_at [Numeric] Time to repeat
14
+ # @param skip_now [Boolean] Skip notify after call, default: +false+
15
+ # @return [TrueClass]
16
+ def notify(repeat_at = nil, skip_now: false)
17
+ @channel.call(message) unless skip_now
18
+ repeat(repeat_at) if repeat_at
19
+ true
20
+ end
21
+
22
+ # @return [TrueClass]
23
+ def stop
24
+ @thread&.kill
25
+ true
26
+ end
27
+
28
+ private
29
+
30
+ def repeat(time_at)
31
+ @thread = Thread.new do
32
+ loop do
33
+ sleep time_at
34
+ @channel.call(message)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end