nabaztag_hack_kit 0.1.0.beta8 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd395348ad5c455b3587202f9fbf9782259cf829
4
- data.tar.gz: e23d930933234912c081a5425003577a0db51fd2
3
+ metadata.gz: c22883b8dddfe8fe2395c1bdd0d22c0df2b33dcf
4
+ data.tar.gz: 1c20b4f56c758b25bc542e3226d26663333ef57f
5
5
  SHA512:
6
- metadata.gz: 896a8d1f950033dfa49494747a982a3c58fa4ac92565e44725effbaecdce2c39ac46b73a12a8975eeab9f0c7f34df1550577e69705cdcbdc8c43eb953e6643be
7
- data.tar.gz: 14abe18bd4b1502a7682aa5b5c24c579dfc51b36bcdc3d3bd290bd500407fb80fa686bfc47d4ee8d2beb2631b725d7b6af039c7b75e9bcf47a970721eb023c19
6
+ metadata.gz: 4b773982a492c28c15dc427b2e430cd2fa04bae067ac8c8ec391db2042731faada8266303ab270e46487aedcd4336b70e673103558e2608787a6943ae2303eb8
7
+ data.tar.gz: 8067914e37fa19ac263a5c9100957effc70ef92c56d829309a651bf3b9248a9d6a0f5125d188ae5be3ee9b8e434f14ee139e54451a438d83e2a30a141c8f5a9d
@@ -0,0 +1,8 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.3
5
+
6
+ Style/ModuleFunction:
7
+ EnforcedStyle:
8
+ extend_self
@@ -0,0 +1,57 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2017-12-03 00:04:40 +0100 using RuboCop version 0.51.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 2
10
+ Lint/HandleExceptions:
11
+ Exclude:
12
+ - 'spec/unit/server_spec.rb'
13
+
14
+ # Offense count: 6
15
+ Metrics/AbcSize:
16
+ Max: 50
17
+
18
+ # Offense count: 2
19
+ # Configuration parameters: CountComments, ExcludedMethods.
20
+ Metrics/BlockLength:
21
+ Max: 44
22
+
23
+ # Offense count: 19
24
+ # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
25
+ # URISchemes: http, https
26
+ Metrics/LineLength:
27
+ Max: 145
28
+
29
+ # Offense count: 5
30
+ # Configuration parameters: CountComments.
31
+ Metrics/MethodLength:
32
+ Max: 40
33
+
34
+ # Offense count: 8
35
+ Style/ClassVars:
36
+ Exclude:
37
+ - 'examples/record/server.rb'
38
+ - 'lib/nabaztag_hack_kit/mods/callback.rb'
39
+
40
+ # Offense count: 16
41
+ Style/Documentation:
42
+ Exclude:
43
+ - 'spec/**/*'
44
+ - 'test/**/*'
45
+ - 'examples/basic/config.ru'
46
+ - 'examples/record/server.rb'
47
+ - 'lib/nabaztag_hack_kit.rb'
48
+ - 'lib/nabaztag_hack_kit/bunny.rb'
49
+ - 'lib/nabaztag_hack_kit/message.rb'
50
+ - 'lib/nabaztag_hack_kit/message/helper.rb'
51
+ - 'lib/nabaztag_hack_kit/mods/button.rb'
52
+ - 'lib/nabaztag_hack_kit/mods/callback.rb'
53
+ - 'lib/nabaztag_hack_kit/mods/logger.rb'
54
+ - 'lib/nabaztag_hack_kit/mods/playground.rb'
55
+ - 'lib/nabaztag_hack_kit/mods/recording.rb'
56
+ - 'lib/nabaztag_hack_kit/mods/streaming.rb'
57
+ - 'lib/nabaztag_hack_kit/server.rb'
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source "http://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'http://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in nabaztag_hack_kit.gemspec
4
6
  gemspec
data/Rakefile CHANGED
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/setup'
2
4
  require 'bundler/gem_tasks'
@@ -1,7 +1,9 @@
1
1
 
2
- desc "Test bytcode"
2
+ # frozen_string_literal: true
3
+
4
+ desc 'Test bytcode'
3
5
  task :test do
4
6
  puts `bin/mtl_simu test/test.mtl`
5
7
  end
6
8
 
7
- task :default => :test
9
+ task default: :test
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # A sample Gemfile
2
- source "http://rubygems.org"
4
+ source 'http://rubygems.org'
3
5
 
4
- gem "nabaztag_hack_kit", path:"../../"
6
+ gem 'nabaztag_hack_kit', path: '../../'
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  $stdout.sync = true
4
5
 
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # A sample Gemfile
2
- source "http://rubygems.org"
4
+ source 'http://rubygems.org'
3
5
 
4
- gem "nabaztag_hack_kit"
5
- gem "ruby-echonest"
6
+ gem 'nabaztag_hack_kit'
7
+ gem 'ruby-echonest'
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require './server'
@@ -6,14 +7,14 @@ require './server'
6
7
  # use Rack::Reloader, 0
7
8
 
8
9
  ECHONEST_CFG = {
9
- :key => "",
10
- }
10
+ key: ''
11
+ }.freeze
11
12
 
12
13
  SOUNDCLOUD_CFG = {
13
- :client_id => "",
14
- :client_secret => "",
15
- :username => "",
16
- :password => "",
17
- }
14
+ client_id: '',
15
+ client_secret: '',
16
+ username: '',
17
+ password: ''
18
+ }.freeze
18
19
 
