polling 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/lib/polling.rb CHANGED
@@ -13,6 +13,7 @@ module Polling
13
13
  loop do
14
14
  arr.each do |time|
15
15
  time = Confirm::check_value(time)
16
+ time = 0 if args[:start] && time >= 60
16
17
  Sleep::exec Target::interval(time,args)
17
18
  args[:start] = false
18
19
  yield
@@ -10,7 +10,8 @@ module Polling
10
10
  def check_arr(arr)
11
11
  if arr.count == 1
12
12
  time = convert(arr[0])
13
- arr = time < 60 ? create_arr(time) : [time]
13
+ #arr = time < 60 ? create_arr(time) : [time]
14
+ arr = create_arr(time)
14
15
  raise TypeError, "Please set a value that is divisible by 60." if (60 % time != 0) && time < 60
15
16
  end
16
17
  return arr
@@ -34,11 +35,15 @@ module Polling
34
35
 
35
36
  def create_arr(time)
36
37
  arr = Array.new
37
- arr << 0 if time != 0
38
- result = time
39
- while time < 60
38
+ if time < 60
39
+ arr << 0 if time != 0
40
+ result = time
41
+ while time < 60
42
+ arr << time
43
+ time += result
44
+ end
45
+ else
40
46
  arr << time
41
- time += result
42
47
  end
43
48
  return arr
44
49
  end
@@ -1,3 +1,3 @@
1
1
  module Polling
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.7"
3
3
  end
data/test/test_confirm.rb CHANGED
@@ -6,16 +6,23 @@ class PollingTest < Test::Unit::TestCase
6
6
  assert_equal 0, Polling::Confirm::check_value("0")
7
7
  assert_equal 60, Polling::Confirm::check_value(60)
8
8
  assert_equal 5, Polling::Confirm::check_value("5")
9
+ end
9
10
 
11
+ def test_convert
10
12
  assert_equal 5, Polling::Confirm::convert(5)
11
13
  assert_equal 5, Polling::Confirm::convert("5")
12
14
  assert_equal 5, Polling::Confirm::convert("5s")
13
15
  assert_equal 300, Polling::Confirm::convert("5m")
14
16
  assert_equal 18000, Polling::Confirm::convert("5h")
17
+ end
15
18
 
19
+ def test_check_arr
16
20
  assert_equal ["0","10","20","30","40","50"], Polling::Confirm::check_arr(["0","10","20","30","40","50"])
17
21
  assert_equal [0,10,20,30,40,50], Polling::Confirm::check_arr([0,10,20,30,40,50])
18
22
  assert_equal [0,10,20,30,40,50], Polling::Confirm::check_arr(["10s"])
23
+ assert_equal [60], Polling::Confirm::check_arr(["1m"])
24
+ assert_equal [120], Polling::Confirm::check_arr(["2m"])
25
+ assert_equal [1800], Polling::Confirm::check_arr(["30m"])
19
26
  assert_equal [0,10,20,30,40,50], Polling::Confirm::check_arr(["10"])
20
27
  assert_equal [0,10,20,30,40,50], Polling::Confirm::check_arr([10])
21
28
  assert_equal [0,30], Polling::Confirm::check_arr([30])
data/test/test_run.rb CHANGED
@@ -5,7 +5,8 @@ class PollingTest < Test::Unit::TestCase
5
5
  # puts "start: #{Time.now}"
6
6
  # #arr = [5,15,25,35,45,55]
7
7
  # #arr = ["0","10","20","30","40","50"]
8
- # arr = ["10s"]
8
+ # #arr = ["10s"]
9
+ # arr = ["3m"]
9
10
  # Polling::run(arr,true) do
10
11
  # puts Time.now
11
12
  # sleep 2
data/test/test_target.rb CHANGED
@@ -23,6 +23,9 @@ class PollingTest < Test::Unit::TestCase
23
23
  assert_equal 300, Polling::Target::interval(300,debug)
24
24
  assert_equal 300, Polling::Target::interval(300,debug)
25
25
  assert_equal 3600, Polling::Target::interval(3600,debug)
26
+
27
+ Time.stubs(:now).returns(Time.parse "2012/11/19 10:16:00")
28
+ assert_equal 300, Polling::Target::interval(300,debug)
26
29
  end
27
30
 
28
31
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polling
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-18 00:00:00.000000000 Z
12
+ date: 2012-11-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: polling
15
15
  email: