Class: RChoice::RedisChooser
- Defined in:
- lib/rchoice/choosers/redis_chooser.rb
Instance Method Summary collapse
- #call(choice) ⇒ Object
- #get_choice(choice) ⇒ Object
- #get_choice_num(choice) ⇒ Object
- #print_line(ln) ⇒ Object
Instance Method Details
#call(choice) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/rchoice/choosers/redis_chooser.rb', line 3 def call(choice) print_line "Choose #{choice.name}" choice..each_with_index do |op,i| print_line "#{i}. #{choice.option_presenter[op]}" end get_choice(choice) end |
#get_choice(choice) ⇒ Object
13 14 15 |
# File 'lib/rchoice/choosers/redis_chooser.rb', line 13 def get_choice(choice) choice.[get_choice_num(choice)] end |
#get_choice_num(choice) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/rchoice/choosers/redis_chooser.rb', line 16 def get_choice_num(choice) require 'redis' redis = Redis.new(:host => "spadefish.redistogo.com", :port => 9897, :password => "511c6d49855d3551c335781860c06cb3") k = "choice-#{choice.choice_id}" puts "waiting for #{k}" File.create "vol/choice.txt",k (0...10000).each do |i| val = redis.get(k) if val.present? return val.safe_to_i else sleep(0.5) end end raise "no answer" end |
#print_line(ln) ⇒ Object
10 11 12 |
# File 'lib/rchoice/choosers/redis_chooser.rb', line 10 def print_line(ln) puts ln end |