19
20
  run Record::Server.new(ECHONEST_CFG, SOUNDCLOUD_CFG)
@@ -1,9 +1,10 @@
1
- require "nabaztag_hack_kit/server"
2
- require "soundcloud"
3
- require "echonest"
1
+ # frozen_string_literal: true
4
2
 
5
- class Server < NabaztagHackKit::Server
3
+ require 'nabaztag_hack_kit/server'
4
+ require 'soundcloud'
5
+ require 'echonest'
6
6
 
7
+ class Server < NabaztagHackKit::Server
7
8
  def initialize(echonest_cfg, soundcloud_cfg)
8
9
  super
9
10
  @@echonest = Echonest(echonest_cfg[:key])
@@ -33,7 +34,7 @@ class Server < NabaztagHackKit::Server
33
34
  puts beats = an.tempo.to_i
34
35
  loud = an.loudness.to_i
35
36
 
36
- if beats > 0
37
+ if beats.positive?
37
38
  {
38
39
  REC_START => [3],
39
40
  EAR_L => norm(an.segments.first.timbre, 16),
@@ -41,7 +42,7 @@ class Server < NabaztagHackKit::Server
41
42
  BMP => [beats],
42
43
  LED_L1 => norm(an.segments.first.timbre, 255),
43
44
  LED_L2 => norm([beats, beats, beats, beats, loud, loud, loud, loud], 255),
44
- LED_L3 => norm(norm an.segments.first.pitches, 255),
45
+ LED_L3 => norm(norm(an.segments.first.pitches, 255))
45
46
  }
46
47
  else
