fortune_teller 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +7 -0
- data/README.txt +21 -0
- data/Rakefile +13 -0
- data/bin/fortune_teller +11 -0
- data/fortune_teller.gemspec +23 -0
- data/lib/fortune_teller/chooser.rb +83 -0
- data/lib/fortune_teller/list_renderer.rb +11 -0
- data/lib/fortune_teller/logger.rb +8 -0
- data/lib/fortune_teller/nil_panel.rb +19 -0
- data/lib/fortune_teller/panel.rb +22 -0
- data/lib/fortune_teller/reveal.rb +8 -0
- data/lib/fortune_teller/version.rb +3 -0
- data/lib/fortune_teller.rb +62 -0
- data/spec/spec_helper.rb +5 -0
- metadata +79 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2012 Jonathan Thomas
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Total hack of a commandline Ruby version of an origami fortune teller:
|
2
|
+
http://en.wikipedia.org/wiki/Paper_fortune_teller
|
3
|
+
|
4
|
+
To use it simply...
|
5
|
+
install it:
|
6
|
+
gem install fortune_teller
|
7
|
+
|
8
|
+
then, run it:
|
9
|
+
fortune_teller
|
10
|
+
|
11
|
+
Expect to see (something like):
|
12
|
+
Pick one (i.e. type it, then press enter):
|
13
|
+
bird
|
14
|
+
dog
|
15
|
+
chicken
|
16
|
+
mouse
|
17
|
+
exit
|
18
|
+
|
19
|
+
At which point, you type your selection, followed by pressing the
|
20
|
+
enter-key
|
21
|
+
...it's that easy.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
require "rspec/core/rake_task"
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
5
|
+
|
6
|
+
gemspec = eval(File.read("fortune_teller.gemspec"))
|
7
|
+
|
8
|
+
task :build => "#{gemspec.full_name}.gem"
|
9
|
+
|
10
|
+
file "#{gemspec.full_name}.gem" => gemspec.files + ["fortune_teller.gemspec"] do
|
11
|
+
system "gem build fortune_teller.gemspec"
|
12
|
+
system "gem install fortune_teller-#{FortuneTeller::VERSION}.gem"
|
13
|
+
end
|
data/bin/fortune_teller
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "fortune_teller/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "fortune_teller"
|
7
|
+
s.version = FortuneTeller::VERSION
|
8
|
+
s.authors = ["JayTeeSr"]
|
9
|
+
s.email = ["jaytee_sr_at_his-service_dot_net"]
|
10
|
+
s.homepage = "https://github.com/JayTeeSF/fortune_teller"
|
11
|
+
s.summary = %q{Commandline Ruby version of an origami fortune teller: http://en.wikipedia.org/wiki/Paper_fortune_teller}
|
12
|
+
s.description = %q{Commandline Ruby version of an origami fortune teller: http://en.wikipedia.org/wiki/Paper_fortune_teller}
|
13
|
+
s.rubyforge_project = "fortune_teller"
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.bindir = 'bin'
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
|
20
|
+
# specify any dependencies here; for example:
|
21
|
+
s.add_development_dependency "rspec", "~> 2.11.0"
|
22
|
+
#s.add_development_dependency "ruby-debug19"
|
23
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require_relative "list_renderer"
|
2
|
+
require_relative "logger"
|
3
|
+
module FortuneTeller
|
4
|
+
class Chooser
|
5
|
+
LOCATIONS = [ :tl, :tr, :bl, :br ]
|
6
|
+
attr_reader :tl_panel, :tr_panel, :bl_panel, :br_panel
|
7
|
+
attr_reader :list_renderer
|
8
|
+
def initialize(_tl_panel, _tr_panel, _bl_panel = nil, _br_panel = nil, options = {})
|
9
|
+
@tl_panel = _tl_panel
|
10
|
+
Logger.log "tl_panel: #{@tl_panel}"
|
11
|
+
@tr_panel = _tr_panel
|
12
|
+
Logger.log "tr_panel: #{@tr_panel}"
|
13
|
+
@bl_panel = _bl_panel || NilPanel.new
|
14
|
+
Logger.log "bl_panel: #{@bl_panel}"
|
15
|
+
@br_panel = _br_panel || NilPanel.new
|
16
|
+
Logger.log "br_panel: #{@br_panel}"
|
17
|
+
@list_renderer = options[:list_renderer] || ListRenderer.new
|
18
|
+
define_selection_aliases
|
19
|
+
end
|
20
|
+
|
21
|
+
def selections_hash
|
22
|
+
LOCATIONS.reduce({}) {|memo, location|
|
23
|
+
if (value = send( "#{location}_panel" )).present?
|
24
|
+
memo[location] = value
|
25
|
+
end
|
26
|
+
memo
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def selections
|
31
|
+
selections_hash.values
|
32
|
+
end
|
33
|
+
|
34
|
+
def define_selection_aliases
|
35
|
+
selections_hash.each_pair do |k,v|
|
36
|
+
self.class.send(:alias_method, v.to_s.to_sym, k)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def valid? choice
|
41
|
+
respond_to? choice
|
42
|
+
end
|
43
|
+
|
44
|
+
def exit
|
45
|
+
yield if block_given?
|
46
|
+
Logger.log "exiting..."
|
47
|
+
Kernel.exit
|
48
|
+
end
|
49
|
+
alias_method :Q, :exit
|
50
|
+
alias_method :q, :exit
|
51
|
+
|
52
|
+
def choose
|
53
|
+
choice = nil
|
54
|
+
begin
|
55
|
+
self.class.clear_screen( 1.2 )
|
56
|
+
choice = self.class.prompt( list_renderer.render( selections | [:exit] ) )
|
57
|
+
Logger.log("got: #{choice.inspect}")
|
58
|
+
end until( valid?( choice ) )
|
59
|
+
Logger.log("trying it...")
|
60
|
+
self.class.clear_screen(1)
|
61
|
+
send( choice )
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.clear_screen( after = 0 )
|
65
|
+
sleep( after )
|
66
|
+
puts "\e[H\e[2J"
|
67
|
+
end
|
68
|
+
|
69
|
+
LOCATIONS.each do |location|
|
70
|
+
define_method(location) {
|
71
|
+
send( "#{location}_panel" ).pick
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.prompt(text)
|
76
|
+
print text
|
77
|
+
gets.chomp.tap do |result|
|
78
|
+
puts
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
require_relative "panel"
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class ListRenderer
|
2
|
+
attr_reader :separator
|
3
|
+
def initialize( options = {} )
|
4
|
+
@separator = options[:separator] || "\n"
|
5
|
+
end
|
6
|
+
|
7
|
+
def render( text_array )
|
8
|
+
"Pick one (i.e. type it, then press enter):\n" +
|
9
|
+
text_array.map(&:to_s).join( separator ) + "\n"
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative "nil_panel"
|
2
|
+
module FortuneTeller
|
3
|
+
class Panel
|
4
|
+
attr_reader :label
|
5
|
+
attr_accessor :reveal
|
6
|
+
def initialize(_label, _reveal = nil )
|
7
|
+
@label = _label
|
8
|
+
@reveal = _reveal ||= NilPanel.new
|
9
|
+
end
|
10
|
+
alias_method :to_s, :label
|
11
|
+
|
12
|
+
def present?
|
13
|
+
true
|
14
|
+
end
|
15
|
+
|
16
|
+
def pick
|
17
|
+
puts "Flick, flick, flick, flick...\n"
|
18
|
+
reveal.choose
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
require_relative "reveal"
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require_relative "fortune_teller/chooser"
|
2
|
+
module FortuneTeller
|
3
|
+
class Game
|
4
|
+
def jail_reveal
|
5
|
+
Reveal.new( "Oops, you're in Jail!" )
|
6
|
+
end
|
7
|
+
|
8
|
+
def mud_reveal
|
9
|
+
Reveal.new( "Oops, you're in the mud!" )
|
10
|
+
end
|
11
|
+
|
12
|
+
def cookie_reveal
|
13
|
+
Reveal.new( "Wow, you get a cookie!" )
|
14
|
+
end
|
15
|
+
|
16
|
+
def final_choices
|
17
|
+
@final_choices ||= [
|
18
|
+
Panel.new( "blue", choice([jail_reveal, mud_reveal, cookie_reveal]) ),
|
19
|
+
Panel.new( "green", choice([jail_reveal, mud_reveal, cookie_reveal]) ),
|
20
|
+
Panel.new( "pink", choice([jail_reveal, mud_reveal, cookie_reveal]) ),
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
24
|
+
def final_choice_1
|
25
|
+
@final_choice_1 ||= choice(final_choices)
|
26
|
+
end
|
27
|
+
|
28
|
+
def final_choice_2
|
29
|
+
@final_choice_2 ||= choice(final_choices - [ final_choice_1 ])
|
30
|
+
end
|
31
|
+
|
32
|
+
def choice(choices)
|
33
|
+
choices[rand(choices.size)]
|
34
|
+
end
|
35
|
+
|
36
|
+
def level_three_chooser
|
37
|
+
Chooser.new( final_choice_1, final_choice_2 )
|
38
|
+
end
|
39
|
+
|
40
|
+
def level_two_chooser
|
41
|
+
Chooser.new(
|
42
|
+
Panel.new( "9", level_three_chooser ),
|
43
|
+
Panel.new( "7", level_three_chooser ),
|
44
|
+
Panel.new( "3", level_three_chooser ),
|
45
|
+
Panel.new( "5", level_three_chooser ),
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
def level_one_chooser
|
50
|
+
Chooser.new(
|
51
|
+
Panel.new( "bird", level_two_chooser ),
|
52
|
+
Panel.new( "dog", level_two_chooser ),
|
53
|
+
Panel.new( "chicken", level_two_chooser ),
|
54
|
+
Panel.new( "mouse", level_two_chooser )
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
def run
|
59
|
+
level_one_chooser.choose
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fortune_teller
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- JayTeeSr
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.11.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.11.0
|
30
|
+
description: ! 'Commandline Ruby version of an origami fortune teller: http://en.wikipedia.org/wiki/Paper_fortune_teller'
|
31
|
+
email:
|
32
|
+
- jaytee_sr_at_his-service_dot_net
|
33
|
+
executables:
|
34
|
+
- fortune_teller
|
35
|
+
extensions: []
|
36
|
+
extra_rdoc_files: []
|
37
|
+
files:
|
38
|
+
- .gitignore
|
39
|
+
- Gemfile
|
40
|
+
- MIT-LICENSE
|
41
|
+
- README.txt
|
42
|
+
- Rakefile
|
43
|
+
- bin/fortune_teller
|
44
|
+
- fortune_teller.gemspec
|
45
|
+
- lib/fortune_teller.rb
|
46
|
+
- lib/fortune_teller/chooser.rb
|
47
|
+
- lib/fortune_teller/list_renderer.rb
|
48
|
+
- lib/fortune_teller/logger.rb
|
49
|
+
- lib/fortune_teller/nil_panel.rb
|
50
|
+
- lib/fortune_teller/panel.rb
|
51
|
+
- lib/fortune_teller/reveal.rb
|
52
|
+
- lib/fortune_teller/version.rb
|
53
|
+
- spec/spec_helper.rb
|
54
|
+
homepage: https://github.com/JayTeeSF/fortune_teller
|
55
|
+
licenses: []
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project: fortune_teller
|
74
|
+
rubygems_version: 1.8.24
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: ! 'Commandline Ruby version of an origami fortune teller: http://en.wikipedia.org/wiki/Paper_fortune_teller'
|
78
|
+
test_files:
|
79
|
+
- spec/spec_helper.rb
|