Permalink
Browse files

add thor cli, clear cli renderer, add specs for cli renderer

  • Loading branch information...
1 parent 04b5bb6 commit 88dff84b23a045880ba83df71709d6d6cc7ea9e9 @Gonzih committed Feb 14, 2012
Showing with 55 additions and 33 deletions.
  1. +1 −0 Gemfile.lock
  2. +6 −0 bin/ruby_game_of_life
  3. +2 −0 game_of_life.gemspec
  4. +20 −0 lib/game_of_life/cli.rb
  5. +25 −27 lib/game_of_life/renderers/cli.rb
  6. +0 −5 main.rb
  7. +1 −1 spec/lib/renderers/cli_spec.rb
View
1 Gemfile.lock
@@ -2,6 +2,7 @@ PATH
remote: .
specs:
game_of_life (0.0.1)
+ thor (~> 0.14.6)
GEM
remote: https://rubygems.org/
View
6 bin/ruby_game_of_life
@@ -0,0 +1,6 @@
+#!/usr/bin/env ruby
+
+require 'game_of_life'
+require 'game_of_life/cli'
+
+GameOfLife::Cli.start
View
2 game_of_life.gemspec
@@ -15,6 +15,8 @@ Gem::Specification.new do |gem|
gem.require_paths = ["lib"]
gem.version = GameOfLife::VERSION
+ gem.add_dependency 'thor', '~> 0.14.6'
+
gem.add_development_dependency 'bundler', '>= 1.0'
gem.add_development_dependency 'rspec', '~> 2.8'
gem.add_development_dependency 'guard', '~> 1.0.0'
View
20 lib/game_of_life/cli.rb
@@ -0,0 +1,20 @@
+require 'thor'
+
+module GameOfLife
+ class Cli < Thor
+
+ default_task :start
+
+ desc 'start', 'start game'
+ method_option :renderer,
+ default: 'cli',
+ aliases: '-r',
+ desc: 'which renderer you want to use.'
+ def start
+ if options['renderer'] == 'cli'
+ game = GameOfLife::Renderers::Cli.new
+ game.run
+ end
+ end
+ end
+end
View
52 lib/game_of_life/renderers/cli.rb
@@ -1,37 +1,35 @@
module GameOfLife
module Renderers
- module Cli
- class Renderer
- def run
- include_methods
- run_loop
- end
+ class Cli
+ def run
+ include_methods
+ run_loop
+ end
- def include_methods
- GameOfLife::World.send(:include, WorldMethods)
- GameOfLife::Cell.send(:include, CellMethods)
- end
+ def include_methods
+ GameOfLife::World.send(:include, WorldMethods)
+ GameOfLife::Cell.send(:include, CellMethods)
+ end
- def height
- `tput lines`.to_i || 40
- end
+ def height
+ `tput lines`.to_i || 40
+ end
- def width
- `tput cols`.to_i || 40
- end
+ def width
+ `tput cols`.to_i || 40
+ end
- def world
- @world ||= GameOfLife::World.new(width, height)
- end
+ def world
+ @world ||= GameOfLife::World.new(width, height)
+ end
- def run_loop
- loop do
- output = world.to_s
- system('clear')
- puts output
- world.next!
- sleep(0.1)
- end
+ def run_loop
+ loop do
+ output = world.to_s
+ system('clear')
+ puts output
+ world.next!
+ sleep(0.1)
end
end
View
5 main.rb
@@ -1,5 +0,0 @@
-require 'bundler/setup'
-require 'game_of_life'
-
-game = GameOfLife::Renders::Cli::Renderer.new
-game.run
View
2 spec/lib/renderers/cli_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
describe GameOfLife::Renderers::Cli do
- let (:game) { GameOfLife::Renderers::Cli::Renderer.new }
+ let (:game) { GameOfLife::Renderers::Cli.new }
describe GameOfLife::Cell do
let (:cell) { GameOfLife::Cell.new(false) }

0 comments on commit 88dff84

Please sign in to comment.