physh_roller 1.0.1 → 1.1.1

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: 9657b33b99f914a4cf30e78a51c1f7de5da71483
4
- data.tar.gz: 8f2f0ebf7e929cade84e7c48cbd20aa497b38945
3
+ metadata.gz: ece651f5f73ec4aa0ad0685b543a592386957448
4
+ data.tar.gz: 10ba01555a7a6ae9135181fe5020c8c5fcb9497a
5
5
  SHA512:
6
- metadata.gz: 853ca6638ef6436535a2384af558a01cf300b35450af660c3112cc69bca4850eec2d3e4fee4b1b7cbfdc76ac2df68e50f237ff1dea5f2e5ae36f76b6e540df26
7
- data.tar.gz: c226a5dcf6bbc09837f49767ae4aa06596c409d4e1b1f590be4cb65d66015dd671e911057b01ac7e47dbc1e612fd33ff9a75c9364bf1af9e2beee84781f0df55
6
+ metadata.gz: 0d7453fdc65c19892d6d3139481a98646779534c1d63568eac990158cf4f3a4363c273e2ef924a9734d2d566d5274d65dffd3e45e4c6c78edaec21103e35ea6a
7
+ data.tar.gz: 30f52ad3cce8891cde2b32e72742b9730d9e1e4162432d35041aa806c6083d3dcf60e2b20bf76b017a7e2a1743819169698962e67977a9a47c82c3defb5cebb0
data/README CHANGED
@@ -12,6 +12,14 @@ If you've installed the gem, you can simply run:
12
12
 
13
13
  Example dice strings are 4d6, 20d100-20, 14D2+6. Basically, anything that matches the regular expression /\A(\d+)?d(\d+)([\+-]\d*)?\z/i.
14
14
 
15
+ Command line help is available with
16
+
17
+ dice --help
18
+
19
+ Now supports FATE dice rolls with:
20
+
21
+ dice -f
22
+
15
23
  As A Module
16
24
  -----------
17
25
 
data/bin/dice CHANGED
@@ -18,14 +18,21 @@ opt_parse = OptionParser.new do |opts|
18
18
  puts opts
19
19
  exit
20
20
  end
21
+
22
+ # Fate diceroll switch
23
+ opts.on('-f', '--fate', 'Make a FATE dice roll.') do
24
+ options[:fate] = true
25
+ end
21
26
  end
22
27
 
23
28
  opt_parse.parse!
24
-
25
-
26
- dice_roll_string = ARGV.unshift[0]
27
-
28
- dice_roll = PhyshRoller::DiceRoll.new(dice_roll_string, $stdout)
29
+
30
+ if options[:fate]
31
+ dice_roll = PhyshRoller::FateRoll.new
32
+ else
33
+ dice_roll_string = ARGV.unshift[0]
34
+ dice_roll = PhyshRoller::DiceRoll.new(dice_roll_string, $stdout)
35
+ end
29
36
  dice_roll.roll_dice
30
37
  dice_roll.output_results
31
38
 
@@ -60,7 +60,7 @@ module PhyshRoller
60
60
  def output_results
61
61
  results = self.results
62
62
  @output.puts "You rolled: #{results[:dice_roll]}"
63
- @output.puts "Dice rolls: #{results[:dice_rolls].join(',')}"
63
+ @output.puts "Dice rolls: #{results[:dice_rolls].join(', ')}"
64
64
  @output.puts "Total: #{results[:sum]}"
65
65
  end
66
66
 
@@ -0,0 +1,36 @@
1
+ module PhyshRoller
2
+ class FateRoll < DiceRoll
3
+ def initialize(dice_roll_string='4d3',output=$stdout)
4
+ super
5
+ end
6
+
7
+ def results
8
+ results_hash = {
9
+ :dice_roll => 'FATE Roll',
10
+ :dice_rolls => convert_dice_to_fate,
11
+ :sum => get_fate_total,
12
+ :roll_modifier => 0
13
+ }
14
+ end
15
+
16
+ def convert_dice_to_fate
17
+ dice_rolls = @dice_array.map { |die| die.last_result - 2 }.sort.reverse
18
+ converted_dice = dice_rolls.map do |roll|
19
+ case roll
20
+ when -1
21
+ then '-'
22
+ when 0
23
+ then 'Nil'
24
+ when 1
25
+ then '+'
26
+ end
27
+ end
28
+ return converted_dice
29
+ end
30
+
31
+ def get_fate_total
32
+ sum = @dice_array.map { |die| die.last_result - 2 }.reduce(:+)
33
+ sum >= 0 ? '+' + sum.to_s : sum.to_s
34
+ end
35
+ end
36
+ end
data/lib/physh_roller.rb CHANGED
@@ -2,4 +2,5 @@
2
2
  # Just holds require statements.
