dice-cli 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3aacd16db50f17412ab0a859b5c4f37adfc1badf
4
+ data.tar.gz: '09cd3643736cead70d310c85d1b427e33f082834'
5
+ SHA512:
6
+ metadata.gz: 1c4c446200faca7b4dbec003bffaa9c68fdd2f32518a2f783a1f906de558422e992910ffd3ae7f8254399cc4fe61093f9c332738e16985b705ac2b4c7fc8081a
7
+ data.tar.gz: bbfe34f05cff2ff127c594da4c7317e4d043b12f8cd4ba06b4c618f2658939b6b416f3510a6759465883e2504a3bf619de19be0f58e438c4729140afa27f2090
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Walerian Sobczak
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,24 @@
1
+ # dice
2
+ CLI for simulating dice rolls.
3
+
4
+ ## Usage
5
+ ```
6
+ Usage: dice [options]
7
+ -f, --faces N Roll the dice with N faces. Default: 6.
8
+ -c, --count COUNT Roll the dice COUNT times. Default: 1.
9
+ -h, --help Show the help message.
10
+ ```
11
+
12
+ ## Examples
13
+ ```
14
+ $ dice
15
+ 6
16
+ ```
17
+
18
+ ```
19
+ $ dice -f 8 -c 4
20
+ 6
21
+ 6
22
+ 5
23
+ 3
24
+ ```
data/bin/dice ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/dice'
4
+
5
+ begin
6
+ Dice.parse(ARGV)
7
+ Dice.run || exit
8
+ rescue => e
9
+ STDERR.puts e.message
10
+ STDERR.puts e.backtrace.join("\n")
11
+ exit
12
+ end
data/dice.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ require File.join(File.dirname(__FILE__), 'lib/dice/version')
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'dice-cli'
5
+ s.version = Dice::VERSION
6
+ s.licenses = ['MIT']
7
+ s.summary = 'Dice'
8
+ s.description = 'CLI for simulating dice rolls.'
9
+ s.authors = ['Walerian Sobczak']
10
+ s.email = 'walerian.sobczak@gmail.com'
11
+ s.homepage = 'https://github.com/walerian777/dice'
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
+ s.test_files = s.files.grep(%r{^spec/})
16
+ s.require_paths = %w(lib)
17
+
18
+ s.add_development_dependency 'rspec', '~> 3.5', '>= 3.5.0'
19
+ end
@@ -0,0 +1,33 @@
1
+ require 'optparse'
2
+ require_relative 'version'
3
+
4
+ module Dice
5
+ class Parser
6
+ attr_reader :options
7
+
8
+ def initialize(args)
9
+ @options = {}
10
+ @args = args
11
+ end
12
+
13
+ def call
14
+ OptionParser.new do |parser|
15
+ parser.banner = 'Usage: dice [options]'
16
+ parser.version = Dice::VERSION
17
+
18
+ parser.on('-f', '--faces N', Integer, 'Roll the dice with N faces.') do |faces|
19
+ options[:faces] = faces
20
+ end
21
+
22
+ parser.on('-c', '--count COUNT', Integer, 'Roll the dice COUNT times.') do |count|
23
+ options[:count] = count
24
+ end
25
+
26
+ parser.on('-h', '--help', 'Show this help message.') do
27
+ puts parser
28
+ exit
29
+ end
30
+ end.parse!(@args)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ module Dice
2
+ class Roller
3
+ attr_reader :count, :faces
4
+
5
+ def initialize(args = {})
6
+ args = defaults.merge(args)
7
+ @count = args[:count]
8
+ @faces = args[:faces]
9
+ end
10
+
11
+ def call
12
+ count.times do
13
+ puts roll
14
+ end
15
+ end
16
+
17
+ def roll
18
+ rand(1..faces)
19
+ end
20
+
21
+ def defaults
22
+ { faces: 6, count: 1 }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Dice
2
+ VERSION = '0.0.1'.freeze
3
+ end
data/lib/dice.rb ADDED
@@ -0,0 +1,15 @@
1
+ require_relative 'dice/parser'
2
+ require_relative 'dice/roller'
3
+
4
+ module Dice
5
+ def self.parse(args)
6
+ parser = Parser.new(args)
7
+ parser.call
8
+ @options = parser.options
9
+ end
10
+
11
+ def self.run
12
+ roller = Roller.new(@options)
13
+ roller.call
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ describe Dice do
2
+ it 'returns a number when called in shell' do
3
+ expect(`dice`).to match(/\d\n/)
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ describe Dice::Parser do
2
+ describe '#call' do
3
+ it 'leaves initial options value when no arguments were given' do
4
+ parser = Dice::Parser.new([])
5
+ parser.call
6
+ expect(parser.options).to be_empty
7
+ end
8
+
9
+ it 'assings faces option' do
10
+ new_faces = 2
11
+ parser = Dice::Parser.new(%W(--faces #{new_faces}))
12
+ parser.call
13
+ expect(parser.options[:faces]).to eql(new_faces)
14
+ end
15
+
16
+ it 'assings count option' do
17
+ new_count = 4
18
+ parser = Dice::Parser.new(%W(--count #{new_count}))
19
+ parser.call
20
+ expect(parser.options[:count]).to eql(new_count)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,33 @@
1
+ describe Dice::Roller do
2
+ describe '#call' do
3
+ it 'prints a rolled value' do
4
+ rolled_value = 4
5
+ roller = Dice::Roller.new
6
+ allow(roller).to receive(:roll) { rolled_value }
7
+ expect(STDOUT).to receive(:puts).with(rolled_value)
8
+ roller.call
9
+ end
10
+
11
+ it 'prints a rolled value a given number of times' do
12
+ rolled_value = 4
13
+ rolls_count = 3
14
+ roller = Dice::Roller.new(count: rolls_count)
15
+ allow(roller).to receive(:roll) { rolled_value }
16
+ expect(STDOUT).to receive(:puts).exactly(rolls_count).times.with(rolled_value)
17
+ roller.call
18
+ end
19
+ end
20
+
21
+ describe '#roll' do
22
+ it 'returns an instance of Integer' do
23
+ roller = Dice::Roller.new
24
+ expect(roller.roll).to be_kind_of(Integer)
25
+ end
26
+
27
+ it 'returns a number in a given range' do
28
+ maximum = 10
29
+ roller = Dice::Roller.new(faces: maximum)
30
+ expect(1..maximum).to cover(roller.roll)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,6 @@
1
+ require 'dice'
2
+
3
+ RSpec.configure do |config|
4
+ config.order = :random
5
+ Kernel.srand config.seed
6
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dice-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Walerian Sobczak
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.5'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.5.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.5'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 3.5.0
33
+ description: CLI for simulating dice rolls.
34
+ email: walerian.sobczak@gmail.com
35
+ executables:
36
+ - dice
37
+ extensions: []
38
+ extra_rdoc_files: []
39
+ files:
40
+ - ".gitignore"
41
+ - ".rspec"
42
+ - LICENSE
43
+ - README.md
44
+ - bin/dice
45
+ - dice.gemspec
46
+ - lib/dice.rb
47
+ - lib/dice/parser.rb
48
+ - lib/dice/roller.rb
49
+ - lib/dice/version.rb
50
+ - spec/dice/dice_spec.rb
51
+ - spec/dice/parser_spec.rb
52
+ - spec/dice/roller_spec.rb
53
+ - spec/spec_helper.rb
54
+ homepage: https://github.com/walerian777/dice
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.6.8
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Dice
78
+ test_files:
79
+ - spec/dice/dice_spec.rb
80
+ - spec/dice/parser_spec.rb
81
+ - spec/dice/roller_spec.rb
82
+ - spec/spec_helper.rb