bingo_game 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d154c487b76427ba87d2ff7aa1f043ed3305138e
4
+ data.tar.gz: 3e162153ba961ccd1834f81f4ad818553c69cb10
5
+ SHA512:
6
+ metadata.gz: 443c89d12b52f47964bfb92a45eb69420ed0badfaa989e5d5072762fbd92d3194449fc95480a5279ed7341b960519116608581a0f3d27738424c82d82f237fa3
7
+ data.tar.gz: 419d32fa1ec129083879dd777d9802053b87651382b6ef8575e644581e50019d03859577caa0638dcd727d562a8189af0278e115235450d4b56a788e0e90b145
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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bingo_game.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # BingoGame
2
+
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ ```ruby
9
+ gem 'bingo_game'
10
+ ```
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install bingo_game
19
+
20
+ ## Usage
21
+
22
+ Create Seed Data
23
+
24
+ ```
25
+ $ bingo seed
26
+ ```
27
+
28
+ Play BingoGame
29
+
30
+ ```
31
+ $ bingo
32
+ ```
33
+
34
+ ## Development
35
+
36
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
37
+
38
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
39
+
40
+ ## Contributing
41
+
42
+ 1. Fork it ( https://github.com/[my-github-username]/bingo_game/fork )
43
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
44
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
45
+ 4. Push to the branch (`git push origin my-new-feature`)
46
+ 5. Create a new Pull Request
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/bingo ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'bingo_game'
4
+
5
+ BingoGame::Cli.new(ARGV).call
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bingo_game"
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,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bingo_game/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'bingo_game'
8
+ spec.version = BingoGame::VERSION
9
+ spec.authors = ['ganmacs']
10
+ spec.email = ['ganmacs@gmail.com']
11
+
12
+ spec.summary = "Let's play Bingo game"
13
+ spec.homepage = 'https://github.com/ganmacs/bingo_game'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = 'bin'
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.9'
21
+ spec.add_development_dependency 'rake', '~> 10.0'
22
+ spec.add_development_dependency 'rspec'
23
+ end
@@ -0,0 +1,50 @@
1
+ require 'thread'
2
+ require 'bingo_game/seed_generator'
3
+ require 'bingo_game/flipper'
4
+
5
+ module BingoGame
6
+ class Cli
7
+ def initialize(args)
8
+ @args = args
9
+ end
10
+
11
+ def call
12
+ case @args.first
13
+ when 'seed'
14
+ seed_generator.generate
15
+ puts 'Success'
16
+ else
17
+ shutto_suruyatu
18
+ flipper.call
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def shutto_suruyatu
25
+ t = Thread.start {
26
+ loop { random_number }
27
+ }
28
+
29
+ gets # for stopping roulette
30
+ Thread.kill(t)
31
+ printf "\e[2A"
32
+ end
33
+
34
+ def random_number
35
+ [*0..90].shuffle.each do |num|
36
+ puts "#{num}"
37
+ sleep 0.05
38
+ printf "\e[1A"
39
+ end
40
+ end
41
+
42
+ def seed_generator
43
+ @seed_generator ||= SeedGenerator.new
44
+ end
45
+
46
+ def flipper
47
+ @flipper ||= Flipper.new
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,40 @@
1
+ module BingoGame
2
+ class Flipper
3
+ def initialize(file_path = '.seed')
4
+ @file_path = file_path
5
+ end
6
+
7
+ def call
8
+ if finish?
9
+ puts 'Bingo game is over. Go Home!!!'
10
+ else
11
+ n = loaded_seed.first
12
+ update_seed
13
+ store_seed(n)
14
+ puts n
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def store_seed(n)
21
+ File.open('.cards', 'a') do |file|
22
+ file.puts(n)
23
+ end
24
+ end
25
+
26
+ def update_seed
27
+ File.open(@file_path, 'w') do |file|
28
+ file.puts(loaded_seed.drop(1))
29
+ end
30
+ end
31
+
32
+ def finish?
33
+ loaded_seed.size <= 0
34
+ end
35
+
36
+ def loaded_seed
37
+ @loaded_seed ||= File.open(@file_path).map(&:strip)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,20 @@
1
+ module BingoGame
2
+ class SeedGenerator
3
+ def initialize(file_path: '.seed', limit: 90)
4
+ @file_path = file_path
5
+ @limit = limit
6
+ end
7
+
8
+ def generate
9
+ File.open(@file_path, 'w') do |file|
10
+ file.puts(seed)
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def seed
17
+ [*1..@limit].shuffle
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module BingoGame
2
+ VERSION = '0.0.1'
3
+ end
data/lib/bingo_game.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'bingo_game/version'
2
+ require 'bingo_game/cli'
3
+
4
+ module BingoGame
5
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bingo_game
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - ganmacs
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-11 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.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
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: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - ganmacs@gmail.com
58
+ executables:
59
+ - bingo
60
+ - console
61
+ - setup
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".gitignore"
66
+ - ".rspec"
67
+ - ".travis.yml"
68
+ - Gemfile
69
+ - README.md
70
+ - Rakefile
71
+ - bin/bingo
72
+ - bin/console
73
+ - bin/setup
74
+ - bingo_game.gemspec
75
+ - lib/bingo_game.rb
76
+ - lib/bingo_game/cli.rb
77
+ - lib/bingo_game/flipper.rb
78
+ - lib/bingo_game/seed_generator.rb
79
+ - lib/bingo_game/version.rb
80
+ homepage: https://github.com/ganmacs/bingo_game
81
+ licenses: []
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.4.5
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Let's play Bingo game
103
+ test_files: []