3
3
 
4
4
  require_relative 'physh_roller/dice_roll'
5
- require_relative 'physh_roller/die'
5
+ require_relative 'physh_roller/die'
6
+ require_relative 'physh_roller/fate_roll'
@@ -15,6 +15,7 @@ module PhyshRoller
15
15
  it { should respond_to(:roll_modifier) }
16
16
  it { should respond_to(:dice_array) }
17
17
  it { should respond_to(:results) }
18
+ it { should respond_to(:roll_dice) }
18
19
  end
19
20
 
20
21
  context "with an invalid dice_roll_string" do
@@ -134,7 +135,7 @@ module PhyshRoller
134
135
  end
135
136
 
136
137
  it "should output the dice rolls" do
137
- @output.should_receive(:puts).with(/\ADice rolls: (\d,)+\d\z/)
138
+ @output.should_receive(:puts).with(/\ADice rolls: (\d, )+\d\z/)
138
139
  end
139
140
 
140
141
  it "should output the total" do
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ module PhyshRoller
4
+ describe FateRoll do
5
+ before(:each) { @output = double('output').as_null_object }
6
+
7
+ describe "attributes and method tests" do
8
+ subject { FateRoll.new }
9
+
10
+ it { should respond_to(:results) }
11
+ it { should respond_to(:roll_dice) }
12
+ its(:dice_roll_string) { should == '4d3' }
13
+ end
14
+
15
+ describe "#results" do
16
+ before(:each) do
17
+ @fate_roll = FateRoll.new
18
+ @fate_roll.roll_dice
19
+ end
20
+
21
+ subject { @fate_roll.results }
22
+
23
+ it { should be_a_kind_of(Hash) }
24
+ its([:dice_roll]) { should == "FATE Roll"}
25
+ its([:dice_rolls]) { should have(4).dice }
26
+ its([:roll_modifier]) { should == 0 }
27
+ its([:sum]) { should match /\A[\+-][01234]\z/ }
28
+ end
29
+
30
+ describe "#convert_dice_to_fate" do
31
+ before { @fate_roll = FateRoll.new.roll_dice }
32
+
33
+ it "should have 4 dice in the array" do
34
+ @fate_roll.convert_dice_to_fate.size.should == 4
35
+ end
36
+
37
+ it "should have elements with value '+', 'Nil', or '-'" do
38
+ @fate_roll.convert_dice_to_fate.each { |n|
39
+ ['+', 'Nil', '-'].include?(n).should be_true
40
+ }
41
+ end
42
+ end
43
+
44
+ describe "#get_fate_total" do
45
+ before { @fate_roll = FateRoll.new.roll_dice }
46
+
47
+ subject { @fate_roll.get_fate_total }
48
+
49
+ it { should match /\A[\+-][01234]\z/ }
50
+ end
51
+ end
52
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: physh_roller
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kryptyk Fysh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-10 00:00:00.000000000 Z
11
+ date: 2013-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -45,16 +45,17 @@ email: kryptykfysh@kryptykfysh.co.uk
45
45
  executables:
46
46
  - dice
47
47
  extensions: []
48
- extra_rdoc_files:
49
- - README
48
+ extra_rdoc_files: []
50
49
  files:
51
50
  - bin/dice
52
51
  - lib/physh_roller/die.rb
53
52
  - lib/physh_roller/dice_roll.rb
53
+ - lib/physh_roller/fate_roll.rb
54
54
  - lib/physh_roller.rb
55
55
  - LICENSE
56
56
  - README
57
57
  - spec/physh_roller/die_spec.rb
58
+ - spec/physh_roller/fate_roll_spec.rb
58
59
  - spec/physh_roller/dice_roll_spec.rb
59
60
  - spec/spec_helper.rb
60
61
  homepage: https://github.com/kryptykfysh/PhyshRoller
@@ -69,7 +70,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
70
  requirements:
70
71
  - - '>='
71
72
  - !ruby/object:Gem::Version
72
- version: '1.9'
73
+ version: 1.9.0
73
74
  required_rubygems_version: !ruby/object:Gem::Requirement
74
75
  requirements:
75
76
  - - '>='
@@ -83,5 +84,6 @@ specification_version: 4
83
84
  summary: A dice rolling application
84
85
  test_files:
85
86
  - spec/physh_roller/die_spec.rb
87
+ - spec/physh_roller/fate_roll_spec.rb
86
88
  - spec/physh_roller/dice_roll_spec.rb
87
89
  - spec/spec_helper.rb