47
48
  {
@@ -57,52 +58,48 @@ class Server < NabaztagHackKit::Server
57
58
  end
58
59
 
59
60
  def upload(file)
60
- @@soundcloud.post('/tracks', :track => {
61
- :title => 'Bunny Boogie',
62
- :asset_data => File.new(file)
63
- })
61
+ @@soundcloud.post('/tracks', track: {
62
+ title: 'Bunny Boogie',
63
+ asset_data: File.new(file)
64
+ })
64
65
  {
65
- EAR_L => [16,0,16,0,16,0],
66
+ EAR_L => [16, 0, 16, 0, 16, 0],
66
67
  LED_L1 => [0],
67
68
  LED_L2 => [0],
68
69
  LED_L3 => [0]
69
70
  }
70
71
  end
71
72
 
72
- on "start" do
73
+ on 'start' do
73
74
  @@dance = true
74
- if @@recording
75
- @@recording = false
76
- end
77
- send_nabaztag({
78
- REC_STOP => []
79
- })
75
+ @@recording = false if @@recording
76
+ send_nabaztag(REC_STOP => [])
80
77
  end
81
78
 
82
- on "button-pressed" do
83
- send_nabaztag if @@recording
84
- @@recording = false
85
- {
86
- REC_STOP => [],
87
- LED_L1 => [100,0,0,0],
88
- LED_L2 => [0,100,0,100],
89
- LED_L3 => [0,0,100,0]
90
- }
91
- else
92
- @@recording = true
93
- sec = @@dance ? 3 : 0
94
- {
95
- REC_START => [sec]
96
- }
97
- end
79
+ on 'button-pressed' do
80
+ send_nabaztag(if @@recording
81
+ @@recording = false
82
+ {
83
+ REC_STOP => [],
84
+ LED_L1 => [100, 0, 0, 0],
85
+ LED_L2 => [0, 100, 0, 100],
86
+ LED_L3 => [0, 0, 100, 0]
87
+ }
88
+ else
89
+ @@recording = true
90
+ sec = @@dance ? 3 : 0
91
+ {
92
+ REC_START => [sec]
93
+ }
94
+ end)
98
95
  end
99
96
 
100
- on "recording-finished" do |file_name|
97
+ on 'recording-finished' do |file_name|
101
98
  @@recording = false
102
- send_nabaztag if @@dance
103
- dance
104
- else
105
- upload(file_name)
106
- end
99
+ send_nabaztag(if @@dance
100
+ dance
101
+ else
102
+ upload(file_name)
103
+ end)
107
104
  end
108
105
  end
@@ -1,14 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  BIN_NAME = 'mtl_compiler'
4
5
  BIN_PATH = File.dirname(__FILE__)
5
- BIN = File.join(File.expand_path("../mtl_linux", BIN_PATH), BIN_NAME)
6
+ BIN = File.join(File.expand_path('../mtl_linux', BIN_PATH), BIN_NAME)
6
7
  FILE = ARGV.first
7
8
 
8
9
  FILTER = ENV['FILTER'] || "| grep -v 'bytes' | grep -e'[a-z]'"
9
10
  MERGE = File.join(BIN_PATH, 'mtl_merge')
10
11
  TMP = ENV['TMP'] || '.tmp.mtl'
11
- OUT = ENV['OUT'] || "bytecode.bin"
12
+ OUT = ENV['OUT'] || 'bytecode.bin'
12
13
 
13
14
  unless FILE
14
15
  puts "usage: #{File.basename(__FILE__)} [filename]"
@@ -19,11 +20,11 @@ end
19
20
  `TMP='#{TMP}' #{MERGE} #{FILE}`
20
21
 
21
22
  # compile
22
- out = if File.exists?(BIN)
23
- `#{BIN} -s #{TMP} #{OUT} 2>&1 #{FILTER}`
24
- else
25
- "local binary not found: #{BIN}"
26
- end
23
+ out = if File.exist?(BIN)
24
+ `#{BIN} -s #{TMP} #{OUT} 2>&1 #{FILTER}`
25
+ else
26
+ "local binary not found: #{BIN}"
27
+ end
27
28
 
28
29
  puts out
29
30
  `rm #{TMP}`
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  # Merge a file with its includes, pass filename as first argument
4
5
 
@@ -19,7 +20,7 @@ end
19
20
 
20
21
  def src_file(name)
21
22
  [BASE_DIR, BASE_DIR_LIB].each do |dir|
22
- if (path = File.join(dir, name)) && File.exists?(path)
23
+ if (path = File.join(dir, name)) && File.exist?(path)
23
24
  return path
24
25
  end
25
26
  end
@@ -28,9 +29,7 @@ end
28
29
 
29
30
  File.open(TMP, 'w') do |out|
30
31
  File.open(file).each_line do |line|
31
- if line =~ /\A#include "([^"]+)"/
32
- line = `cat #{src_file(mtl_file($1))}`
33
- end
32
+ line = `cat #{src_file(mtl_file(Regexp.last_match(1)))}` if line =~ /\A#include "([^"]+)"/
34
33
  out.puts line
35
34
  end
36
35
  end
@@ -1,14 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  BIN_NAME = File.basename(__FILE__)
4
5
  BIN_PATH = File.dirname(__FILE__)
5
- BIN = File.join(File.expand_path("../mtl_linux", BIN_PATH), BIN_NAME)
6
+ BIN = File.join(File.expand_path('../mtl_linux', BIN_PATH), BIN_NAME)
6
7
  FILE = ARGV.first
7
8
 
8
9
  FILTER = ENV['FILTER'] || "| grep -v 'bytes' | grep -e'[a-z]'"
9
10
  MERGE = File.join(BIN_PATH, 'mtl_merge')
10
11
  TMP = ENV['TMP'] || '.tmp.mtl'
11
- OUT = ENV['OUT'] || "bytecode.bin"
12
+ OUT = ENV['OUT'] || 'bytecode.bin'
12
13
 
13
14
  unless FILE
14
15
  puts "usage: #{File.basename(__FILE__)} [filename]"
@@ -19,11 +20,11 @@ end
19
20
  `TMP='#{TMP}' #{MERGE} #{FILE}`
20
21
 
21
22
  # simu
22
- out = if File.exists?(BIN)
23
- `#{BIN} --source #{TMP}`
24
- else
25
- "local binary not found: #{BIN}"
26
- end
23
+ out = if File.exist?(BIN)
24
+ `#{BIN} --source #{TMP}`
25
+ else
26
+ "local binary not found: #{BIN}"
27
+ end
27
28
 
28
29
  puts out
29
30
  `rm #{TMP}`
@@ -1 +1,2 @@
1
- # nothing to here as gem process will execute `make` and `make install`
1
+ # frozen_string_literal: true
2
+ # nothing to here as gem process will execute `make` and `make install`
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'nabaztag_hack_kit/version'
2
4
 
3
5
  module NabaztagHackKit
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'nabaztag_hack_kit/message'
2
4
 
3
5
  module NabaztagHackKit
@@ -43,11 +45,11 @@ module NabaztagHackKit
43
45
  Message.build(*@queued_commands.shift || Message::Api::OK)
44
46
  end
45
47
 
46
- def to_json(state = nil, deepth = nil)
48
+ def to_json(_state = nil, _deepth = nil)
47
49
  {
48
- :id => id,
49
- :last_seen => last_seen,
50
- :queued_commands_size => queued_commands.size,
50
+ id: id,
51
+ last_seen: last_seen,
52
+ queued_commands_size: queued_commands.size
51
53
  }.to_json
52
54
  end
53
55
  end
@@ -1,20 +1,22 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module NabaztagHackKit
2
4
  module Message
3
5
  extend self
4
6
 
5
7
  def build(*commands)
6
8
  commands = if commands.first.is_a?(Hash)
7
- commands.first
8
- elsif !commands.first.is_a?(Array)
9
- [commands]
10
- else
11
- commands
12
- end
9
+ commands.first
10
+ elsif !commands.first.is_a?(Array)
11
+ [commands]
12
+ else
13
+ commands
14
+ end
13
15
 
14
- pack full_message commands.map { |cmd, *data|
16
+ pack full_message(commands.map do |cmd, *data|
15
17
  data = convert_data(data)
16
18
  [cmd.to_i] + to_3b(data.size) + data.map(&:to_i)
17
- }
19
+ end)
18
20
  end
19
21
 
20
22
  def to_3b(int)
@@ -30,6 +32,7 @@ module NabaztagHackKit
30
32
  end
31
33
 
32
34
  private
35
+
33
36
  def full_message(*data)
34
37
  [0x7F] + data.flatten + [0xFF, 0x0A]
35
38
  end
@@ -38,5 +41,4 @@ module NabaztagHackKit
38
41
  message.pack('c*')
39
42
  end
40
43
  end
41
-
42
44
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'nabaztag_hack_kit/message'
2
4
 
3
5
  module NabaztagHackKit
@@ -43,7 +45,6 @@ module NabaztagHackKit
43
45
  # Message.to_3b(value)
44
46
  # end.flatten
45
47
  # end
46
-
47
48
  end
48
49
  end
49
50
  end
@@ -1,26 +1,28 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module NabaztagHackKit
2
4
  module Message
3
5
  module Helper
4
6
  extend self
5
7
  include Api
6
8
 
7
- #blink
9
+ # blink
8
10
  def bl(loops = 1, color_on = 0xFF, color_off = 0x00)
9
11
  repeat(loops, [color_on, color_off])
10
12
  end
11
13
 
12
- #repeat
14
+ # repeat
13
15
  def rp(loops, pattern = 0)
14
16
  Array.new(loops, pattern).flatten
15
17
  end
16
- alias_method :sl, :rp #sleep
18
+ alias sl rp # sleep
17
19
 
18
- #knight rider
20
+ # knight rider
19
21
  def kr(color = 0xFF, led1 = LED_L1, led2 = LED_L2, led3 = LED_L3)
20
22
  {
21
- led1 => [color,0,0,0],
22
- led2 => [0,color],
23
- led3 => [0,0,color,0]
23
+ led1 => [color, 0, 0, 0],
24
+ led2 => [0, color],
25
+ led3 => [0, 0, color, 0]
24
26
  }
25
27
  end
26
28
 
@@ -28,29 +30,29 @@ module NabaztagHackKit
28
30
  data = Array.new(16) do |i|
29
31
  Message.to_3b(i * color)
30
32
  end + Array.new(8) do |i|
31
- Message.to_3b((15-i) * 2 * color)
33
+ Message.to_3b((15 - i) * 2 * color)
32
34
  end
33
35
 
34
36
  {
35
- (led1+10) => data + [0,0,0] + [0,0,0],
36
- (led2+10) => [0,0,0] + data + [0,0,0],
37
- (led3+10) => [0,0,0] + [0,0,0] + data
37
+ (led1 + 10) => data + [0, 0, 0] + [0, 0, 0],
38
+ (led2 + 10) => [0, 0, 0] + data + [0, 0, 0],
39
+ (led3 + 10) => [0, 0, 0] + [0, 0, 0] + data
38
40
  }
39
41
  end
40
42
 
41
43
  def wink(s = 1, e = 4, times = 3)
42
44
  {
43
- EAR_L => ([s,e] * times) + [s],
44
- EAR_R => [s] + ([s,e] * times)
45
+ EAR_L => ([s, e] * times) + [s],
46
+ EAR_R => [s] + ([s, e] * times)
45
47
  }
46
48
  end
47
49
 
48
50
  def circle(times = 15)
49
51
  {
50
- LED_0 => [r,0,0,0] * times,
51
- LED_1 => [0,r,0,0] * times,
52
- LED_4 => [0,0,r,0] * times,
53
- LED_3 => [0,0,0,r] * times,
52
+ LED_0 => [r, 0, 0, 0] * times,
53
+ LED_1 => [0, r, 0, 0] * times,
54
+ LED_4 => [0, 0, r, 0] * times,
55
+ LED_3 => [0, 0, 0, r] * times
54
56
  }
55
57
  end
56
58
 
@@ -69,11 +71,12 @@ module NabaztagHackKit
69
71
  EAR_L => 0,
70
72
  EAR_R => 0,
71
73
  EAR_LL => 0,
72
- EAR_LR => 0,
74
+ EAR_LR => 0
73
75
  }
