hazard 1.2.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95dbcf77daa7235693220c74d60b47e42ab3e635
4
- data.tar.gz: 062155ee83ebdddb008e8c7f6f133b4c4d8292bf
3
+ metadata.gz: '08657cc882b26b86eb7897b444e125cb51799659'
4
+ data.tar.gz: b4e26bda3ada9032117860ef51f41706478f1502
5
5
  SHA512:
6
- metadata.gz: 8b77918372e932a63734eabf940a5c06fd6a5263df7f9290c26b88a7ee18f80dbdc004d1aa341b96e5c07d3ec864460cf1a8509338af9a76fd7272f3bfbf54b2
7
- data.tar.gz: da19de999a0edcead798d6ffb9716154fbde19288bcda76219dff6edacb7bf9750a0dbc3d8421ad418a3144ac4cf3ef62e3510f1342c139d186f9bf6bee84249
6
+ metadata.gz: 23ef045fd2f8ec1548bd8e24efa5a64b2db98967d5b3c27c34676d8be30908f47ef7cd84b66111749665302927c9fd645ed2308a9464567fdfd92ead6a298570
7
+ data.tar.gz: d5715f5e44b94c8a8f6555dd4212ef94d7b5b3ee84bc78a8aef894ca9e0905beb748b920ccddcd323f7e5920e168493bac98b634b123bba48ebea179ba168c78
data/README.md CHANGED
@@ -151,8 +151,7 @@ Assuming you are playing DD Next
151
151
 
152
152
  ## Weighted Tables
153
153
 
154
- Weighted tables are object that allow to get weighted random.
155
- Example : if you have two time foo and one time bar in your table.
154
+ Weighted tables are object that allow to get weighted random.
156
155
 
157
156
  ### If you have the weights
158
157
 
@@ -1,3 +1,3 @@
1
1
  class Hazard
2
- VERSION = '1.2.0'
2
+ VERSION = '1.2.1'
3
3
  end
data/lib/hazard.rb CHANGED
@@ -1,20 +1,38 @@
1
1
  require_relative 'rolled_dice'
2
2
  require_relative 'weighted_table'
3
3
 
4
+ # This class roll the dice.
5
+ #
6
+ # @author Cédric ZUGER
4
7
  class Hazard
5
8
 
9
+ # Regular entry point. This is where you will go when you call Hazard.d6 for instance.
10
+ #
11
+ # @param method_name [String] the description of the dice. See help for detail.
12
+ #
13
+ # @return [Object] if detail has been asked, it will return a [RolledDice] object, otherwise it will return an [Integer] containing the sum of the dice.
6
14
  def self.method_missing( method_name )
7
15
  # Transform the method_name to string
8
16
  method_name = method_name.to_s
9
17
  self.roll_dice( method_name )
10
18
  end
11
19
 
20
+ # From string entry point, in case you have your dice description in a database for instance.
21
+ #
22
+ # @param dice_string [String] the description of the dice. See help for detail.
23
+ #
24
+ # @return [Object] if detail has been asked, it will return a [RolledDice] object, otherwise it will return an [Integer] containing the sum of the dice.
12
25
  def self.from_string( dice_string )
13
26
  roll_dice( dice_string )
14
27
  end
15
28
 
16
29
  private
17
30
 
31
+ # Roll dice according to method name
32
+ #
33
+ # @param method_name [String] the description of the dice. See help for detail.
34
+ #
35
+ # @return [Object] if detail has been asked, it will return a [RolledDice] object, otherwise it will return an [Integer] containing the sum of the dice.
18
36
  def self.roll_dice( method_name )
19
37
  # Parse the method name to get how many dice and what size of dice was required
20
38
  dice_match = method_name.to_s.match( /(d|r|m|s)?(\d*)d(\d+)/ )
data/lib/rolled_dice.rb CHANGED
@@ -1,13 +1,23 @@
1
+ # This class represents the result of a roll, for people that need to work wit dice details.
2
+ #
3
+ # @author Cédric ZUGER
1
4
  class RolledDice
2
5
 
3
6
  attr_reader :result, :rolls
4
7
 
8
+ # Create a RolledDice object
9
+ #
10
+ # @param rolls [Array] an array of integer containing the dice rolls.
5
11
  def initialize( rolls )
6
12
  @rolls = rolls
7
13
  @result = rolls.reduce(:+)
8
14
  end
9
15
 
10
- # Required for tests
16
+ # Compare two rolls
17
+ #
18
+ # @param rolled_dice [RolledDice] the other RolledDice to compare
19
+ #
20
+ # @return [Boolean] the result of the comparison
11
21
  def ==( rolled_dice )
12
22
  @rolls == rolled_dice.rolls && @result == rolled_dice.result
13
23
  end
@@ -1,5 +1,8 @@
1
1
  require 'yaml'
2
2
 
3
+ # This class contains objects and associate weights to them. So that you can sample the object according to their weights.
4
+ #
5
+ # @author Cédric ZUGER
3
6
  class WeightedTable
4
7
 
5
8
  BASE_WEIGHT = 1
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hazard
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cédric ZUGER
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-21 00:00:00.000000000 Z
11
+ date: 2018-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler