Permalink
Browse files

convert data into integers

  • Loading branch information...
1 parent 1e1045c commit 2eb51db35316a7b990d4319c497db3c9f725f6db Tobias Bielohlawek committed Jan 7, 2013
Showing with 22 additions and 7 deletions.
  1. +21 −6 lib/nabaztag_hack_kit/mods/playground.rb
  2. +1 −1 lib/nabaztag_hack_kit/version.rb
@@ -6,7 +6,26 @@ module NabaztagHackKit
module Mods
module Playground
+ module Helpers
+ def commands(commands, command_values)
+ Array(commands).zip(command_values).map do |command, values|
+ [command] + int_array(values.split(","))
+ end
+ end
+
+ def int_array(array)
+ array.map do |entry|
+ if entry.to_i.to_s == entry
+ entry.to_i
+ else
+ entry
+ end
+ end
+ end
+ end
+
def self.registered(app)
+ app.helpers Playground::Helpers
app.get "/" do
redirect "/playground"
@@ -32,19 +51,15 @@ def self.registered(app)
app.post "/playground/bunnies/:bunnyid" do # {"command"=>["40"], "command_values"=>[["1,2,3,4"],[]]}
if bunny = Bunny.find(params[:bunnyid])
- bunny.queue_commands(Array(params[:command]).zip(params[:command_values]).map do |command, values|
- [command, *values.split(",")]
- end)
+ bunny.queue_commands commands(params[:command], params[:command_values])
bunny.to_json
end
end
app.post "/playground/bunnies" do # {"bunny"=>["0019db9c2daf"], "command"=>["40"], "command_values"=>[["1,2,3,4"],[]]}
Array(params[:bunny]).uniq.each do |bunnyid|
if bunny = Bunny.find(bunnyid)
- bunny.queue_commands(Array(params[:command]).zip(params[:command_values]).map do |command, values|
- [command, *values.split(",")]
- end)
+ bunny.queue_commands commands(params[:command], params[:command_values])
end
end
@@ -1,3 +1,3 @@
module NabaztagHackKit
- VERSION = "0.1.0.beta1"
+ VERSION = "0.1.0.beta3"
end

0 comments on commit 2eb51db

Please sign in to comment.