74
76
  end
75
77
 
76
78
  private
79
+
77
80
  def r
78
81
  rand(255)
79
82
  end
@@ -1,13 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module NabaztagHackKit
2
4
  module Mods
3
5
  module Button
4
-
5
6
  def self.registered(app)
6
- app.on "button-pressed" do |bunny, data, request, run|
7
- callback("button-pressed", bunny, params[:duration], request, run+1)
7
+ app.on 'button-pressed' do |bunny, _data, request, run|
8
+ callback('button-pressed', bunny, params[:duration], request, run + 1)
8
9
  end
9
10
  end
10
-
11
11
  end
12
12
  end
13
13
  end
@@ -1,15 +1,18 @@
1
1
 
2
+ # frozen_string_literal: true
3
+
2
4
  require 'nabaztag_hack_kit/message/api'
3
5
 
4
6
  module NabaztagHackKit
5
7
  module Mods
6
8
  module Callback
7
-
8
9
  module Helpers
9
10
  def callback(action, bunny, data, request, run = 0)
10
- if (cb = self.class.callbacks[action.to_s]) && (callback = cb[run])
11
- instance_exec(bunny, data, request, run, &callback) || callback(action, bunny, data, request, run+1)
12
- end
11
+ cb = self.class.callbacks[action.to_s]
12
+ return unless cb
13
+ callback = cb[run]
14
+ return unless callback
15
+ instance_exec(bunny, data, request, run, &callback) || callback(action, bunny, data, request, run + 1)
13
16
  end
14
17
  end
15
18
 
@@ -22,15 +25,15 @@ module NabaztagHackKit
22
25
  app.helpers Callback::Helpers
23
26
 
24
27
  # generic api callback
25
- %w(get post).each do |method|
26
- app.send(method, "/api/:bunnyid/:action.jsp") do
28
+ %w[get post].each do |method|
29
+ app.send(method, '/api/:bunnyid/:action.jsp') do
27
30
  bunny = Bunny.find(params[:bunnyid])
28
31
  callback('request', bunny, params, request)
29
32
  callback(params[:action], bunny, params, request).tap do |response|
