randsum 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1ff083ad934444c3cbc349a1210ff7ac7b3e87f
4
- data.tar.gz: f01aa2b396ed625cd19029a96dc97a7c2f9603a2
3
+ metadata.gz: b40795441292e1f022b9964709ae9b1a1440b8d2
4
+ data.tar.gz: e2403d1ed04af388474c6fb24ee69b1065bc2848
5
5
  SHA512:
6
- metadata.gz: d6931b687ec9a810ce76d14476a5b5a41f9c8c9fd50f775f9d0f7790a024dd022d7be99ad239e8b196f51ec4614d42b84a1914992d4a87e397eed85774f3a57c
7
- data.tar.gz: 69f74d416ff979ed8f5347846d5b6e8b3080bb2dfb4afa48419bb673e947ea044a9ed3a653ac02ddedf410558a0d190fb464122b86965f5b7611e0f868962a6f
6
+ metadata.gz: 55770ea57631fe9e4d1297b78b824d45067b5b1b52113201491cf72f901e03bb5ce5096be5dd90b5650556fc1fd140a5208bb2e14e65f29d912aa8d75dc4230e
7
+ data.tar.gz: 6f400f76cb73c5ce4cbc651941646f9cd66dc86c2afeb697e5b95602263c541394d81ce95cc3e6ce1faf4432d49e6c6a264a8e171cbe3dfad7153d198188760a
data/README.md CHANGED
@@ -84,9 +84,9 @@ That's pretty neat, right?
84
84
  Snakeyes. Rough.
85
85
 
86
86
 
87
- ### Making use of the rolls: the `RollReport`
87
+ ### Making use of the rolls: the `Roll`
88
88
 
89
- `Die#roll` returns a `RollReport` object, which can teach you a lot about your rolls (but not, tragically, how to roll better.)
89
+ `Die#roll` returns a `Roll` object, which can teach you a lot about your rolls (but not, tragically, how to roll better.)
90
90
 
91
91
  ```
92
92
  > report = Randsum::D20.roll 5
@@ -128,11 +128,11 @@ And if you don't like that roll (hey we get it) you can use `#die` to get anothe
128
128
  #=> You rolled 1 D20, and got 17. (Rolls: [17])
129
129
  ```
130
130
 
131
- #### Manipulating `RollReport`s
131
+ #### Manipulating `Roll`s
132
132
 
133
- Roll results can be further manipulated after their original creation. To facilitate popular use-cases for Dice rolling, `RollReport`s also include public `#drop_lowest` and `#drop_highest`, and `#drop` methods.
133
+ Roll results can be further manipulated after their original creation. To facilitate popular use-cases for Dice rolling, `Roll`s also include public `#drop_lowest` and `#drop_highest`, and `#drop` methods.
134
134
 
135
- `#drop_lowest` returns a new `RollReport` without the lowest numerical die roll.
135
+ `#drop_lowest` returns a new `Roll` without the lowest numerical die roll.
136
136
 
137
137
  ```
138
138
  > report = Randsum::D6.roll 4
@@ -163,7 +163,7 @@ Both `#drop_lowest` and `#drop_highest` can also take an optional integer argume
163
163
  ### Why build this?
