rbtclk 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0793a8daa998be3e4bd67ee152329152f5cc4f20
4
- data.tar.gz: 382a9757c3c86e232fc562b61bb58f5fb897a0bf
3
+ metadata.gz: 17fc4da29cb43bc63ccbf700de720b9996ec3f01
4
+ data.tar.gz: c5032087f6b07e91ca96feb74f0a7dd72589ae53
5
5
  SHA512:
6
- metadata.gz: 2f6d0c98deb4bb04f9ae49fece0bd3cd9a8ebd326b4b50edfa834b283be2d8b2efebc4d312008c1ee26b8b0f121eb249c32dbbe469afc58b4993c1b401ba4a41
7
- data.tar.gz: aa4e72554bd9183a3136c39ecb7bf70461d8df62ba53cbffc888f1250cef2fe642f897faf94dce93e5a761937d1ee1e12e6f3da324be1901ad9953e65743e4b1
6
+ metadata.gz: 99ac089abae20f02e34767571df0cae822c6e40ac0316b5f9578e335abc494f0fc5021d3838600833b2b100df9df77474bd901abf63ea34c3b1306a184756225
7
+ data.tar.gz: 6d317ba43f872d80fbf61d1742e1404b2e04d26a11ab37fecd2b04c43904b5b203bef70ad0674f3abb640f66022a5c1e00cff99907c59c8068a362bf20ecfac6
data/config/default.rb ADDED
@@ -0,0 +1,24 @@
1
+ # rbtclk sample configuration file
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
+ Rbtclk.configure do |c|
7
+ # clock, countup and countdown are available.
8
+ c.mode = "timer"
9
+
10
+ # Font setting depends on Artii library.
11
+ # https://github.com/miketierney/artii/tree/master/lib/figlet/fonts
12
+ # You can use a lot of font types.
13
+ c.font = "clb8x8"
14
+
15
+ # You can use Ruby's Date#strftime style.
16
+ # It is compatible with strftime(3) of standard C library.
17
+ c.format = "%X"
18
+
19
+ # black, red, green, yellow, blue, magenta, cyan and white are available.
20
+ c.color = "black"
21
+
22
+ # You can specify limit time as seconds in countdown timer.
23
+ c.time = "180"
24
+ end
data/lib/rbtclk.rb CHANGED
@@ -56,15 +56,42 @@ module Rbtclk
56
56
  end
57
57
 
58
58
  def fill(params)
59
- {mode: params[:mode] || "clock",
60
- font: params[:font] || "clb8x8",
61
- format: params[:format] || "%X",
62
- color: params[:color] || "black",
63
- time: params[:time] || "180"}
59
+ {mode: params[:mode] || MODE,
60
+ font: params[:font] || FONT,
61
+ format: params[:format] || FORMAT,
62
+ color: params[:color] || COLOR,
63
+ time: params[:time] || TIME}
64
64
  end
65
65
 
66
66
  def remove_extra_params(params)
67
67
  params.delete(:mode)
68
+
69
+ if params[:mode] != "countdown"
70
+ params.delete(:time)
71
+ end
72
+ end
73
+
74
+ def load_config
75
+ dot_rbtclk_in_home = File.expand_path(".rbtclk", "~")
76
+
77
+ if File.exist?(dot_rbtclk_in_home)
78
+ load dot_rbtclk_in_home
79
+ else
80
+ load File.expand_path("../../config/default.rb", __FILE__)
81
+ end
82
+ end
83
+
84
+ # Methods for configuration DSL
85
+ def configure(&block)
86
+ Rbtclk.instance_eval(&block)
87
+ end
88
+
89
+ %w(mode font format color time).each do |attr|
90
+ define_method "#{attr}=" do |value|
91
+ const_set attr.to_s.upcase, value
92
+ end
68
93
  end
69
94
  end
95
+
96
+ load_config
70
97
  end
@@ -4,5 +4,5 @@
4
4
  # http://opensource.org/licenses/mit-license.php
5
5
 
6
6
  module Rbtclk
7
- VERSION = "0.3.1"
7
+ VERSION = "0.3.2"
8
8
  end
data/spec/rbtclk_spec.rb CHANGED
@@ -31,6 +31,14 @@ RSpec.describe Rbtclk do
31
31
  time: "180"}
32
32
  end
33
33
 
34
+ before do
35
+ filled_params.each do |attribute, value|
36
+ const_name = attribute.to_s.upcase
37
+ Rbtclk.send(:remove_const, const_name)
38
+ Rbtclk.const_set(const_name, value)
39
+ end
40
+ end
41
+
34
42
  describe "#fill" do
35
43
  context "there are no blank elements in the argument" do
36
44
  subject { Rbtclk.fill(filled_params) }
@@ -50,15 +58,34 @@ RSpec.describe Rbtclk do
50
58
  end
51
59
 
52
60
  describe "#remove_extra_params" do
53
- let(:params_that_has_no_mode) do
54
- filled_params.delete(:mode)
55
- filled_params
56
- end
57
-
58
61
  context "params contains :mode value" do
59
- specify ":mode value is removed" do
60
- Rbtclk.remove_extra_params(filled_params)
61
- expect(filled_params).to eq params_that_has_no_mode
62
+ let(:params_that_has_no_mode) do
63
+ filled_params.delete(:mode)
64
+ filled_params
65
+ end
66
+
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
70
+ end
71
+
72
+ context "mode is clock" do
73
+ specify ":mode and :time values are removed" do
74
+ Rbtclk.remove_extra_params(filled_params)
75
+ expect(filled_params).to eq params_that_has_no_mode_and_no_time
76
+ end
77
+ end
78
+
79
+ context "mode is countdown" do
80
+ let(:filled_params_whose_mode_is_clock) do
81
+ filled_params[:mode] = "countdown"
82
+ filled_params
83
+ end
84
+
85
+ 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
88
+ end
62
89
  end
63
90
  end
64
91
  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.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moza USANE
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-26 00:00:00.000000000 Z
11
+ date: 2014-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -124,6 +124,7 @@ files:
124
124
  - README.md
125
125
  - Rakefile
126
126
  - bin/rbtclk
127
+ - config/default.rb
127
128
  - lib/rbtclk.rb
128
129
  - lib/rbtclk/clock.rb
129
130
  - lib/rbtclk/color_code.rb