rbtclk 0.3.4 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a0fc07db46af23f24380a963fa37722a3ff6bb7a
4
- data.tar.gz: eebf1b0c316d18cdd75d26feae2043491858178e
3
+ metadata.gz: 249cb25def3f52ad44433d4f871f72cbd75cf7a3
4
+ data.tar.gz: c547d281e2e035742cae671576296f0d34532b21
5
5
  SHA512:
6
- metadata.gz: bba36b861bb79b97bb5e022e7b4401c191a9bb63a7af1f8037e2be552aa143141f7c93c93ad6e8cc6c41aff224298aa17c94bd24db67f09dbfb9d3fbf13ae6e9
7
- data.tar.gz: a4eccd625012d44a89b8f6f0f94dd0d6c515338cced9da1e1ca6e5904217f6ea20190fd1363bdda4b0b059689fc2746fb7630c08e42ab8b99e1ba601ea30f434
6
+ metadata.gz: db87de5f550c2e183fed77957ee96e2d424fae85045df107ff0b3499ca1f946d156285b9cc75d31d6cf8c487c8981bb74ad90d1cc19e5f5237fc966eac417fc6
7
+ data.tar.gz: 5670e0ad318bb2579747af6df0ea412772a39a23b2a2371c25b4b1f8f85cc02dfed857035edff072bd6c44324bfb6665f48f2826028479dce6439fad93a0bf4c
data/README.md CHANGED
@@ -7,6 +7,21 @@ A light-weight timer application that can run in terminal emulators :rabbit:
7
7
  ## Requirement
8
8
 
9
9
  - Ruby 2.0 or later.
10
+ - afplay or mpg123
11
+
12
+ This application is tested on OS X 10.10 and Arch Linux.
13
+
14
+ Rbtclk needs a sound player tool like afplay or mpg123.
15
+ OS X has normally afplay as default.
16
+ If you use other UNIX like system, you should install mpg123.
17
+
18
+ On Arch Linux,
19
+
20
+ ```shell
21
+ $ sudo pacman -S mpg123
22
+ ```
23
+
24
+ Rbtclk works without sound player tools, but alerming by sound file is disabled.
10
25
 
11
26
  ## Installation
12
27
 
@@ -34,7 +49,7 @@ $ rbtclk
34
49
 
35
50
  ### Mode
36
51
 
37
- This application supports some modes; clock, countup and countdown.
52
+ This application supports some modes; clock, countup and countdown.
38
53
 
39
54
  #### Example
40
55
 
@@ -83,10 +98,14 @@ $ rbtclk -m countdown --time 90
83
98
  #### #### ## #### ## ## #### ####
84
99
  ```
85
100
 
101
+ When remaining time reaches 0, rbtclk produces a sound to alert.
102
+ This function is experimental!
103
+ You can use this feature on only OS X.
104
+
86
105
  ### Change font
87
106
 
88
107
  This application depends on artii library (https://github.com/miketierney/artii).
89
- You can use any fonts that are supported by artii.
108
+ You can use any fonts are supported by artii.
90
109
 
91
110
  #### Example
92
111
 
@@ -187,6 +206,9 @@ Rbtclk.configure do |c|
187
206
 
188
207
  # You can specify limit time as seconds in countdown timer.
189
208
  c.time = "180"
209
+
210
+ # The alarm sound is suppressed if no_alarm is true.
211
+ c.no_alarm = false
190
212
  end
191
213
  ```
192
214
 
@@ -196,7 +218,9 @@ end
196
218
  - [x] Countup Timer
197
219
  - [x] Countdown Timer
198
220
  - [x] Configuration by ~/.rbtclk
199
- - [ ] Sound
221
+ - [x] Sound
222
+ - [ ] Sound on Linux/BSD
223
+ - [ ] Controlling sound by command line options
200
224
  - [ ] Refactoring
201
225
 
202
226
  ## Code Status
@@ -210,3 +234,7 @@ end
210
234
  3. Commit your changes (`git commit -am 'Add some feature'`)
211
235
  4. Push to the branch (`git push origin my-new-feature`)
212
236
  5. Create a new Pull Request
