pinzoro 1.0.0

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.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pinzoro.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 parrot-studio
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ # Pinzoro
2
+
3
+ You can write like (T)RPG dice (e.g. 2D6, 3D20), and get result.
4
+
5
+ "Pinzoro" means "1 and 1 on 2D6" in Japanese.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'pinzoro'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pinzoro
20
+
21
+ ## Usage
22
+
23
+ # get dice roll result by Array.
24
+ # "n.dx" or "n.Dx"
25
+ 2.d6 #=> [2, 4]
26
+ 2.D6 #=> [6, 5]
27
+ 1.D20 #=> [18]
28
+ 3.d4 #=> [4, 1, 2]
29
+
30
+ # get added result.
31
+ # "n.dx!" or "n.Dx!"
32
+ 2.d6! #=> 6
33
+ 2.D6! #=> 11
34
+ 1.D10! #=> 9
35
+ 3.d4! #=> 7
36
+
37
+ # you can roll unreal dice.
38
+ 5.d7 #=> [6, 1, 7, 2, 3]
39
+ 100.d21 #=> [5, 11, 21, ..., 15]
40
+
41
+ # roll times at least 1.
42
+ 0.d6 #=> raise error
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
51
+
52
+ ## License
53
+
54
+ The MIT License.
55
+
56
+ ## Author
57
+
58
+ parrot-studio(ぱろっと) (@parrot_studio / parrot.studio.dev at gmail.com)
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core'
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec) do |spec|
6
+ spec.pattern = FileList['spec/**/*_spec.rb']
7
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ require "pinzoro/version"
3
+ require "pinzoro/roll"
4
+
5
+ class Integer
6
+
7
+ def diceroll(dice)
8
+ Pinzoro.roll(dice, self)
9
+ end
10
+
11
+ # override
12
+ def method_missing(name, *args)
13
+ super if self <= 0
14
+ m = name.to_s.match(/\A[d|D](\d+)(!)?\z/)
15
+ super unless m
16
+ ret = self.diceroll(m[1].to_i)
17
+ super unless ret
18
+ m[2] ? ret.inject(&:+) : ret
19
+ end
20
+
21
+ end
@@ -0,0 +1,12 @@
1
+ # coding: utf-8
2
+ module Pinzoro
3
+
4
+ module_function
5
+
6
+ def roll(dice, times = 1)
7
+ return unless (dice && times)
8
+ return if dice <= 0 || times <= 0
9
+ (1..times).map{ rand(dice) + 1 }
10
+ end
11
+
12
+ end
@@ -0,0 +1,3 @@
1
+ module Pinzoro
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pinzoro/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "pinzoro"
8
+ gem.version = Pinzoro::VERSION
9
+ gem.authors = ["parrot-studio"]
10
+ gem.email = ["parrot.studio.dev@gmail.com"]
11
+ gem.description = %q{You can write like (T)RPG dice (e.g. 2D6, 3D20), and get result.}
12
+ gem.summary = %q{You can write like (T)RPG dice (e.g. 2D6, 3D20), and get result. "Pinzoro" means "1 and 1 on 2D6" in Japanese.}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,62 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Pinzoro do
5
+
6
+ describe '#roll' do
7
+
8
+ context 'dice roll' do
9
+ let(:dice_size){ 6 }
10
+ subject{ Pinzoro.roll(dice_size, 2) }
11
+ it { subject.size.should == 2 }
12
+ it { subject.all?{|v| v >= 1 && v <= dice_size }.should be_true }
13
+ end
14
+
15
+ context 'roll times default is 1' do
16
+ let(:dice_size){ 8 }
17
+ subject{ Pinzoro.roll(dice_size) }
18
+ it { subject.size.should == 1 }
19
+ it { subject.all?{|v| v >= 1 && v <= dice_size }.should be_true }
20
+ end
21
+
22
+ context 'return nil if dice_size is nil' do
23
+ it { Pinzoro.roll(nil, 2).should be_nil }
24
+ end
25
+
26
+ end
27
+
28
+ describe 'add method for Integer class' do
29
+
30
+ context 'roll 2d6' do
31
+ subject { 2.d6 }
32
+ it { subject.size.should == 2 }
33
+ it { subject.all?{|v| v >= 1 && v <= 6 }.should be_true }
34
+ end
35
+
36
+ context 'roll 3D10' do
37
+ subject { 3.D10 }
38
+ it { subject.size.should == 3 }
39
+ it { subject.all?{|v| v >= 1 && v <= 10 }.should be_true }
40
+ end
41
+
42
+ context '2.d6! is sum result' do
43
+ subject { 2.d6! }
44
+ it { subject.should be_kind_of(Integer) }
45
+ it { subject.should >= (1 * 2) }
46
+ it { subject.should <= (6 * 2) }
47
+ end
48
+
49
+ context '3.D8! is sum result' do
50
+ subject { 3.D8! }
51
+ it { subject.should be_kind_of(Integer) }
52
+ it { subject.should >= (1 * 3) }
53
+ it { subject.should <= (8 * 3) }
54
+ end
55
+
56
+ context 'call original method missing if self <= 0' do
57
+ it { lambda{-1.d6}.should raise_error }
58
+ end
59
+
60
+ end
61
+
62
+ end
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'pinzoro'
4
+ require 'rspec'
5
+
6
+ RSpec.configure do |config|
7
+ config.color_enabled = true
8
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pinzoro
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - parrot-studio
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-23 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: You can write like (T)RPG dice (e.g. 2D6, 3D20), and get result.
15
+ email:
16
+ - parrot.studio.dev@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/pinzoro.rb
27
+ - lib/pinzoro/roll.rb
28
+ - lib/pinzoro/version.rb
29
+ - pinzoro.gemspec
30
+ - spec/pinzoro/pinzoro_spec.rb
31
+ - spec/spec_helper.rb
32
+ homepage: ''
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.24
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: You can write like (T)RPG dice (e.g. 2D6, 3D20), and get result. "Pinzoro"
56
+ means "1 and 1 on 2D6" in Japanese.
57
+ test_files:
58
+ - spec/pinzoro/pinzoro_spec.rb
59
+ - spec/spec_helper.rb