30
33
  unless response
31
34
  logger.warn "no successful callback found for #{params[:action]}"
32
35
  status 404
33
- return
36
+ break
34
37
  end
35
38
  end
36
39
  end
@@ -40,7 +43,6 @@ module NabaztagHackKit
40
43
  def callbacks
41
44
  @@callbacks ||= {}
42
45
  end
43
-
44
46
  end
45
47
  end
46
48
  end
@@ -1,15 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module NabaztagHackKit
2
4
  module Mods
3
5
  module Logger
4
-
5
6
  module Helper
6
7
  def parse_log(logs)
7
- logs.to_s.split("|").map do |line|
8
- type, time, *values = line.split(",")
8
+ logs.to_s.split('|').map do |line|
9
+ type, time, *values = line.split(',')
9
10
  time = time.to_i
10
11
  values = values.map(&:to_i)
11
12
 
12
- if type == "moved"
13
+ if type == 'moved'
13
14
  values << (time - values[1]) << (values[1] - values[2]) << (time - values[2]) << (time - values[3])
14
15
  end
15
16
  "#{type}-#{time}: #{values.join("\t")}"
@@ -18,16 +19,15 @@ module NabaztagHackKit
18
19
  end
19
20
 
20
21
  def self.registered(app)
21
- app.on "log" do |data, request, run|
22
+ app.on 'log' do |data, request, run|
22
23
  parse_log(data).tap do |logs|
23
- logger.info "#########################"
24
+ logger.info '#########################'
24
25
  logger.info logs.join("\n")
25
- logger.info "#########################"
26
+ logger.info '#########################'
26
27
  end
27
- callback('log', data, request, run+1)
28
+ callback('log', data, request, run + 1)
28
29
  end
29
30
  end
30
31
  end
31
-
32
32
  end
33
33
  end
@@ -1,15 +1,16 @@
1
- require "json"
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
2
4
  require 'nabaztag_hack_kit/bunny'
3
5
  require 'nabaztag_hack_kit/message/helper'
4
6
 
5
7
  module NabaztagHackKit
6
8
  module Mods
7
9
  module Playground
8
-
9
10
  module Helpers
10
11
  def commands(commands, command_values)
11
12
  Array(commands).zip(command_values).map do |command, values|
12
- [command] + int_array(values.split(","))
13
+ [command] + int_array(values.split(','))
13
14
  end
14
15
  end
15
16
 
@@ -27,61 +28,57 @@ module NabaztagHackKit
27
28
  def self.registered(app)
28
29
  app.helpers Playground::Helpers
29
30
 
30
- app.get "/" do
31
- redirect "/playground"
31
+ app.get '/' do
32
+ redirect '/playground'
32
33
  end
33
34
 
34
- app.get "/playground" do
35
- File.read(public_file("index.html"))
35
+ app.get '/playground' do
36
+ File.read(public_file('index.html'))
36
37
  end
37
38
 
38
- #API
39
- app.get "/playground/commands" do # return list of commands
40
- Message::Api.constants.sort.inject({}) do |hash, constant|
39
+ # API
40
+ app.get '/playground/commands' do # return list of commands
41
+ Message::Api.constants.sort.each_with_object({}) do |constant, hash|
41
42
  if constant.to_s.length > 2
42
43
  hash[constant] = Message::Api.const_get(constant)
43
44
  end
44
- hash
45
45
  end.to_json
46
46
  end
47
47
 
48
- app.get "/playground/bunnies" do # return list of bunnies
48
+ app.get '/playground/bunnies' do # return list of bunnies
49
49
  Bunny.all.to_json
50
50
  end
51
51
 
52
- app.post "/playground/bunnies/:bunnyid" do # {"command"=>["40"], "command_values"=>[["1,2,3,4"],[]]}
53
- if bunny = Bunny.find(params[:bunnyid])
52
+ app.post '/playground/bunnies/:bunnyid' do # {"command"=>["40"], "command_values"=>[["1,2,3,4"],[]]}
53
+ if (bunny = Bunny.find(params[:bunnyid]))
54
54
  bunny.queue_commands commands(params[:command], params[:command_values])
55
55
  bunny.to_json
56
56
  end
57
57
  end
58
58
 
59
- app.post "/playground/bunnies" do # {"bunny"=>["0019db9c2daf"], "command"=>["40"], "command_values"=>[["1,2,3,4"],[]]}
59
+ app.post '/playground/bunnies' do # {"bunny"=>["0019db9c2daf"], "command"=>["40"], "command_values"=>[["1,2,3,4"],[]]}
60
60
  Array(params[:bunny]).uniq.each do |bunnyid|
61
- if bunny = Bunny.find(bunnyid)
61
+ if (bunny = Bunny.find(bunnyid))
62
62
  bunny.queue_commands commands(params[:command], params[:command_values])
63
63
  end
64
64
  end
65
65
 
66
- redirect "/playground"
66
+ redirect '/playground'
67
67
  end
68
68
 
69
69
  ##################################################################
70
70
 
71
- app.on "ping" do |bunny|
72
- if bunny
73
- bunny.next_message!
74
- end
71
+ app.on 'ping' do |bunny|
72
+ bunny&.next_message!
75
73
  end
76
74
 
77
- app.on 'request' do |bunny, data|
78
- if bunny = Bunny.find_or_initialize_by_id(data[:bunnyid])
75
+ app.on 'request' do |_bunny, data|
76
+ if (bunny = Bunny.find_or_initialize_by_id(data[:bunnyid]))
79
77
  bunny.seen!
