wiesenberg_gem_building_practice 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a1d871e737ce0fe761ba283307a310f98569f5ff
4
+ data.tar.gz: 9f7a0a7f487bbf024956d632a3c8fa36a36decce
5
+ SHA512:
6
+ metadata.gz: 5ee971112fa89562d790050324a332156baeb545be1abb4af711a87ea1c90051261c01c916a9885595dafb915ef0eab4fdf6101887c4f53f763d8dde98a41561
7
+ data.tar.gz: 479460956532eef74d1c008fe15ecb3bf73c5c383e8fb532bc386a6a9de459900bff65887702e3b63ba27423f19de7d61260b2fd8051a9f0ea154f9e3edc3f06
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.localized ADDED
File without changes
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.2.4
5
+ before_install: gem install bundler -v 1.13.6
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wiesenberg_gem_building_practice.gemspec
4
+
5
+ gemspec
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # WiesenbergGemBuildingPractice
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/wiesenberg_gem_building_practice`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'wiesenberg_gem_building_practice'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install wiesenberg_gem_building_practice
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/wiesenberg_gem_building_practice.
36
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/.DS_Store ADDED
Binary file
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wiesenberg_gem_building_practice"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/.DS_Store ADDED
Binary file
@@ -0,0 +1,164 @@
1
+ require "wiesenberg_gem_building_practice/version"
2
+
3
+ module WiesenbergGemBuildingPractice
4
+ # Gem Building Practice: Rock Paper Scissors
5
+
6
+ module RockPaperScissors
7
+
8
+ require 'io/console'
9
+
10
+ class Game
11
+
12
+ def play
13
+ welcome
14
+ enter_names
15
+ loop do
16
+ loop do
17
+ choose_handshapes
18
+ render_choices
19
+ break if winner_found?
20
+ end
21
+ declare_winner
22
+ break unless another_game?
23
+ end
24
+ end
25
+
26
+ def welcome
27
+
28
+ print %{
29
+
30
+ WELCOME TO ROCK-PAPER-SCISSORS!
31
+
32
+ Rules:
33
+ 1. Choose whether to play against a friend or the computer.
34
+ 2. Each human player chooses a handshape. The computer chooses one
35
+ at random.
36
+ 3. When both players choose the same hand shape, it is a draw. Go
37
+ back to step 2.
38
+ 4. When the hand shapes are different, the winner is as follows:
39
+ (a) Rock and scissors: rock wins
40
+ (b) Paper and rock: paper wins
41
+ (c) scissors and paper: scissors win
42
+ }
43
+
44
+ end # welcome
45
+
46
+ def enter_names
47
+ print "\n Are you playing against the computer (Y or N)? "
48
+ until %w(Y N).include? (answer = gets.chomp)
49
+ print " Incorrect answer - try again: "
50
+ end
51
+ puts
52
+ @player_1 = Human.new(enter_name("First"))
53
+ @player_2 = Computer.new("Computer") if answer == "Y"
54
+ @player_2 = Human.new(enter_name("Next")) if answer == "N"
55
+ end
56
+
57
+ def enter_name(player_number)
58
+ print " #{player_number.ljust(5, padstr = " ")} player, please enter your name: "
59
+ while "" == (name = gets.chomp)
60
+ print " Incorrect answer - try again: "
61
+ end
62
+ name
63
+ end
64
+
65
+ def choose_handshapes
66
+ [@player_1, @player_2].each { |player| player.choose_handshape}
67
+ end
68
+
69
+ def render_choices
70
+ puts "\n #{"Name".ljust(12, padstr = " ")}#{(" " * 5)}Handshape"
71
+ puts " #{("-" * 12) + (" " * 5) + ("-" * 9)}"
72
+ [@player_1, @player_2].each { |player| puts " #{(player.name.ljust(12, padstr = " ")) + (" " * 5) + player.handshape.to_s.capitalize}" }
73
+ end
74
+
75
+ def winner_found?
76
+ case @player_1.handshape
77
+ when @player_2.handshape
78
+ puts "\n Draw - choose again\n"
79
+ return false
80
+ when :rock
81
+ @player_2.handshape == :scissors ? winner_1 : winner_2
82
+ when :paper
83
+ @player_2.handshape == :rock ? winner_1 : winner_2
84
+ when :scissors
85
+ @player_2.handshape == :paper ? winner_1 : winner_2
86
+ end
87
+ true
88
+ end
89
+
90
+ def winner_1
91
+ @winner = @player_1.name
92
+ end
93
+
94
+ def winner_2
95
+ @winner = @player_2.name
96
+ end
97
+
98
+ def declare_winner
99
+ print "\n Winner is #{@winner}. "
100
+ puts "Congratulations!" if @winner != "Computer"
101
+ puts "Bad luck!" if @winner == "Computer"
102
+ end
103
+
104
+ def another_game?
105
+ print "\n Another game (Y or N)? "
106
+ until %w(Y N).include? (answer = gets.chomp)
107
+ print "Incorrect answer - try again: "
108
+ end
109
+ return true if answer == "Y"
110
+ puts "\n Thanks for playing. Goodbye!\n\n"
111
+ false
112
+ end
113
+
114
+ end # class Game
115
+
116
+ class Player
117
+
118
+ def initialize(name)
119
+ @name = name
120
+ end
121
+
122
+ attr_reader :name, :handshape
123
+
124
+ end # class Player
125
+
126
+ class Human < Player
127
+
128
+ def choose_handshape
129
+ puts "\n #{@name}, choose your handshape - Rock, Paper, Scissors (R, P or S)."
130
+ print " (Your answer will not be shown to keep it secret from your opponent.): "
131
+ until %w(R P S).include? (answer = STDIN.noecho(&:gets).chomp)
132
+ print " Incorrect answer - try again: "
133
+ end
134
+ puts
135
+ case answer
136
+ when "R"
137
+ @handshape = :rock
138
+ when "P"
139
+ @handshape = :paper
140
+ when "S"
141
+ @handshape = :scissors
142
+ end
143
+ @handshape
144
+ end
145
+
146
+ end # class Human
147
+
148
+ class Computer < Player
149
+
150
+ def choose_handshape
151
+ puts "\n Computer is choosing ..."
152
+ sleep(0.5)
153
+ @handshape = [:rock, :paper, :scissors].sample
154
+ end
155
+
156
+ end # end class Computer
157
+
158
+ end # module RockPaperScissors
159
+
160
+ end # module WiesenbergGemBuildingPractice
161
+
162
+
163
+ # WiesenbergGemBuildingPractice::RockPaperScissors::Game.new.play
164
+
@@ -0,0 +1,3 @@
1
+ module WiesenbergGemBuildingPractice
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,160 @@
1
+ # Gem Building Practice: Rock Paper Scissors
2
+
3
+ module RockPaperScissors
4
+
5
+ require 'io/console'
6
+
7
+ class Game
8
+
9
+ def play
10
+ welcome
11
+ enter_names
12
+ loop do
13
+ loop do
14
+ choose_handshapes
15
+ render_choices
16
+ break if winner_found?
17
+ end
18
+ declare_winner
19
+ break unless another_game?
20
+ end
21
+ end
22
+
23
+ def welcome
24
+
25
+ print %{
26
+
27
+ WELCOME TO ROCK-PAPER-SCISSORS!
28
+
29
+ Rules:
30
+ 1. Choose whether to play against a friend or the computer.
31
+ 2. Each human player chooses a handshape. The computer chooses one
32
+ at random.
33
+ 3. When both players choose the same hand shape, it is a draw. Go
34
+ back to step 2.
35
+ 4. When the hand shapes are different, a winner is chosen as follows:
36
+ (a) Rock and scissors: rock wins
37
+ (b) Paper and rock: paper wins
38
+ (c) scissors and paper: scissors win
39
+ }
40
+
41
+ end # welcome
42
+
43
+ def enter_names
44
+ print "\n Are you playing against the computer (Y or N)? "
45
+ until %w(Y N).include? (answer = gets.chomp)
46
+ print " Incorrect answer - try again: "
47
+ end
48
+ puts
49
+ @player_1 = Human.new(enter_name("First"))
50
+ @player_2 = Computer.new("Computer") if answer == "Y"
51
+ @player_2 = Human.new(enter_name("Next")) if answer == "N"
52
+ end
53
+
54
+ def enter_name(player_number)
55
+ print " #{player_number.ljust(5, padstr = " ")} player, please enter your name: "
56
+ while "" == (name = gets.chomp)
57
+ print " Incorrect answer - try again: "
58
+ end
59
+ name
60
+ end
61
+
62
+ def choose_handshapes
63
+ [@player_1, @player_2].each { |player| player.choose_handshape}
64
+ end
65
+
66
+ def render_choices
67
+ puts "\n #{"Name".ljust(12, padstr = " ")}#{(" " * 5)}Handshape"
68
+ puts " #{("-" * 12) + (" " * 5) + ("-" * 9)}"
69
+ [@player_1, @player_2].each { |player| puts " #{(player.name.ljust(12, padstr = " ")) + (" " * 5) + player.handshape.to_s.capitalize}" }
70
+ end
71
+
72
+ def winner_found?
73
+ case @player_1.handshape
74
+ when @player_2.handshape
75
+ puts "\n Draw - choose again\n"
76
+ return false
77
+ when :rock
78
+ @player_2.handshape == :scissors ? winner_1 : winner_2
79
+ when :paper
80
+ @player_2.handshape == :rock ? winner_1 : winner_2
81
+ when :scissors
82
+ @player_2.handshape == :paper ? winner_1 : winner_2
83
+ end
84
+ true
85
+ end
86
+
87
+ def winner_1
88
+ @winner = @player_1.name
89
+ end
90
+
91
+ def winner_2
92
+ @winner = @player_2.name
93
+ end
94
+
95
+ def declare_winner
96
+ print "\n Winner is #{@winner}. "
97
+ puts "Congratulations!" if @winner != "Computer"
98
+ puts "Bad luck!" if @winner == "Computer"
99
+ end
100
+
101
+ def another_game?
102
+ print "\n Another game (Y or N)? "
103
+ until %w(Y N).include? (answer = gets.chomp)
104
+ print "Incorrect answer - try again: "
105
+ end
106
+ return true if answer == "Y"
107
+ puts "\n Thanks for playing. Goodbye!\n\n"
108
+ false
109
+ end
110
+
111
+ end # class Game
112
+
113
+ class Player
114
+
115
+ def initialize(name)
116
+ @name = name
117
+ end
118
+
119
+ attr_reader :name, :handshape
120
+
121
+ end # class Player
122
+
123
+ class Human < Player
124
+
125
+ def choose_handshape
126
+ puts "\n #{@name}, choose your handshape - Rock, Paper, Scissors (R, P or S)."
127
+ print " (Your answer will not be shown to keep it secret from your opponent.): "
128
+ until %w(R P S).include? (answer = STDIN.noecho(&:gets).chomp)
129
+ print " Incorrect answer - try again: "
130
+ end
131
+ puts
132
+ case answer
133
+ when "R"
134
+ @handshape = :rock
135
+ when "P"
136
+ @handshape = :paper
137
+ when "S"
138
+ @handshape = :scissors
139
+ end
140
+ @handshape
141
+ end
142
+
143
+ end # class Human
144
+
145
+ class Computer < Player
146
+
147
+ def choose_handshape
148
+ puts "\n Computer is choosing ..."
149
+ sleep(0.5)
150
+ @handshape = [:rock, :paper, :scissors].sample
151
+ end
152
+
153
+ end # end class Computer
154
+
155
+ end # module RockPaperScissors
156
+
157
+
158
+ RockPaperScissors::Game.new.play
159
+
160
+
File without changes
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wiesenberg_gem_building_practice/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wiesenberg_gem_building_practice"
8
+ spec.version = WiesenbergGemBuildingPractice::VERSION
9
+ spec.authors = ["David Wiesenberg"]
10
+ spec.email = ["david_britta@yahoo.com"]
11
+
12
+ spec.summary = %q{Gem building practice}
13
+ spec.description = %q{A gem program for Rock-Paper-Scissors}
14
+ spec.homepage = "https://github.com/dwiesenberg/wiesenberg_gem_building_practice.git"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against " \
22
+ "public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
26
+ f.match(%r{^(test|spec|features)/})
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency "bundler", "~> 1.13"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wiesenberg_gem_building_practice
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - David Wiesenberg
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-12-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: A gem program for Rock-Paper-Scissors
56
+ email:
57
+ - david_britta@yahoo.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".DS_Store"
63
+ - ".gitignore"
64
+ - ".localized"
65
+ - ".rspec"
66
+ - ".travis.yml"
67
+ - Gemfile
68
+ - README.md
69
+ - Rakefile
70
+ - bin/.DS_Store
71
+ - bin/console
72
+ - bin/setup
73
+ - lib/.DS_Store
74
+ - lib/wiesenberg_gem_building_practice.rb
75
+ - lib/wiesenberg_gem_building_practice/.DS_Store
76
+ - lib/wiesenberg_gem_building_practice/version.rb
77
+ - rock_paper_scissors.rb
78
+ - wiesenberg_gem_building_prac.textClipping
79
+ - wiesenberg_gem_building_practice.gemspec
80
+ homepage: https://github.com/dwiesenberg/wiesenberg_gem_building_practice.git
81
+ licenses: []
82
+ metadata:
83
+ allowed_push_host: https://rubygems.org
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.4.8
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Gem building practice
104
+ test_files: []