sometimes 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/rubyCI.yml +20 -0
- data/README.md +16 -1
- data/lib/sometimes.rb +20 -6
- data/lib/sometimes/version.rb +1 -1
- data/sometimes.gemspec +3 -1
- data/test/helper.rb +1 -1
- data/test/test_sometimes.rb +47 -1
- metadata +33 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ccb9ae4d24901c0c3e8c281b0a472757886b960114efd2522a98e541eaf62979
|
4
|
+
data.tar.gz: 31f5ea8578f47a910f01053ac0ac5d7173a19875253e5ce6470b63a1c4b70b02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de1851cdd5e43008141669e83f67d7d9a288c50831534e27091f9c05263eba54388601cb14ba842abd863610603d2e56388d0785150f24e93dbb11f322de221e
|
7
|
+
data.tar.gz: 736c27a6b843706b1aef4cfeeb06ebb6e982db39f35cbb4c977abe7aea4fbe4721601e49014a5b50143450b8df98e2ec15fca38791509ac4f8a91de7f5317013
|
@@ -0,0 +1,20 @@
|
|
1
|
+
name: Ruby CI
|
2
|
+
|
3
|
+
on: [push, pull_request] # push OR PR
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
matrix:
|
10
|
+
ruby-version: [2.7, 3.0]
|
11
|
+
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
|
15
|
+
- name: Set up Ruby and Bundle Install
|
16
|
+
uses: ruby/setup-ruby@v1
|
17
|
+
with:
|
18
|
+
ruby-version: ${{ matrix.ruby-version }}
|
19
|
+
bundler-cache: true
|
20
|
+
- run: bundle exec rake
|
data/README.md
CHANGED
@@ -58,7 +58,7 @@ Maybe you want to remind someone of something, but not toooo often (It gets anno
|
|
58
58
|
puts "Howdy, Don't forget to register!" # be annoying, but only 15% of the time
|
59
59
|
end
|
60
60
|
|
61
|
-
33.
|
61
|
+
33.percent_of_the_time do
|
62
62
|
be_very_polite
|
63
63
|
end
|
64
64
|
```
|
@@ -75,6 +75,21 @@ end
|
|
75
75
|
end
|
76
76
|
```
|
77
77
|
|
78
|
+
If you can't say something nice, don't say anything at all:
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
never do
|
82
|
+
puts "You're a terrible person"
|
83
|
+
end
|
84
|
+
```
|
85
|
+
|
86
|
+
Always remember your manners:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
always do
|
90
|
+
puts "Thanks for sharing!"
|
91
|
+
end
|
92
|
+
```
|
78
93
|
## Why?
|
79
94
|
|
80
95
|
This gem was made so [alonetone](http://github.com/sudara/alonetone) could bit more fun when displaying notices and communicating to our users.
|
data/lib/sometimes.rb
CHANGED
@@ -19,8 +19,13 @@ require "sometimes/version"
|
|
19
19
|
# 40.percent_of_the_time do
|
20
20
|
class Integer
|
21
21
|
def percent_of_the_time(&block)
|
22
|
-
|
23
|
-
|
22
|
+
return if self == 0
|
23
|
+
|
24
|
+
if self < 0 || self > 100
|
25
|
+
raise(ArgumentError, 'Integer should be between 0 and 100 to be used with the percent_of_the_time method')
|
26
|
+
else
|
27
|
+
yield block if Kernel.rand(1..100) <= self
|
28
|
+
end
|
24
29
|
end
|
25
30
|
end
|
26
31
|
|
@@ -35,12 +40,21 @@ end
|
|
35
40
|
# sometimes do
|
36
41
|
class Object
|
37
42
|
def half_the_time(&block)
|
38
|
-
50.percent_of_the_time
|
43
|
+
50.percent_of_the_time(&block)
|
39
44
|
end
|
40
|
-
alias
|
45
|
+
alias sometimes half_the_time
|
41
46
|
|
42
47
|
def rarely(&block)
|
43
|
-
5.percent_of_the_time
|
48
|
+
5.percent_of_the_time(&block)
|
49
|
+
end
|
50
|
+
|
51
|
+
def mostly(&block)
|
52
|
+
95.percent_of_the_time(&block)
|
44
53
|
end
|
45
|
-
end
|
46
54
|
|
55
|
+
def never(&block); end
|
56
|
+
|
57
|
+
def always
|
58
|
+
yield
|
59
|
+
end
|
60
|
+
end
|
data/lib/sometimes/version.rb
CHANGED
data/sometimes.gemspec
CHANGED
@@ -14,6 +14,8 @@ Gem::Specification.new do |gem|
|
|
14
14
|
|
15
15
|
gem.files = `git ls-files`.split($/)
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
-
gem.test_files = gem.files.grep(%r{^(test
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test)/})
|
18
|
+
gem.add_development_dependency("rake")
|
19
|
+
gem.add_development_dependency("test-unit")
|
18
20
|
gem.require_paths = ["lib"]
|
19
21
|
end
|
data/test/helper.rb
CHANGED
data/test/test_sometimes.rb
CHANGED
@@ -3,6 +3,17 @@ require 'sometimes'
|
|
3
3
|
require 'helper'
|
4
4
|
|
5
5
|
class SometimesTest < Test::Unit::TestCase
|
6
|
+
def test_sometimes
|
7
|
+
i = 0
|
8
|
+
100000.times do
|
9
|
+
sometimes do
|
10
|
+
i += 1
|
11
|
+
end
|
12
|
+
end
|
13
|
+
puts i
|
14
|
+
assert (i < 51000) && (i > 49000)
|
15
|
+
end
|
16
|
+
|
6
17
|
def test_ranges
|
7
18
|
i = 0
|
8
19
|
(25..50).times { i += 1 }
|
@@ -31,6 +42,16 @@ class SometimesTest < Test::Unit::TestCase
|
|
31
42
|
assert i < 8000
|
32
43
|
end
|
33
44
|
|
45
|
+
def test_mostly
|
46
|
+
i = 0
|
47
|
+
100000.times do
|
48
|
+
mostly do
|
49
|
+
i += 1
|
50
|
+
end
|
51
|
+
end
|
52
|
+
assert i > 90000
|
53
|
+
end
|
54
|
+
|
34
55
|
def test_99
|
35
56
|
i = 0
|
36
57
|
100000.times do
|
@@ -51,4 +72,29 @@ class SometimesTest < Test::Unit::TestCase
|
|
51
72
|
assert i < 1100
|
52
73
|
end
|
53
74
|
|
54
|
-
|
75
|
+
def test_0
|
76
|
+
bool = true
|
77
|
+
100000.times do
|
78
|
+
0.percent_of_the_time do
|
79
|
+
bool = false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
assert_equal true, bool
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_never
|
86
|
+
bool = true
|
87
|
+
never do
|
88
|
+
bool = false
|
89
|
+
end
|
90
|
+
assert_equal true, bool
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_always
|
94
|
+
bool = false
|
95
|
+
always do
|
96
|
+
bool = true
|
97
|
+
end
|
98
|
+
assert_equal true, bool
|
99
|
+
end
|
100
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sometimes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sudara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2021-02-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: test-unit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
description: Be random. Be unpredictable. But only sometimes
|
14
42
|
email:
|
15
43
|
- sudara@alonetone.com
|
@@ -17,6 +45,7 @@ executables: []
|
|
17
45
|
extensions: []
|
18
46
|
extra_rdoc_files: []
|
19
47
|
files:
|
48
|
+
- ".github/workflows/rubyCI.yml"
|
20
49
|
- ".gitignore"
|
21
50
|
- Gemfile
|
22
51
|
- LICENSE.txt
|
@@ -45,8 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
74
|
- !ruby/object:Gem::Version
|
46
75
|
version: '0'
|
47
76
|
requirements: []
|
48
|
-
|
49
|
-
rubygems_version: 2.6.11
|
77
|
+
rubygems_version: 3.1.2
|
50
78
|
signing_key:
|
51
79
|
specification_version: 4
|
52
80
|
summary: Be random. Be unpredictable. But only sometimes
|