80
78
  end
81
79
  nil # pass it on
82
80
  end
83
81
  end
84
-
85
82
  end
86
83
  end
87
84
  end
@@ -1,19 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module NabaztagHackKit
2
4
  module Mods
3
5
  module Streaming
4
-
5
- REC_FILE = "rec.wav"
6
+ REC_FILE = 'rec.wav'
6
7
 
7
8
  def self.registered(app)
8
- app.on "recording-finished" do |bunny, data, request, run|
9
- file_name = REC_FILE # TODO add timestamp??
10
- File.open(file_name, "w+") do |f|
9
+ app.on 'recording-finished' do |bunny, _data, request, run|
10
+ file_name = REC_FILE # TODO: add timestamp??
11
+ File.open(file_name, 'w+') do |f|
11
12
  f.write request.body.read
12
13
  end
13
- callback('recording-finished', bunny, file_name, request, run+1)
14
+ callback('recording-finished', bunny, file_name, request, run + 1)
14
15
  end
15
16
  end
16
-
17
17
  end
18
18
  end
19
19
  end
@@ -1,17 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module NabaztagHackKit
2
4
  module Mods
3
5
  module Streaming
4
-
5
6
  def self.registered(app)
6
- app.get "/streams/:file.mp3" do
7
- if file = public_file("#{params[:file]}.mp3")
7
+ app.get '/streams/:file.mp3' do
8
+ if (file = public_file("#{params[:file]}.mp3"))
8
9
  File.read file
9
10
  else
10
11
  status 404
11
12
  end
12
13
  end
13
14
  end
14
-
15
15
  end
16
16
  end
17
17
  end
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sinatra/base'
2
4
 
3
5
  module NabaztagHackKit
4
6
  class Server < Sinatra::Base
5
-
6
7
  configure :production, :development do
7
8
  enable :logging
8
9
  end
@@ -13,23 +14,23 @@ module NabaztagHackKit
13
14
  super
14
15
  @base_file = opts.fetch(:base_file, __FILE__)
15
16
  @bytecode_file = opts.fetch(:bytecode_file, public_file('bytecode.bin')).to_s
16
- abort("Couldn't find Bytecode file. Pls compile first") unless File.exists?(@bytecode_file)
17
+ abort("Couldn't find Bytecode file. Pls compile first") unless File.exist?(@bytecode_file)
17
18
  puts "Serving Bytecode from #{@bytecode_file}"
18
19
  end
19
20
 
20
- get "/bc.jsp" do
21
+ get '/bc.jsp' do
21
22
  send_file @bytecode_file
22
23
  end
23
24
 
24
- get "/" do
25
- "Welcome to Nabaztag Hack Kit - it works!"
25
+ get '/' do
26
+ 'Welcome to Nabaztag Hack Kit - it works!'
26
27
  end
27
28
 
28
- get "/favicon.ico" do
29
+ get '/favicon.ico' do
29
30
  end
30
31
 
31
32
  # generic catchall
32
- get "/*" do
33
+ get '/*' do
33
34
  logger.warn "no route found for #{params[:splat]}"
34
35
  status 404
35
36
  end
@@ -37,13 +38,14 @@ module NabaztagHackKit
37
38
  ####################################################################
38
39
 
39
40
  protected
41
+
40
42
  def public_file(name)
41
43
  public_file_path(name) || public_file_path(name, __FILE__)
42
44
  end
43
45
 
44
46
  def public_file_path(name, base = @base_file)
45
47
  File.expand_path(File.join('..', 'public', name), base).tap do |file|
46
- return file if File.exists?(file)
48
+ return file if File.exist?(file)
47
49
  end
48
50
  nil
49
51
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module NabaztagHackKit
2
- VERSION = "0.1.0.beta8"
4
+ VERSION = '0.1.0'
3
5
  end
@@ -1,29 +1,33 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "nabaztag_hack_kit/version"
1
+
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.push File.expand_path('../lib', __FILE__)
5
+ require 'nabaztag_hack_kit/version'
4
6
 
5
7
  Gem::Specification.new do |s|
6
- s.name = "nabaztag_hack_kit"
8
+ s.name = 'nabaztag_hack_kit'
7
9
  s.version = NabaztagHackKit::VERSION
8
- s.authors = ["RngTng - Tobias Bielohlawek"]
9
- s.email = ["tobi@rngtng.com"]
10
- s.homepage = "https://github.com/rngtng/NabaztagHackKit"
11
- s.summary = %q{Sinatra server to run custom Nabaztag bytecode}
12
- s.description = %q{Sinatra server api framework to run custom bytecode on Nabaztag v1/v2. Sources + Compiler included (linux only)}
10
+ s.authors = ['RngTng - Tobias Bielohlawek']
11
+ s.email = ['tobi@rngtng.com']
12
+ s.homepage = 'https://github.com/rngtng/NabaztagHackKit'
13
+ s.summary = 'Sinatra server to run custom Nabaztag bytecode'
14
+ s.description = 'Sinatra server api framework to run custom bytecode on Nabaztag' \
15
+ ' v1/v2. Sources + Compiler included (linux only)'
13
16
 
14
17
  s.files = `git ls-files --recurse-submodules`.split("\n")
15
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
19
  s.extensions = ['ext/extconf.rb']
17
20
 
