stattr 0.0.5 → 0.0.6

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/stattr.rb +31 -20
  2. metadata +1 -1
@@ -1,21 +1,28 @@
1
- Normstats = ['STR', 'DEX', 'CHA', 'INT', 'WIS', 'CON']
2
1
 
3
- # Roll a D(sides) size die.
4
- def rolld(sides)
5
- rand(sides) + 1
6
- end
2
+ module Stattr
3
+ Normstats = ['STR', 'DEX', 'CHA', 'INT', 'WIS', 'CON']
4
+
5
+ class Dice
6
+ attr_accessor :sides, :count
7
+ def initialize(sides=6, count=1)
8
+ @sides = sides
9
+ @count = count
10
+ end
7
11
 
12
+ def self.roll(sides=6, count=1)
13
+ new(sides, count).roll
14
+ end
8
15
 
9
- # Rolls a number of dice of particular sizes.
10
- def rollmanyd(sides, dice)
11
- rolls = 0
12
- (1..dice).each do |i|
13
- rolls = rolls + rolld(sides)
16
+ def rolls
17
+ (1..count).map { |d| rand(sides) + 1 }
14
18
  end
15
- rolls
16
- end
17
19
 
18
- def modstat(r)
20
+ def roll
21
+ rolls.inject(0) { |total, d| total += d }
22
+ end
23
+ end
24
+
25
+ def modstat(r)
19
26
  modlist = []
20
27
  case r
21
28
  when 3
@@ -48,7 +55,7 @@ end
48
55
  def statroll
49
56
  stathash = {}
50
57
  Normstats.each do |stat|
51
- stathash[stat] = modstat(rollmanyd(6,3))
58
+ stathash[stat] = modstat(Stattr::Dice.roll(6,3))
52
59
  end
53
60
  stathash
54
61
  end
@@ -63,12 +70,12 @@ attr_accessor :str, :dex, :cha, :con, :wis, :int
63
70
  @@sides = 6
64
71
  @@dicenum = 3
65
72
  def initialize
66
- @str = modstat(rollmanyd(@@sides, @@dicenum))
67
- @dex = modstat(rollmanyd(@@sides, @@dicenum))
68
- @cha = modstat(rollmanyd(@@sides, @@dicenum))
69
- @con = modstat(rollmanyd(@@sides, @@dicenum))
70
- @wis = modstat(rollmanyd(@@sides, @@dicenum))
71
- @int = modstat(rollmanyd(@@sides, @@dicenum))
73
+ @str = modstat(Stattr::Dice.roll(@@sides, @@dicenum))
74
+ @dex = modstat(Stattr::Dice.roll(@@sides, @@dicenum))
75
+ @cha = modstat(Stattr::Dice.roll(@@sides, @@dicenum))
76
+ @con = modstat(Stattr::Dice.roll(@@sides, @@dicenum))
77
+ @wis = modstat(Stattr::Dice.roll(@@sides, @@dicenum))
78
+ @int = modstat(Stattr::Dice.roll(@@sides, @@dicenum))
72
79
  end
73
80
  end
74
81
 
@@ -80,3 +87,7 @@ attr_accessor :stats, :name
80
87
  @stats = Statlist.new
81
88
  end
82
89
  end
90
+
91
+ end
92
+
93
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stattr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: