Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

convert data into integers

  • Loading branch information...
commit 2eb51db35316a7b990d4319c497db3c9f725f6db 1 parent 1e1045c
@rngtng authored
View
27 lib/nabaztag_hack_kit/mods/playground.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,9 +51,7 @@ 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
@@ -42,9 +59,7 @@ def self.registered(app)
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
View
2  lib/nabaztag_hack_kit/version.rb
@@ -1,3 +1,3 @@
module NabaztagHackKit
- VERSION = "0.1.0.beta1"
+ VERSION = "0.1.0.beta3"
end
Please sign in to comment.
Something went wrong with that request. Please try again.