frequency-dsl 0.0.3 → 0.0.4
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.
- data/LICENSE +10 -23
- data/README.rdoc +11 -1
- data/VERSION +1 -1
- data/frequency-dsl.gemspec +1 -1
- data/lib/frequency.rb +3 -2
- data/spec/frequency_spec.rb +15 -2
- metadata +3 -3
data/LICENSE
CHANGED
|
@@ -1,27 +1,14 @@
|
|
|
1
1
|
Copyright (c) 2010, Tiago Peczenyj
|
|
2
2
|
All rights reserved.
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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.
|
data/README.rdoc
CHANGED
|
@@ -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
|
-
|
|
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.
|
|
1
|
+
0.0.4
|
data/frequency-dsl.gemspec
CHANGED
data/lib/frequency.rb
CHANGED
|
@@ -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 =~
|
|
35
|
+
Float(rate.gsub(/%$/,""))/100 if rate =~ /^-?\d+(.\d+)?%$/
|
|
35
36
|
end
|
|
36
37
|
end
|
data/spec/frequency_spec.rb
CHANGED
|
@@ -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:
|
|
4
|
+
hash: 23
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 0
|
|
9
|
-
-
|
|
10
|
-
version: 0.0.
|
|
9
|
+
- 4
|
|
10
|
+
version: 0.0.4
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Tiago Peczenyj
|