frequency-dsl 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,27 +1,14 @@
1
1
  Copyright (c) 2010, Tiago Peczenyj
2
2
  All rights reserved.
3
3
 
4
- Redistribution and use in source and binary forms, with or without
5
- modification, are permitted provided that the following conditions are met:
6
- 1. Redistributions of source code must retain the above copyright
7
- notice, this list of conditions and the following disclaimer.
8
- 2. Redistributions in binary form must reproduce the above copyright
9
- notice, this list of conditions and the following disclaimer in the
10
- documentation and/or other materials provided with the distribution.
11
- 3. All advertising materials mentioning features or use of this software
12
- must display the following acknowledgement:
13
- This product includes software developed by the <organization>.
14
- 4. Neither the name of the <organization> nor the
15
- names of its contributors may be used to endorse or promote products
16
- derived from this software without specific prior written permission.
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
17
7
 
18
- THIS SOFTWARE IS PROVIDED BY Tiago Peczenyj ''AS IS'' AND ANY
19
- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
- DISCLAIMED. IN NO EVENT SHALL Tiago Peczenyj BE LIABLE FOR ANY
22
- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
@@ -4,6 +4,11 @@ Frequency is a small dsl written in ruby to work with frequency events (never, s
4
4
 
5
5
  == Examples
6
6
 
7
+ Frequency is easy...
8
+
9
+ require 'rubygems'
10
+ require 'frequency'
11
+
7
12
  include Frequency
8
13
 
9
14
  sometimes do
@@ -22,10 +27,15 @@ Frequency is a small dsl written in ruby to work with frequency events (never, s
22
27
  puts "you can use strings instead float numbers"
23
28
  end
24
29
 
25
- alwais do
30
+ always do
26
31
  puts "bye"
27
32
  end
28
33
 
34
+ the option with_probability does not work with never and always.
35
+
36
+ == Install
37
+ [sudo] gem install frequency-dsl
38
+
29
39
  == Copyright
30
40
 
31
41
  Copyright (c) 2010 Tiago Peczenyj. See LICENSE for details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{frequency-dsl}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tiago Peczenyj"]
@@ -26,11 +26,12 @@ module Frequency
26
26
  private
27
27
  def execute_with_probability(conditions,default)
28
28
  rate = conditions[:with_probability] || default
29
- rate = Float(rate) rescue correct_if_string(rate)
29
+ rate = Float(rate) rescue correct_if_string(rate)
30
+ raise "probability must be [0..100]%" unless 0 <= rate && rate <= 1
30
31
  yield if Kernel.rand() < rate
31
32
  end
32
33
 
33
34
  def correct_if_string(rate)
34
- Float(rate.gsub(/%$/,""))/100 if rate =~ /^\d+(.\d+)?%$/
35
+ Float(rate.gsub(/%$/,""))/100 if rate =~ /^-?\d+(.\d+)?%$/
35
36
  end
36
37
  end
@@ -45,7 +45,20 @@ describe "Frequency" do
45
45
  end.should be_true
46
46
 
47
47
  end
48
-
48
+ it "should be raise a exception if probability is more than 100%" do
49
+ lambda{
50
+ sometimes :with_probability => '101%' do
51
+ true
52
+ end
53
+ }.should raise_exception(RuntimeError)
54
+ end
55
+ it "should be raise a exception if probability is less than 0%" do
56
+ lambda{
57
+ sometimes :with_probability => '-1%' do
58
+ true
59
+ end
60
+ }.should raise_exception(RuntimeError)
61
+ end
49
62
  end
50
-
63
+
51
64
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frequency-dsl
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tiago Peczenyj