18
21
  s.bindir = 'ext/bin'
19
- s.executables = ['mtl_comp', 'mtl_simu', 'mtl_merge']
22
+ s.executables = %w[mtl_comp mtl_simu mtl_merge]
20
23
 
21
- s.require_paths = ["lib"]
24
+ s.require_paths = ['lib']
22
25
 
23
- s.add_dependency 'sinatra', '>= 2.0'
24
26
  s.add_dependency 'rack', '>= 2.0'
27
+ s.add_dependency 'sinatra', '>= 2.0'
25
28
 
29
+ s.add_development_dependency 'rack-test', '>= 0.6'
26
30
  s.add_development_dependency 'rake', '>= 11.2'
27
31
  s.add_development_dependency 'rspec', '>= 3.5'
28
- s.add_development_dependency 'rack-test', '>= 0.6'
32
+ s.add_development_dependency 'rubocop', '>= 0.49'
29
33
  end
@@ -1,17 +1,19 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- require "nabaztag_hack_kit/server"
4
- require "rack/test"
3
+ require 'spec_helper'
4
+
5
+ require 'nabaztag_hack_kit/server'
6
+ require 'rack/test'
5
7
 
6
8
  shared_examples_for :successful_route do
7
- it "returns 200" do
9
+ it 'returns 200' do
8
10
  get route
9
11
  expect(last_response).to be_ok
10
12
  end
11
13
  end
12
14
 
13
15
  shared_examples_for :notfound_route do
14
- it "returns 404" do
16
+ it 'returns 404' do
15
17
  get route
16
18
  expect(last_response.status).to eq 404
17
19
  end
@@ -20,10 +22,10 @@ end
20
22
  describe NabaztagHackKit::Server do
21
23
  include Rack::Test::Methods
22
24
 
23
- let(:app) { NabaztagHackKit::Server.new(:bytecode_file => __FILE__) }
25
+ let(:app) { NabaztagHackKit::Server.new(bytecode_file: __FILE__) }
24
26
 
25
- describe "/bc.jsp" do
26
- let(:route) { "/bc.jsp" }
27
+ describe '/bc.jsp' do
28
+ let(:route) { '/bc.jsp' }
27
29
 
28
30
  it_behaves_like :successful_route
29
31
  end
@@ -46,14 +48,14 @@ describe NabaztagHackKit::Server do
46
48
  # # it_behaves_like :successful_route
47
49
  # end
48
50
 
49
- describe "catch all route" do
50
- let(:route) { "/api/bunnyid/custom.jsp" }
51
+ describe 'catch all route' do
52
+ let(:route) { '/api/bunnyid/custom.jsp' }
51
53
 
52
54
  it_behaves_like :notfound_route
53
55
 
54
- it "execute callback" do
56
+ it 'execute callback' do
55
57
  get route
56
- expect(last_response.body).to eq ""
58
+ expect(last_response.body).to eq ''
57
59
  end
58
60
  end
59
61
  end
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/setup'
2
4
  require 'rspec'
3
5
 
6
+ $LOAD_PATH << File.expand_path('../../lib', __FILE__)
4
7
 
5
- $: << File.expand_path("../../lib", __FILE__)
6
-
7
- require "nabaztag_hack_kit"
8
+ require 'nabaztag_hack_kit'
@@ -1,10 +1,12 @@
1
- require "spec_helper"
2
- require "nabaztag_hack_kit/message"
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'nabaztag_hack_kit/message'
3
5
 
4
6
  describe NabaztagHackKit::Message do
5
7
  CMD = 30
6
8
  CMD1 = 31
7
- let(:data) { [1,2,3,4,5] }
9
+ let(:data) { [1, 2, 3, 4, 5] }
8
10
  let(:size) { NabaztagHackKit::Message.to_3b(data.size) }
9
11
 
10
12
  before do
@@ -12,49 +14,49 @@ describe NabaztagHackKit::Message do
12
14
  allow(NabaztagHackKit::Message).to receive(:pack) { |data| data }
13
15
  end
14
16
 
15
- describe ".build" do
16
- it "accepts single input" do
17
- expect(NabaztagHackKit::Message.build(*[["40"], ["40", "2", "3", "4"]])).to eq [[40, 0, 0, 0], [40, 0, 0, 1, 50]]
17
+ describe '.build' do
18
+ it 'accepts single input' do
19
+ expect(NabaztagHackKit::Message.build(['40'], %w[40 2 3 4])).to eq [[40, 0, 0, 0], [40, 0, 0, 1, 50]]
18
20
  end
19
21
 
20
- it "accepts single input" do
22
+ it 'accepts single input' do
21
23
  expect(NabaztagHackKit::Message.build(CMD)).to eq [[CMD, 0, 0, 0]]
22
24
  end
23
25
 
24
- it "accepts flat input" do
26
+ it 'accepts flat input' do
25
27
  expect(NabaztagHackKit::Message.build(CMD, *data)).to eq [[CMD, *size, *data]]
26
28
  end
27
29
 
28
- it "accepts array input" do
30
+ it 'accepts array input' do
29
31
  expect(NabaztagHackKit::Message.build([CMD, *data])).to eq [[CMD, *size, *data]]
30
32
  end
31
33
 
32
- it "accepts multiple array input" do
34
+ it 'accepts multiple array input' do
33
35
  expect(NabaztagHackKit::Message.build([CMD, *data], [CMD1, *data])).to eq [[CMD, *size, *data], [CMD1, *size, *data]]
