frequency-dsl 0.0.7 → 0.0.8
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/VERSION +1 -1
- data/lib/frequency.rb +2 -0
- data/rdoc/classes/Frequency.html +32 -17
- data/rdoc/created.rid +1 -1
- data/rdoc/files/lib/frequency_rb.html +1 -1
- data/rdoc/fr_method_index.html +3 -2
- data/rdoc/index.html +2 -2
- data/spec/frequency_spec.rb +47 -21
- metadata +4 -5
- data/frequency-dsl.gemspec +0 -61
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.8
|
data/lib/frequency.rb
CHANGED
data/rdoc/classes/Frequency.html
CHANGED
@@ -75,7 +75,7 @@
|
|
75
75
|
<div id="description">
|
76
76
|
<p>
|
77
77
|
Module <a href="Frequency.html">Frequency</a> A small dsl written in ruby
|
78
|
-
to work with frequency events (<a href="Frequency.html#
|
78
|
+
to work with frequency events (<a href="Frequency.html#M000006">never</a>,
|
79
79
|
<a href="Frequency.html#M000003">sometimes</a>, <a
|
80
80
|
href="Frequency.html#M000001">always</a>..)
|
81
81
|
</p>
|
@@ -90,9 +90,10 @@ href="Frequency.html#M000001">always</a>..)
|
|
90
90
|
|
91
91
|
<div class="name-list">
|
92
92
|
<a href="#M000001">always</a>
|
93
|
-
<a href="#
|
93
|
+
<a href="#M000004">maybe</a>
|
94
|
+
<a href="#M000006">never</a>
|
94
95
|
<a href="#M000002">normally</a>
|
95
|
-
<a href="#
|
96
|
+
<a href="#M000005">rarely</a>
|
96
97
|
<a href="#M000003">sometimes</a>
|
97
98
|
</div>
|
98
99
|
</div>
|
@@ -167,27 +168,41 @@ href="Frequency.html#M000001">always</a>..)
|
|
167
168
|
</div>
|
168
169
|
</div>
|
169
170
|
|
170
|
-
<div id="method-
|
171
|
-
<a name="
|
171
|
+
<div id="method-M000004" class="method-detail">
|
172
|
+
<a name="M000004"></a>
|
172
173
|
|
173
174
|
<div class="method-heading">
|
174
|
-
<
|
175
|
+
<span class="method-name">maybe</span><span class="method-args">(cond={})</span>
|
176
|
+
</div>
|
177
|
+
|
178
|
+
<div class="method-description">
|
179
|
+
<p>
|
180
|
+
Alias for <a href="Frequency.html#M000003">sometimes</a>
|
181
|
+
</p>
|
182
|
+
</div>
|
183
|
+
</div>
|
184
|
+
|
185
|
+
<div id="method-M000006" class="method-detail">
|
186
|
+
<a name="M000006"></a>
|
187
|
+
|
188
|
+
<div class="method-heading">
|
189
|
+
<a href="#M000006" class="method-signature">
|
175
190
|
<span class="method-name">never</span><span class="method-args">(cond={})</span>
|
176
191
|
</a>
|
177
192
|
</div>
|
178
193
|
|
179
194
|
<div class="method-description">
|
180
195
|
<p>
|
181
|
-
<a href="Frequency.html#
|
196
|
+
<a href="Frequency.html#M000006">never</a> do something example:
|
182
197
|
</p>
|
183
198
|
<pre>
|
184
199
|
never { puts "ok"}
|
185
200
|
</pre>
|
186
201
|
<p><a class="source-toggle" href="#"
|
187
|
-
onclick="toggleCode('
|
188
|
-
<div class="method-source-code" id="
|
202
|
+
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
203
|
+
<div class="method-source-code" id="M000006-source">
|
189
204
|
<pre>
|
190
|
-
<span class="ruby-comment cmt"># File lib/frequency.rb, line
|
205
|
+
<span class="ruby-comment cmt"># File lib/frequency.rb, line 52</span>
|
191
206
|
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">never</span>(<span class="ruby-identifier">cond</span>={})
|
192
207
|
<span class="ruby-keyword kw">nil</span>
|
193
208
|
<span class="ruby-keyword kw">end</span>
|
@@ -226,28 +241,28 @@ href="Frequency.html#M000003">sometimes</a> method example:
|
|
226
241
|
</div>
|
227
242
|
</div>
|
228
243
|
|
229
|
-
<div id="method-
|
230
|
-
<a name="
|
244
|
+
<div id="method-M000005" class="method-detail">
|
245
|
+
<a name="M000005"></a>
|
231
246
|
|
232
247
|
<div class="method-heading">
|
233
|
-
<a href="#
|
248
|
+
<a href="#M000005" class="method-signature">
|
234
249
|
<span class="method-name">rarely</span><span class="method-args">(cond={}) {|| ...}</span>
|
235
250
|
</a>
|
236
251
|
</div>
|
237
252
|
|
238
253
|
<div class="method-description">
|
239
254
|
<p>
|
240
|
-
<a href="Frequency.html#
|
255
|
+
<a href="Frequency.html#M000005">rarely</a> (25%) do something, see <a
|
241
256
|
href="Frequency.html#M000003">sometimes</a> method example:
|
242
257
|
</p>
|
243
258
|
<pre>
|
244
259
|
rarely { puts "ok"}
|
245
260
|
</pre>
|
246
261
|
<p><a class="source-toggle" href="#"
|
247
|
-
onclick="toggleCode('
|
248
|
-
<div class="method-source-code" id="
|
262
|
+
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
263
|
+
<div class="method-source-code" id="M000005-source">
|
249
264
|
<pre>
|
250
|
-
<span class="ruby-comment cmt"># File lib/frequency.rb, line
|
265
|
+
<span class="ruby-comment cmt"># File lib/frequency.rb, line 45</span>
|
251
266
|
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rarely</span>(<span class="ruby-identifier">cond</span>={})
|
252
267
|
<span class="ruby-identifier">execute_with_probability</span>(<span class="ruby-identifier">cond</span>,<span class="ruby-constant">RARELY</span> ) { <span class="ruby-keyword kw">yield</span> } <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
253
268
|
<span class="ruby-keyword kw">end</span>
|
data/rdoc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Thu, 20 May 2010 12:59:23 -0300
|
data/rdoc/fr_method_index.html
CHANGED
@@ -21,9 +21,10 @@
|
|
21
21
|
<h1 class="section-bar">Methods</h1>
|
22
22
|
<div id="index-entries">
|
23
23
|
<a href="classes/Frequency.html#M000001">always (Frequency)</a><br />
|
24
|
-
<a href="classes/Frequency.html#
|
24
|
+
<a href="classes/Frequency.html#M000004">maybe (Frequency)</a><br />
|
25
|
+
<a href="classes/Frequency.html#M000006">never (Frequency)</a><br />
|
25
26
|
<a href="classes/Frequency.html#M000002">normally (Frequency)</a><br />
|
26
|
-
<a href="classes/Frequency.html#
|
27
|
+
<a href="classes/Frequency.html#M000005">rarely (Frequency)</a><br />
|
27
28
|
<a href="classes/Frequency.html#M000003">sometimes (Frequency)</a><br />
|
28
29
|
</div>
|
29
30
|
</div>
|
data/rdoc/index.html
CHANGED
@@ -5,13 +5,13 @@
|
|
5
5
|
|
6
6
|
<!--
|
7
7
|
|
8
|
-
frequency 0.0.
|
8
|
+
frequency 0.0.7
|
9
9
|
|
10
10
|
|
11
11
|
-->
|
12
12
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
13
13
|
<head>
|
14
|
-
<title>frequency 0.0.
|
14
|
+
<title>frequency 0.0.7
|
15
15
|
</title>
|
16
16
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
17
17
|
</head>
|
data/spec/frequency_spec.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
2
3
|
include Frequency
|
3
4
|
|
4
|
-
describe "Frequency" do
|
5
|
-
|
5
|
+
describe "Frequency" do
|
6
6
|
describe "always" do
|
7
7
|
it "should be execute always" do
|
8
8
|
always { true }.should be_true
|
@@ -15,50 +15,76 @@ describe "Frequency" do
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
describe "rarely" do
|
19
|
+
it "should be execute if rand() returns less than 0.25" do
|
20
|
+
Kernel.should_receive(:rand).with().and_return(0.24999)
|
21
|
+
rarely { true }.should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should not be execute if rand() returns more than 0.25" do
|
25
|
+
Kernel.should_receive(:rand).with().and_return(0.25)
|
26
|
+
rarely { true }.should be_nil
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "normally" do
|
31
|
+
it "should be execute if rand() returns less than 0.75" do
|
32
|
+
Kernel.should_receive(:rand).with().and_return(0.74999)
|
33
|
+
normally { true }.should be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should not be execute if rand() returns more than 0.75" do
|
37
|
+
Kernel.should_receive(:rand).with().and_return(0.75)
|
38
|
+
normally { true }.should be_nil
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
18
42
|
describe "sometimes" do
|
43
|
+
|
19
44
|
it "should be execute if rand() returns less than 0.50" do
|
20
45
|
Kernel.should_receive(:rand).with().and_return(0.14999)
|
21
46
|
sometimes { true }.should be_true
|
22
47
|
end
|
48
|
+
|
23
49
|
it "should not be execute if rand() returns more than 0.50" do
|
24
50
|
Kernel.should_receive(:rand).with().and_return(0.99)
|
25
51
|
sometimes { true }.should be_nil
|
26
52
|
end
|
53
|
+
|
27
54
|
it "should be execute if rand return less than 0.15" do
|
28
55
|
Kernel.should_receive(:rand).with().and_return(0.14999)
|
29
|
-
sometimes
|
30
|
-
true
|
31
|
-
end.should be_true
|
32
|
-
|
56
|
+
sometimes(:with_probability => 0.15){ true }.should be_true
|
33
57
|
end
|
58
|
+
|
34
59
|
it "should not be execute if rand return more than 0.15" do
|
35
60
|
Kernel.should_receive(:rand).with().and_return(0.15)
|
36
|
-
sometimes
|
37
|
-
true
|
38
|
-
end.should be_nil
|
39
|
-
|
61
|
+
sometimes(:with_probability => 0.15){ true }.should be_nil
|
40
62
|
end
|
63
|
+
|
41
64
|
it "should be execute if rand return less than 15%" do
|
42
65
|
Kernel.should_receive(:rand).with().and_return(0.149999)
|
43
|
-
sometimes
|
44
|
-
true
|
45
|
-
end.should be_true
|
46
|
-
|
66
|
+
sometimes(:with_probability => "15%"){ true }.should be_true
|
47
67
|
end
|
68
|
+
|
48
69
|
it "should be raise a exception if probability is more than 100%" do
|
49
70
|
lambda{
|
50
|
-
sometimes
|
51
|
-
true
|
52
|
-
end
|
71
|
+
sometimes(:with_probability => "101%"){ true }
|
53
72
|
}.should raise_exception(RuntimeError)
|
54
73
|
end
|
74
|
+
|
55
75
|
it "should be raise a exception if probability is less than 0%" do
|
56
76
|
lambda{
|
57
|
-
sometimes
|
58
|
-
true
|
59
|
-
end
|
77
|
+
sometimes(:with_probability => "-0.1%"){ true }
|
60
78
|
}.should raise_exception(RuntimeError)
|
61
|
-
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "maybe" do
|
84
|
+
it "hehe" do
|
85
|
+
Kernel.should_receive(:rand).with().and_return(0.99)
|
86
|
+
maybe { true }.should be_nil
|
87
|
+
end
|
62
88
|
end
|
63
89
|
|
64
90
|
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: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tiago Peczenyj
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-05-
|
18
|
+
date: 2010-05-20 00:00:00 -03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -46,7 +46,6 @@ files:
|
|
46
46
|
- README.rdoc
|
47
47
|
- Rakefile
|
48
48
|
- VERSION
|
49
|
-
- frequency-dsl.gemspec
|
50
49
|
- lib/frequency.rb
|
51
50
|
- rdoc/classes/Frequency.html
|
52
51
|
- rdoc/created.rid
|
data/frequency-dsl.gemspec
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
|
-
Gem::Specification.new do |s|
|
7
|
-
s.name = %q{frequency-dsl}
|
8
|
-
s.version = "0.0.7"
|
9
|
-
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = ["Tiago Peczenyj"]
|
12
|
-
s.date = %q{2010-05-19}
|
13
|
-
s.description = %q{A small dsl written in ruby to work with frequency events (never, sometimes, always..)}
|
14
|
-
s.email = %q{tiago.peczenyj@gmail.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
"LICENSE",
|
21
|
-
"README.rdoc",
|
22
|
-
"Rakefile",
|
23
|
-
"VERSION",
|
24
|
-
"frequency-dsl.gemspec",
|
25
|
-
"lib/frequency.rb",
|
26
|
-
"rdoc/classes/Frequency.html",
|
27
|
-
"rdoc/created.rid",
|
28
|
-
"rdoc/files/README_rdoc.html",
|
29
|
-
"rdoc/files/lib/frequency_rb.html",
|
30
|
-
"rdoc/fr_class_index.html",
|
31
|
-
"rdoc/fr_file_index.html",
|
32
|
-
"rdoc/fr_method_index.html",
|
33
|
-
"rdoc/index.html",
|
34
|
-
"rdoc/rdoc-style.css",
|
35
|
-
"spec/frequency_spec.rb",
|
36
|
-
"spec/spec_helper.rb"
|
37
|
-
]
|
38
|
-
s.homepage = %q{http://github.com/peczenyj/Frequency}
|
39
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
40
|
-
s.require_paths = ["lib"]
|
41
|
-
s.rubygems_version = %q{1.3.7}
|
42
|
-
s.summary = %q{A small dsl written in ruby to work with frequency events}
|
43
|
-
s.test_files = [
|
44
|
-
"spec/frequency_spec.rb",
|
45
|
-
"spec/spec_helper.rb"
|
46
|
-
]
|
47
|
-
|
48
|
-
if s.respond_to? :specification_version then
|
49
|
-
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
|
-
s.specification_version = 3
|
51
|
-
|
52
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
|
-
s.add_development_dependency(%q<rspec>, [">= 0"])
|
54
|
-
else
|
55
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
56
|
-
end
|
57
|
-
else
|
58
|
-
s.add_dependency(%q<rspec>, [">= 0"])
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|