rollr 0.0.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.
Files changed (2) hide show
  1. data/lib/rollr.rb +52 -0
  2. metadata +47 -0
@@ -0,0 +1,52 @@
1
+ # Rollr Simulates rolling dice of different size.
2
+ #
3
+ # @author Alex Jarvis
4
+
5
+ require 'rubygems'
6
+
7
+ module Rollr
8
+
9
+
10
+ # Represents a single instance of the result of a die
11
+ #
12
+ class Die
13
+
14
+
15
+ # @attribute sides [Integer] The number of sides the die has
16
+ #
17
+ attr_accessor :sides
18
+
19
+ # New instance of Dice.
20
+ #
21
+ # @param [Integer] sides
22
+ # @return [Object] Die object
23
+ #
24
+ def initialize(sides)
25
+ @sides = sides
26
+ end #initialize
27
+
28
+ # Roll a new die.
29
+ #
30
+ # @param [Integer] count
31
+ # @return [Object] integer
32
+ #
33
+ def roll(count)
34
+ (1..count).map { |d| rand(self.sides) + 1 }.inject(0) { |total, d| total += d }
35
+ end #roll
36
+
37
+ end #Die
38
+
39
+
40
+ #Die Constants
41
+
42
+ D3 = Die.new(3)
43
+ D4 = Die.new(4)
44
+ D6 = Die.new(6)
45
+ D8 = Die.new(8)
46
+ D10= Die.new(10)
47
+ D12 = Die.new(12)
48
+ D20 = Die.new(20)
49
+
50
+ end #Rollr
51
+
52
+
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rollr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alex Jarvis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-06 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Rollr is a Gem that provides useful functions to simulate the Rolling
15
+ of Dice... because we weren't social enough as is.
16
+ email: alxjrvs@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/rollr.rb
22
+ homepage: https://github.com/alxjrvs/Rollr
23
+ licenses: []
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 1.8.24
43
+ signing_key:
44
+ specification_version: 3
45
+ summary: ! 'Rollr: Rand() for the Rest of Us'
46
+ test_files: []
47
+ has_rdoc: