lib/hazard.rb in hazard-1.1.0 vs lib/hazard.rb in hazard-1.2.0
- old
+ new
@@ -2,14 +2,22 @@
require_relative 'weighted_table'
class Hazard
def self.method_missing( method_name )
-
# Transform the method_name to string
method_name = method_name.to_s
+ self.roll_dice( method_name )
+ end
+ def self.from_string( dice_string )
+ roll_dice( dice_string )
+ end
+
+ private
+
+ def self.roll_dice( method_name )
# Parse the method name to get how many dice and what size of dice was required
dice_match = method_name.to_s.match( /(d|r|m|s)?(\d*)d(\d+)/ )
# Raise an error if match fail
raise "Method mising : #{method_name}" unless dice_match
@@ -30,9 +38,8 @@
# Unless splitted_result was requested, return the sum of the rolled dice
return rolls.reduce(:+) unless splited_result
# Return a RolledDice otherwise
RolledDice.new( rolls )
-
end
end