237
+
238
+ ## Special Thanks!
239
+ Alert sound is distributed by [Taira Komori](http://taira-komori.jpn.org/freesounden.html).
240
+ Thanks!
@@ -21,4 +21,7 @@ Rbtclk.configure do |c|
21
21
 
22
22
  # You can specify limit time as seconds in countdown timer.
23
23
  c.time = "180"
24
+
25
+ # The alarm sound is suppressed if no_alarm is true.
26
+ c.no_alarm = false
24
27
  end
@@ -24,6 +24,7 @@ module Rbtclk
24
24
  opt.on("--version") { |v| params[:version] = v }
25
25
  opt.on("--color COLOR") { |c| params[:color] = c }
26
26
  opt.on("--time TIME") { |t| params[:time] = t }
27
+ opt.on("--noalarm") { |n| params[:no_alarm] = n }
27
28
 
28
29
  opt.parse!(args)
29
30
  end
@@ -63,15 +64,17 @@ module Rbtclk
63
64
  font: params[:font] || FONT,
64
65
  format: params[:format] || FORMAT,
65
66
  color: params[:color] || COLOR,
66
- time: params[:time] || TIME}
67
+ time: params[:time] || TIME,
68
+ no_alarm: params[:no_alarm] || NO_ALARM}
67
69
  end
68
70
 
69
71
  def remove_extra_params(params)
70
- params.delete(:mode)
71
-
72
72
  if params[:mode] != "countdown"
73
73
  params.delete(:time)
74
+ params.delete(:no_alarm)
74
75
  end
76
+
77
+ params.delete(:mode)
75
78
  end
76
79
  end
77
80
 
@@ -10,11 +10,8 @@ module Rbtclk
10
10
  def load_config
11
11
  dot_rbtclk_in_home = File.expand_path(".rbtclk", "~")
12
12
 
13
- if File.exist?(dot_rbtclk_in_home)
14
- load dot_rbtclk_in_home
15
- else
16
- load File.expand_path("../../../config/default.rb", __FILE__)
17
- end
13
+ load File.expand_path("../../../config/default.rb", __FILE__)
14
+ load dot_rbtclk_in_home if File.exist?(dot_rbtclk_in_home)
18
15
  end
19
16
 
20
17
  # Methods for configuration DSL
@@ -22,9 +19,12 @@ module Rbtclk
22
19
  self.instance_eval(&block)
23
20
  end
24
21
 
25
- %w(mode font format color time).each do |attr|
22
+ %w(mode font format color time no_alarm).each do |attr|
26
23
  define_method "#{attr}=" do |value|
27
- const_set attr.to_s.upcase, value
24
+ const_name = attr.to_s.upcase
25
+
26
+ remove_const const_name if const_defined?(const_name)
27
+ const_set const_name, value
28
28
  end
29
29
  end
30
30
  end
@@ -6,17 +6,20 @@
6
6
  require "artii"
7
7
  require "curses"
8
8
  require "rbtclk/color_code"
9
+ require "rbtclk/sound_player"
9
10
 
10
11
  module Rbtclk
11
12
  class CountdownTimer
12
13
  include ColorCode
13
14
 
14
- def initialize(font: "clb8x8", format: "%X", color: "black", time: 180)
15
+ def initialize(font: "clb8x8", format: "%X", color: "black", time: 180, no_alarm: false)
15
16
  @artii = Artii::Base.new(font: font)
16
17
  @format = format
17
18
  @color = color
18
19
  @time = time.to_i
20
+ @no_alarm = no_alarm
19
21
  @elapsed = 0
22
+ @sound_player = SoundPlayer.new
20
23
  end
21
24
 
22
25
  def show
@@ -37,10 +40,12 @@ module Rbtclk
37
40
  sleep 1
38
41
  end
39
42
 
43
+ @sound_player.play unless @no_alarm
44
+
40
45
  toggle_marker = true
41
46
  loop do
42
47
  blink(toggle_marker)
43
- is_even = !is_even
48
+ toggle_marker = !toggle_marker
44
49
  sleep 1
45
50
  end
46
51
  end
@@ -0,0 +1,32 @@
1
+ # Rbtclk
2
+ # Copyright (c) 2014 Moza USANE
3
+ # This software is released under the MIT License.
4
+ # http://opensource.org/licenses/mit-license.php
5
+
6
+ require "open3"
7
+
8
+ module Rbtclk
9
+ class SoundPlayer
10
+ def initialize
11
+ sound_file_path = File.expand_path("../../../sound/bell.mp3", __FILE__)
12
+
13
+ @command_line = if command_exist?("afplay")
14
+ "afplay #{sound_file_path}"
15
+ elsif command_exist?("mpg123")
16
+ "mpg123 -q #{sound_file_path}"
17
+ else
18
+ ":" # do noghing
19
+ end
20
+ end
21
+
22
+ def play
23
+ spawn @command_line
24
+ end
25
+
26
+ private
27
+
28
+ def command_exist?(command)
29
+ Open3.capture3("which #{command}")[2].success?
30
+ end
31
+ end
32
+ end
@@ -4,5 +4,5 @@
4
4
  # http://opensource.org/licenses/mit-license.php
5
5
 
6
6
  module Rbtclk
7
- VERSION = "0.3.4"
7
+ VERSION = "0.4.0"
8
8
  end
Binary file
@@ -19,6 +19,7 @@ RSpec.describe Rbtclk::ConfigLoader do
19
19
  c.format = "cheshire-cat"
20
20
  c.color = "queen-of-hearts"
21
21
  c.time = "march-hare"
22
+ c.no_alarm = true
22
23
  end
23
24
  end
24
25
 
@@ -27,6 +28,7 @@ RSpec.describe Rbtclk::ConfigLoader do
27
28
  it { expect(target_klass::FORMAT).to eq "cheshire-cat" }
28
29
  it { expect(target_klass::COLOR).to eq "queen-of-hearts" }
29
30
  it { expect(target_klass::TIME).to eq "march-hare" }
31
+ it { expect(target_klass::NO_ALARM).to eq true }
30
32
  end
31
33
 
32
34
  describe ".mode" do
@@ -53,4 +55,9 @@ RSpec.describe Rbtclk::ConfigLoader do
53
55
  before { target_klass.time = "march-hare" }
54
56
  it { expect(target_klass::TIME).to eq "march-hare" }
55
57
  end
58
+
59
+ describe ".no_alarm" do
60
+ before { target_klass.no_alarm = true }
61
+ it { expect(target_klass::NO_ALARM).to eq true }
62
+ end
56
63
  end
@@ -28,7 +28,8 @@ RSpec.describe Rbtclk do
28
28
  font: "clb8x8",
29
29
  format: "%X",
30
30
  color: "black",
31
- time: "180"}
31
+ time: "180",
32
+ no_alarm: false}
32
33
  end
33
34
 
34
35
  before do
@@ -60,31 +61,35 @@ RSpec.describe Rbtclk do
60
61
  describe "#remove_extra_params" do
61
62
  context "params contains :mode value" do
62
63
  let(:params_that_has_no_mode) do
63
- filled_params.delete(:mode)
64
- filled_params
64
+ dup_params = filled_params.dup
65
+ dup_params.delete(:mode)
66
+ dup_params
65
67
  end
66
68
 
67
- let(:params_that_has_no_mode_and_no_time) do
68
- params_that_has_no_mode.delete(:time)
69
- params_that_has_no_mode
69
+ let(:params_that_has_no_mode_and_no_time_and_no_alarm) do
70
+ dup_params = params_that_has_no_mode.dup
71
+ dup_params.delete(:time)
72
+ dup_params.delete(:no_alarm)
73
+ dup_params
70
74
  end
71
75
 
72
76
  context "mode is clock" do
73
77
  specify ":mode and :time values are removed" do
74
78
  Rbtclk.remove_extra_params(filled_params)
75
- expect(filled_params).to eq params_that_has_no_mode_and_no_time
79
+ expect(filled_params).to eql params_that_has_no_mode_and_no_time_and_no_alarm
76
80
  end
77
81
  end
78
82
 
79
83
  context "mode is countdown" do
80
84
  let(:filled_params_whose_mode_is_clock) do
81
- filled_params[:mode] = "countdown"
82
- filled_params
85
+ dup_params = filled_params.dup
86
+ dup_params[:mode] = "countdown"
87
+ dup_params
83
88
  end
84
89
 
85
90
  specify ":mode and :time values are removed" do
86
- Rbtclk.remove_extra_params(filled_params)
87
- expect(filled_params_whose_mode_is_clock).to eq params_that_has_no_mode
91
+ Rbtclk.remove_extra_params(filled_params_whose_mode_is_clock)
92
+ expect(filled_params_whose_mode_is_clock).to eql params_that_has_no_mode
88
93
  end
89
94
  end
90
95
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbtclk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moza USANE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-06 00:00:00.000000000 Z
11
+ date: 2015-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -131,8 +131,10 @@ files:
131
131
  - lib/rbtclk/config_loader.rb
132
132
  - lib/rbtclk/countdown_timer.rb
133
133
  - lib/rbtclk/countup_timer.rb
134
+ - lib/rbtclk/sound_player.rb
134
135
  - lib/rbtclk/version.rb
135
136
  - rbtclk.gemspec
137
+ - sound/bell.mp3
136
138
  - spec/rbtclk/color_code_spec.rb
137
139
  - spec/rbtclk/config_loader_spec.rb
138
140
  - spec/rbtclk_spec.rb