frequency-dsl 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -0,0 +1,52 @@
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.2"
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
+ "spec/frequency_spec.rb",
27
+ "spec/spec_helper.rb"
28
+ ]
29
+ s.homepage = %q{http://github.com/peczenyj/Frequency}
30
+ s.rdoc_options = ["--charset=UTF-8"]
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = %q{1.3.7}
33
+ s.summary = %q{A small dsl written in ruby to work with frequency events}
34
+ s.test_files = [
35
+ "spec/frequency_spec.rb",
36
+ "spec/spec_helper.rb"
37
+ ]
38
+
39
+ if s.respond_to? :specification_version then
40
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_development_dependency(%q<rspec>, [">= 0"])
45
+ else
46
+ s.add_dependency(%q<rspec>, [">= 0"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<rspec>, [">= 0"])
50
+ end
51
+ end
52
+
data/lib/frequency.rb CHANGED
@@ -3,29 +3,29 @@ module Frequency
3
3
  SOMETIMES = 0.50
4
4
  RARELY = 0.25
5
5
 
6
- def self.always(cond={})
6
+ def always(cond={})
7
7
  yield if block_given?
8
8
  end
9
9
 
10
- def self.normally(cond={})
11
- self.execute_with_probability(cond,NORMALLY ) { yield } if block_given?
10
+ def normally(cond={})
11
+ execute_with_probability(cond,NORMALLY ) { yield } if block_given?
12
12
  end
13
13
 
14
- def self.sometimes(cond={})
15
- self.execute_with_probability(cond,SOMETIMES) { yield } if block_given?
14
+ def sometimes(cond={})
15
+ execute_with_probability(cond,SOMETIMES) { yield } if block_given?
16
16
  end
17
17
 
18
- def self.rarely(cond={})
19
- self.execute_with_probability(cond,RARELY ) { yield } if block_given?
18
+ def rarely(cond={})
19
+ execute_with_probability(cond,RARELY ) { yield } if block_given?
20
20
  end
21
21
 
22
- def self.never(cond={})
22
+ def never(cond={})
23
23
  nil
24
24
  end
25
25
 
26
26
  private
27
- def self.execute_with_probability(conditions,default)
27
+ def execute_with_probability(conditions,default)
28
28
  rate = conditions[:with_probability] || default
29
29
  yield if Kernel.rand() < rate
30
30
  end
31
- end
31
+ end
@@ -1,24 +1,29 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ include Frequency
2
3
 
3
4
  describe "Frequency" do
4
-
5
+
5
6
  describe "always" do
6
-
7
7
  it "should be execute always" do
8
- Frequency.always { true }.should be_true
8
+ always { true }.should be_true
9
9
  end
10
+ end
11
+
12
+ describe "never" do
10
13
  it "should be not execute never" do
11
- Frequency.never { true }.should be_nil
14
+ never { true }.should be_nil
12
15
  end
16
+ end
17
+
18
+ describe "sometimes" do
13
19
  it "should be execute if rand() returns less than 0.50" do
14
20
  Kernel.should_receive(:rand).with().and_return(0.00)
15
- Frequency.sometimes { true }.should be_true
21
+ sometimes { true }.should be_true
16
22
  end
17
23
  it "should not be execute if rand() returns more than 0.50" do
18
24
  Kernel.should_receive(:rand).with().and_return(0.99)
19
- Frequency.sometimes { true }.should be_nil
25
+ sometimes { true }.should be_nil
20
26
  end
21
-
22
27
  end
23
28
 
24
29
  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: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tiago Peczenyj
@@ -46,8 +46,9 @@ files:
46
46
  - README.rdoc
47
47
  - Rakefile
48
48
  - VERSION
49
+ - frequency-dsl.gemspec
49
50
  - lib/frequency.rb
50
- - spec/frequency_helper.rb
51
+ - spec/frequency_spec.rb
51
52
  - spec/spec_helper.rb
52
53
  has_rdoc: true
53
54
  homepage: http://github.com/peczenyj/Frequency
@@ -84,5 +85,5 @@ signing_key:
84
85
  specification_version: 3
85
86
  summary: A small dsl written in ruby to work with frequency events
86
87
  test_files:
87
- - spec/frequency_helper.rb
88
+ - spec/frequency_spec.rb
88
89
  - spec/spec_helper.rb