chansu 0.1.0 â 0.1.1
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.
- checksums.yaml +4 -4
- data/README.md +105 -30
- data/chansu-0.1.0.gem +0 -0
- data/lib/chansu/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 367057f628d86ce66226f7997bafbeb9ab8d858cacc9aa1fd8f70afcbe60e9d6
|
|
4
|
+
data.tar.gz: 4fc96d800011066f267f1c377c80c3a171068f7302e8164c666492e78d8dff45
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 51d3a8fe17e2936802cd60a9bbde6ad961a74b8554f5754c27bff48bd05006be0f953c6e24cd88b299fa0fb979330c113db5bfc2603081a0d74b8a9c6030c53a
|
|
7
|
+
data.tar.gz: 144b2fd17763d88ab025ea9092c05d9d54bf82f9037befcf38c1d474bda4c160ab7439513ca7ba0179ae4a20a0a8d22aedba5dc9d9b0b0f19c4aebfa67069a0a
|
data/README.md
CHANGED
|
@@ -1,43 +1,118 @@
|
|
|
1
|
-
# Chansu
|
|
1
|
+
# Chansu đ˛
|
|
2
|
+
*A Ruby gem for probability-driven DSLs and dice rolls.*
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
**ããŖãŗãš** gives you cool ways to write code with probabilities, dice rolls, and randomness.
|
|
5
|
+
It comes with a natural-language DSL for describing likelihoods (`probably`, `rarely`, `always`, etc.) and utility methods like dice rolls (`d6`, `d20`, âĻ).
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
---
|
|
6
8
|
|
|
7
|
-
##
|
|
9
|
+
## ⨠Features
|
|
10
|
+
- đ˛ **Dice rolls**: `d6`, `d20`, `d100` and even ([dice notation](https://en.wikipedia.org/wiki/Dice_notation)).
|
|
11
|
+
- đ **Probability DSL**: Write code like:
|
|
12
|
+
```ruby
|
|
13
|
+
probably { puts "this happens ~60% of the time" }
|
|
14
|
+
rarely { puts "this almost never happens" }
|
|
15
|
+
always { puts "this always happens" }
|
|
8
16
|
|
|
9
|
-
|
|
17
|
+
- đ **Globally available** by default â no need to include anything. - (Can be disabled with Chansu.disable_globals!)
|
|
18
|
+
- đšī¸ Useful for games, simulations, generative art, or just spicing up your Ruby scripts.
|
|
10
19
|
|
|
11
|
-
|
|
20
|
+
---
|
|
12
21
|
|
|
13
|
-
|
|
14
|
-
bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
If bundler is not being used to manage dependencies, install the gem by executing:
|
|
22
|
+
## đ Installation
|
|
18
23
|
|
|
19
|
-
|
|
20
|
-
|
|
24
|
+
Add this line to your application's Gemfile:
|
|
25
|
+
```ruby
|
|
26
|
+
gem 'chansu'
|
|
21
27
|
```
|
|
28
|
+
Then execute
|
|
29
|
+
```bash
|
|
30
|
+
bundle install
|
|
31
|
+
```
|
|
32
|
+
Or just do
|
|
33
|
+
```bash
|
|
34
|
+
gem install chansu
|
|
35
|
+
```
|
|
36
|
+
---
|
|
22
37
|
|
|
23
|
-
## Usage
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
## Development
|
|
28
|
-
|
|
29
|
-
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
30
|
-
|
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
32
|
-
|
|
33
|
-
## Contributing
|
|
34
|
-
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/chansu. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/chansu/blob/master/CODE_OF_CONDUCT.md).
|
|
38
|
+
## đ ī¸ Usage
|
|
39
|
+
### Probability DSL
|
|
40
|
+
```ruby
|
|
41
|
+
require "chansu"
|
|
36
42
|
|
|
37
|
-
|
|
43
|
+
probably { puts "Hello, world!" } # ~60% chance
|
|
44
|
+
rarely { puts "Surprise!" } # ~10% chance
|
|
45
|
+
always { puts "Guaranteed!" } # 100%
|
|
46
|
+
```
|
|
38
47
|
|
|
39
|
-
|
|
48
|
+
### DSL Reference Table
|
|
49
|
+
| Method | Probability | Example |
|
|
50
|
+
|-------------------------|-------------|-----------------------------------------------|
|
|
51
|
+
| `always` | 100% | `always { puts "Guaranteed!" }` |
|
|
52
|
+
| `certainly` | 90% | `certainly { puts "Very likely" }` |
|
|
53
|
+
| `almost_always` | 85% | `almost_always { puts "Pretty often" }` |
|
|
54
|
+
| `usually` | 80% | `usually { puts "Most of the time" }` |
|
|
55
|
+
| `often` | 75% | `often { puts "Happens often" }` |
|
|
56
|
+
| `likely` | 70% | `likely { puts "Quite probable" }` |
|
|
57
|
+
| `frequently` | 65% | `frequently { puts "Fairly frequent" }` |
|
|
58
|
+
| `probably` | 60% | `probably { puts "More often than not" }` |
|
|
59
|
+
| `more_often_than_not` | 60% | `more_often_than_not { puts "Similar to probably" }` |
|
|
60
|
+
| `maybe` | 50% | `maybe { puts "Flip a coin" }` |
|
|
61
|
+
| `possibly` | 40% | `possibly { puts "Could happen" }` |
|
|
62
|
+
| `not_often` | 35% | `not_often { puts "Less common" }` |
|
|
63
|
+
| `unlikely` | 25% | `unlikely { puts "Not very likely" }` |
|
|
64
|
+
| `with_low_probability` | 15% | `with_low_probability { puts "Long shot" }` |
|
|
65
|
+
| `rarely` | 10% | `rarely { puts "Almost never" }` |
|
|
66
|
+
| `never` | ~0% đ | `never { puts "Basically never" }` |
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
### Dice Rolls
|
|
70
|
+
```ruby
|
|
71
|
+
require "chansu"
|
|
72
|
+
|
|
73
|
+
dice # 2
|
|
74
|
+
dice(42) # 31
|
|
75
|
+
dice(15, 3) # [15, 9, 15]
|
|
76
|
+
d6 # 6
|
|
77
|
+
d20 # 11
|
|
78
|
+
d100 # 90
|
|
79
|
+
dice("2d10") # {:rolls=>[9, 5], :total=>14}
|
|
80
|
+
dice("3d8+5") # {:rolls=>[3, 3, 4], :total=>15}
|
|
81
|
+
```
|
|
82
|
+
---
|
|
83
|
+
## âī¸ Config
|
|
84
|
+
### Controlling globals
|
|
85
|
+
By default, all DSL methods are available globally
|
|
86
|
+
If you want to remove them from your global namespace, disable them with:
|
|
87
|
+
```ruby
|
|
88
|
+
Chansu.disable_globals!
|
|
89
|
+
```
|
|
90
|
+
And include them in your own modules/classes:
|
|
91
|
+
```ruby
|
|
92
|
+
class MyClass
|
|
93
|
+
include Chansu
|
|
94
|
+
end
|
|
95
|
+
```
|
|
96
|
+
---
|
|
97
|
+
## đĻ Development
|
|
98
|
+
Clone and install dependencies:
|
|
99
|
+
```bash
|
|
100
|
+
bundle install
|
|
101
|
+
```
|
|
102
|
+
Run tests
|
|
103
|
+
```bash
|
|
104
|
+
rake test
|
|
105
|
+
```
|
|
106
|
+
Build gem
|
|
107
|
+
```
|
|
108
|
+
gem build
|
|
109
|
+
```
|
|
110
|
+
---
|
|
111
|
+
## đ¤ Contributing
|
|
40
112
|
|
|
41
|
-
|
|
113
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/escalderong/chansu
|
|
114
|
+
Feel free to suggest new probability words, dice, or randomness helpers!
|
|
42
115
|
|
|
43
|
-
|
|
116
|
+
---
|
|
117
|
+
## đ License
|
|
118
|
+
The gem is available as open source under the terms of the MIT License.
|
data/chansu-0.1.0.gem
ADDED
|
Binary file
|
data/lib/chansu/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: chansu
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Santiago Calderon
|
|
@@ -29,6 +29,7 @@ files:
|
|
|
29
29
|
- LICENSE.txt
|
|
30
30
|
- README.md
|
|
31
31
|
- Rakefile
|
|
32
|
+
- chansu-0.1.0.gem
|
|
32
33
|
- lib/chansu.rb
|
|
33
34
|
- lib/chansu/dsl.rb
|
|
34
35
|
- lib/chansu/loops.rb
|