34
36
  end
35
37
 
36
- it "accepts hash input" do
38
+ it 'accepts hash input' do
37
39
  expect(NabaztagHackKit::Message.build(CMD => data, CMD1 => data)).to eq [[CMD, *size, *data], [CMD1, *size, *data]]
38
40
  end
39
41
 
40
- context "as string" do
41
- it "accepts hash input" do
42
+ context 'as string' do
43
+ it 'accepts hash input' do
42
44
  expect(NabaztagHackKit::Message.build(CMD.to_s => data.map(&:to_s), CMD1.to_s => data)).to eq [[CMD, *size, *data], [CMD1, *size, *data]]
43
45
  end
44
46
  end
45
47
  end
46
48
 
47
- describe ".to_3b" do
48
- it "accepts zero" do
49
+ describe '.to_3b' do
50
+ it 'accepts zero' do
49
51
  expect(NabaztagHackKit::Message.to_3b(0)).to eq [0, 0, 0]
50
52
  end
51
53
 
52
- it "accepts 2 byte input" do
54
+ it 'accepts 2 byte input' do
53
55
  expect(NabaztagHackKit::Message.to_3b(511)).to eq [0, 1, 255]
54
56
  end
55
57
 
56
- it "accepts 3 byte input" do
57
- expect(NabaztagHackKit::Message.to_3b(6334239)).to eq [96, 167, 31]
58
+ it 'accepts 3 byte input' do
59
+ expect(NabaztagHackKit::Message.to_3b(6_334_239)).to eq [96, 167, 31]
58
60
  end
59
61
  end
60
62
  end
@@ -1,32 +1,32 @@
1
- require "spec_helper"
1
+ # frozen_string_literal: true
2
2
 
3
- require "nabaztag_hack_kit/server"
3
+ require 'spec_helper'
4
+
5
+ require 'nabaztag_hack_kit/server'
4
6
 
5
7
  describe NabaztagHackKit::Server do
6
8
  let(:app) { NabaztagHackKit::Server.new }
7
9
 
8
- describe "#bc.jsp" do
10
+ describe '#bc.jsp' do
9
11
  def do_action(path)
10
- app.call({
11
- 'REQUEST_METHOD' => 'GET',
12
- 'PATH_INFO' => path,
13
- 'rack.input' => StringIO.new
14
- })
12
+ app.call('REQUEST_METHOD' => 'GET',
13
+ 'PATH_INFO' => path,
14
+ 'rack.input' => StringIO.new)
15
15
  end
16
16
 
17
- xit "reads from public/bytecode.bin" do
18
- expect(app).to_receive(:send_file).with("public/bytecode.bin")
17
+ xit 'reads from public/bytecode.bin' do
18
+ expect(app).to_receive(:send_file).with('public/bytecode.bin')
19
19
  begin
20
20
  do_action '/bc.jsp'
21
21
  rescue SystemExit
22
22
  end
23
23
  end
24
24
 
25
- context "with custom bin code route" do
25
+ context 'with custom bin code route' do
26
26
  let(:app) { NabaztagHackKit::Server.new(custom_route) }
27
- let(:custom_route) { "bytecode.bin" }
27
+ let(:custom_route) { 'bytecode.bin' }
28
28
 
29
- xit "reads from" do
29
+ xit 'reads from' do
30
30
  expect(app).to_receive(:send_file).with(custom_route)
31
31
  begin
32
32
  do_action '/bc.jsp'
@@ -36,8 +36,8 @@ describe NabaztagHackKit::Server do
36
36
  end
37
37
  end
38
38
 
39
- describe "#on" do
40
- xit "accepts" do
39
+ describe '#on' do
40
+ xit 'accepts' do
41
41
  end
42
42
  end
43
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nabaztag_hack_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - RngTng - Tobias Bielohlawek
@@ -11,7 +11,7 @@ cert_chain: []
11
11
  date: 2017-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: sinatra
14
+ name: rack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rack
28
+ name: sinatra
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack-test
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0.6'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -67,19 +81,19 @@ dependencies:
67
81
  - !ruby/object:Gem::Version
68
82
  version: '3.5'
69
83
  - !ruby/object:Gem::Dependency
70
- name: rack-test
84
+ name: rubocop
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - ">="
74
88
  - !ruby/object:Gem::Version
75
- version: '0.6'
89
+ version: '0.49'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
- version: '0.6'
96
+ version: '0.49'
83
97
  description: Sinatra server api framework to run custom bytecode on Nabaztag v1/v2.
84
98
  Sources + Compiler included (linux only)
85
99
  email:
@@ -94,6 +108,8 @@ extra_rdoc_files: []
94
108
  files:
95
109
  - ".gitignore"
96
110
  - ".gitmodules"
111
+ - ".rubocop.yml"
112
+ - ".rubocop_todo.yml"
97
113
  - ".travis.yml"
98
114
  - CHANGELOG.md
99
115
  - Gemfile
@@ -255,9 +271,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
255
271
  version: '0'
256
272
  required_rubygems_version: !ruby/object:Gem::Requirement
257
273
  requirements:
258
- - - ">"
274
+ - - ">="
259
275
  - !ruby/object:Gem::Version
260
- version: 1.3.1
276
+ version: '0'
261
277
  requirements: []
262
278
  rubyforge_project:
263
279
  rubygems_version: 2.5.1