rps_gem 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.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/bin/play-rps +13 -0
  3. data/lib/rps_gem.rb +34 -0
  4. data/lib/rps_gem_man +13 -0
  5. metadata +47 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4371bd53b095ebd1466bcfd4263e22074e34a5f9
4
+ data.tar.gz: c176d6ff7c248d3970a63fe8c4fdb04f677dbf2b
5
+ SHA512:
6
+ metadata.gz: d96a86034bd79bb67aebced0602d0703a6d9da54db10dab4e5dc7cc619af5bd55ab7405d91ccb87e4a8b14cf22e8a1fd38603a20c50f0eb4d11473de34310770
7
+ data.tar.gz: 0c718215b2152579035f4da92fe2a0104bc58ff8978ee749e48f8cd71c84b694b5565f7393702f3924bc625b026f877003ecd62f0fa081e5510cb6dbd669be3a
data/bin/play-rps ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rps_gem'
4
+
5
+ go = RpsGem::LetsPlay.new
6
+
7
+ if(ARGV[0].nil?)
8
+ puts "Make a choice"
9
+ elsif ARGV[0].eql?("-e")
10
+ RpsGem::LetsPlay.example
11
+ else
12
+ puts go.play(ARGV[0])
13
+ end
data/lib/rps_gem.rb ADDED
@@ -0,0 +1,34 @@
1
+ module RpsGem
2
+ class LetsPlay
3
+ def play(player_op)
4
+ options = ["rock","paper","scissors"]
5
+ player_choice = options.find_index {|choice| choice.match(/^#{player_op.downcase}/)}
6
+ computer_choice = rand(options.length)
7
+ if player_choice.nil?
8
+ "Invalid Choice :P"
9
+ else
10
+ if(options[computer_choice]==options[player_choice])
11
+ "Tie!"
12
+ else
13
+ puts "Computer plyaed #{options[computer_choice]}"
14
+ if(self.winner(options[player_choice], options[computer_choice])==options[player_choice])
15
+ "You Won!"
16
+ else
17
+ "You Loose!"
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ def winner(p1, p2)
24
+ wins = {rock: :scissors, scissors: :paper, paper: :rock}
25
+ {true => p1, false => p2}[wins[p1] == p2]
26
+ end
27
+
28
+ def self.example
29
+ path = File.dirname(__FILE__)
30
+ system(" man #{path}/rps_gem_man")
31
+ end
32
+
33
+ end
34
+ end
data/lib/rps_gem_man ADDED
@@ -0,0 +1,13 @@
1
+ .TH man 8 "06 May 2010" "1.0" "nuseradd man page"
2
+ .SH NAME
3
+ play-rps \- Gem to play Command-line Rock, Paper and Scissors game
4
+ .SH SYNOPSIS
5
+ play-rps rock|paper|scissor
6
+ .SH DESCRIPTION
7
+ It is a simple Rock, Paper and Scissors game. You have to choose an option between rock, paper and scissor to play the game.
8
+ .SH OPTIONS
9
+ -e Exapmle: "play-rps rock"
10
+ .SH BUGS
11
+ No known bugs.
12
+ .SH AUTHOR
13
+ Balram Khichar (balram@codebrahma.com)
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rps_gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Balram
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - balram@codebrama.com
16
+ executables:
17
+ - play-rps
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - bin/play-rps
22
+ - lib/rps_gem.rb
23
+ - lib/rps_gem_man
24
+ homepage:
25
+ licenses: []
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.4.4
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Let's play Rock, Paper and Scissors game
47
+ test_files: []