164
164
  [Rollr](http://github.com/alxjrvs/rollr) was one of the first things I ever built. I think it's funny, and I'm not sure why.
165
165
 
166
- I recently had the privilege of attending Sandi Metz' POODNyc workshop, which involved a continual practice of refactoring the same "simple" problem over and over again. I liked revisitng Rollr through the years, and Randsum reflects an attempt to use small refactoring techniques to continue to mull over the "simple" problem of random numbers.
166
+ I liked revisiting Rollr through the years, and Randsum reflects my current take on the problem. I renamed it because at a certain point you realize you just typed `Rollr::Roll.new(rolls:).roll!`and you're just dead inside.
167
167
 
168
168
  ## Development
169
169
 
@@ -173,7 +173,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
173
173
 
174
174
  ## Contributing
175
175
 
176
- Bug reports and pull requests are welcome on GitHub at https://github.com/alxjrvs/randsum. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
176
+ Bug reports and pull requests are welcome on GitHub at https://github.com/RANDSUM/randsum. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
177
177
 
178
178
 
179
179
  ## License
data/lib/randsum/die.rb CHANGED
@@ -11,8 +11,9 @@ module Randsum
11
11
  end
12
12
 
13
13
  def roll(quantity = 1)
14
- Randsum::RollReport.new(
15
- roll_for(quantity)
14
+ Randsum::Roll.new(
15
+ quantity: quantity,
16
+ die: self
16
17
  )
17
18
  end
18
19
 
@@ -23,15 +24,5 @@ module Randsum
23
24
  def simple_roll
24
25
  randomizer.random_number(sides).to_i + ZERO_INDEX_FIXER
25
26
  end
26
-
27
- private
28
-
29
- def roll_for(quantity)
30
- Randsum::Roll.new(
31
- quantity: quantity,
32
- die: self
33
- )
34
- end
35
-
36
27
  end
37
28
  end
data/lib/randsum/roll.rb CHANGED
@@ -1,6 +1,11 @@
1
+ require 'pry'
1
2
  module Randsum
2
3
  class Roll
3
- attr_reader :die, :quantity, :sides, :result
4
+ attr_reader :die, :quantity, :sides, :result, :total
5
+
6
+ alias_method :length, :quantity
7
+ alias_method :count, :quantity
8
+ alias_method :rolls, :result
4
9
 
5
10
  def initialize(die:, quantity:, result: nil)
6
11
  @die = die
@@ -10,8 +15,14 @@ module Randsum
10
15
  end
11
16
 
12
17
  def to_s
13
- "Rolls: #{result}"
18
+ "You rolled #{count} #{die}, and got #{total}. (Rolls: #{result})"
19
+ end
20
+ alias_method :inspect, :to_s
21
+
22
+ def total
23
+ @total ||= result.inject(:+)
14
24
  end
25
+ alias_method :to_i, :total
15
26
 
16
27
  def drop(quantity:,extremity:)
17
28
  return new_roll_with(
@@ -23,7 +34,16 @@ module Randsum
23
34
  )
24
35
  end
25
36
 
37
+ def drop_lowest(quantity = 1)
38
+ drop(quantity: quantity, extremity: :lowest)
39
+ end
40
+
41
+ def drop_highest(quantity = 1)
42
+ drop(quantity: quantity, extremity: :highest)
43
+ end
44
+
26
45
  private
46
+
27
47
  def new_roll_with(result: nil)
28
48
  return Roll.new(
29
49
  die: die,
@@ -1,3 +1,3 @@
1
1
  module Randsum
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
data/lib/randsum.rb CHANGED
@@ -6,10 +6,8 @@ require "randsum/filters/droppers/high_dropper"
6
6
  require "randsum/filters/droppers/low_dropper"
7
7
  require "randsum/roll"
8
8
  require "randsum/die"
9
- require "randsum/roll_report"
10
9
 
11
10
  module Randsum
12
-
13
11
  D2 = Die.new(2)
14
12
  D3 = Die.new(3)
15
13
  D4 = Die.new(4)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: randsum
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Jarvis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-04 00:00:00.000000000 Z
11
+ date: 2016-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -97,7 +97,6 @@ files:
97
97
  - lib/randsum/filters/filter.rb
98
98
  - lib/randsum/metadata.rb
99
99
  - lib/randsum/roll.rb
100
- - lib/randsum/roll_report.rb
101
100
  - lib/randsum/version.rb
102
101
  - randsum.gemspec
103
102
  homepage: http://api.randsum.io
@@ -1,61 +0,0 @@
1
- module Randsum
2
- class RollReport
3
-
4
- def initialize(roll)
5
- @roll = roll
6
- end
7
-
8
- def inspect
9
- to_s
10
- end
11
-
12
- def to_s
13
- "You rolled #{quantity} #{die}, and got #{total}. (#{roll})"
14
- end
15
-
16
- def to_i
17
- total
18
- end
19
-
20
- def sides
21
- die.sides
22
- end
23
-
24
- def die
25
- roll.die
26
- end
27
-
28
- def rolls
29
- @_rolls ||= roll.result
30
- end
31
-
32
- def total
33
- @_total ||= rolls.inject(:+)
34
- end
35
-
36
- def quantity
37
- @_quantity ||= rolls.count
38
- end
39
-
40
- def drop(quantity:, extremity:)
41
- return RollReport.new(
42
- roll.drop(quantity: quantity, extremity: extremity)
43
- )
44
- end
45
-
46
- def drop_lowest(quantity = 1)
47
- return RollReport.new(
48
- roll.drop(quantity: quantity, extremity: :lowest)
49
- )
50
- end
51
-
52
- def drop_highest(quantity = 1)
53
- return RollReport.new(
54
- roll.drop(quantity: quantity, extremity: :highest)
55
- )
56
- end
57
-
58
- private
59
- attr_reader :roll
60
- end
61
- end