lps 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/lps.rb CHANGED
@@ -3,22 +3,14 @@ require 'option_initializer'
3
3
 
4
4
  class LPS
5
5
  include OptionInitializer
6
- option_initializer! :freq, :interval, :while
7
- option_validator do |k, v|
8
- case k
9
- when :freq
10
- raise ArgumentError,
11
- 'frequency must be a positive number (or nil)' unless
12
- v.nil? || (v.is_a?(Numeric) && v > 0)
13
- when :interval
14
- raise ArgumentError,
15
- 'interval must be a positive number (or zero)' unless
16
- v.is_a?(Numeric) && v >= 0
17
- when :while
18
- raise ArgumentError,
19
- 'loop condition must respond to call' unless
20
- v.respond_to?(:call)
21
- end
6
+ option_initializer! :freq, :interval => Numeric, :while => :&
7
+ option_validator :freq do |v|
8
+ msg = 'frequency must be a positive number (or nil)'
9
+ raise TypeError, msg unless v.is_a?(Numeric) || v.nil?
10
+ raise ArgumentError, msg if v.is_a?(Numeric) && v <= 0
11
+ end
12
+ option_validator :interval do |v|
13
+ raise ArgumentError, 'interval must be a non-negative number' if v < 0
22
14
  end
23
15
 
24
16
  # @param [Proc] &block Loop
data/lib/lps/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class LPS
2
- VERSION = '0.1.3'
2
+ VERSION = '0.2.0'
3
3
  end
data/lps.gemspec CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = LPS::VERSION
17
17
 
18
- gem.add_runtime_dependency 'option_initializer', '~> 1.2.0'
18
+ gem.add_runtime_dependency 'option_initializer', '~> 1.5.0'
19
19
  gem.add_development_dependency 'test-unit'
20
20
  gem.add_development_dependency 'guard'
21
21
  gem.add_development_dependency 'guard-test'
data/test/test_lps.rb CHANGED
@@ -30,12 +30,18 @@ class TestLPS < Test::Unit::TestCase
30
30
  end
31
31
 
32
32
  def test_non_positive_frequency
33
+ assert_raise(ArgumentError) { LPS.freq {} }
34
+ assert_raise(ArgumentError) { LPS.freq }
33
35
  assert_raise(ArgumentError) { LPS.freq(0) }
34
36
  assert_raise(ArgumentError) { LPS.freq(-1) }
37
+ assert_raise(ArgumentError) { LPS.freq(1, 1) }
35
38
  end
36
39
 
37
40
  def test_invalid_interval
41
+ assert_raise(ArgumentError) { LPS.interval {} }
42
+ assert_raise(ArgumentError) { LPS.interval }
38
43
  assert_raise(ArgumentError) { LPS.interval(-1) }
44
+ assert_raise(ArgumentError) { LPS.interval(1, 1) }
39
45
  end
40
46
 
41
47
  def test_both_freq_and_interval
@@ -44,8 +50,8 @@ class TestLPS < Test::Unit::TestCase
44
50
  end
45
51
 
46
52
  def test_non_number_params
47
- assert_raise(ArgumentError) { LPS.freq('bad') }
48
- assert_raise(ArgumentError) { LPS.interval('bad') }
53
+ assert_raise(TypeError) { LPS.freq('bad') }
54
+ assert_raise(TypeError) { LPS.interval('bad') }
49
55
  assert_raise(ArgumentError) { LPS.while('bad') }
50
56
  end
51
57
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lps
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
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: 2013-03-04 00:00:00.000000000 Z
12
+ date: 2013-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: option_initializer
@@ -18,7 +18,7 @@ dependencies:
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 1.2.0
21
+ version: 1.5.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ~>
28
28
  - !ruby/object:Gem::Version
29
- version: 1.2.0
29
+ version: 1.5.0
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: test-unit
32
32
  requirement: !ruby/object:Gem::Requirement