Skip to content

Commit 8391a3c

Browse files
committed
rubocop corrections
1 parent 299c5d4 commit 8391a3c

22 files changed

+141
-98
lines changed

lib/jruby_art/app.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'java'
24
require_relative '../jruby_art'
35
Dir["#{K9_ROOT}/lib/*.jar"].each do |jar|
@@ -10,7 +12,6 @@
1012

1113
# A wrapper module for the processing App
1214
module Processing
13-
1415
# Include some core processing classes that we'd like to use:
1516
include_package 'processing.core'
1617
# Load vecmath, fastmath and mathtool modules
@@ -113,7 +114,7 @@ def initialize(options = {})
113114
puts(exception.backtrace.map { |trace| "\t#{trace}" })
114115
close
115116
end
116-
@surface = self.get_surface
117+
@surface = get_surface
117118
# NB: this is the processing runSketch() method as used by processing.py
118119
run_sketch
119120
end
@@ -214,7 +215,7 @@ def respond_to_missing?(name, include_private = false)
214215

215216
def method_missing(name, *args)
216217
app = Processing.app
217-
return app.send(name, *args) if app && app.respond_to?(name)
218+
return app.send(name, *args) if app&.respond_to?(name)
218219

219220
super
220221
end

lib/jruby_art/config.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require 'yaml'
24
require_relative 'default_config'
35
require_relative 'version'

lib/jruby_art/creators/sketch_writer.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: false
2+
23
# The SketchParameters class knows how to format, size, title & class name
34
class SketchParameters
45
attr_reader :name, :args
@@ -19,6 +20,7 @@ def sketch_title
1920
def sketch_size
2021
mode = args.length == 3 ? format(', %s', args[2].upcase) : ''
2122
return 'size 200, 200' if args.empty?
23+
2224
format('size %d, %d%s', args[0].to_i, args[1].to_i, mode)
2325
end
2426
end
@@ -71,6 +73,7 @@ def method_lines(name, content, indent)
7173
two = content.empty? ? BLANK : format(' %s%s', indent, content)
7274
three = format('%send', indent)
7375
return [one, two, three] if /draw/ =~ name
76+
7477
[one, two, three, BLANK]
7578
end
7679
end

lib/jruby_art/default_config.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
# default configuration
24
class Default
35
def self.config

lib/jruby_art/helper_methods.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: false
2+
23
# processing module wrapper
34
require_relative '../jruby_art'
45

@@ -53,6 +54,7 @@ def hsb_color(hue, sat, brightness)
5354

5455
def color(*args)
5556
return super(*args) unless args.length == 1
57+
5658
super(hex_color(args[0]))
5759
end
5860

@@ -61,7 +63,7 @@ def web_to_color_array(web)
6163
end
6264

6365
def int_to_ruby_colors(p5color)
64-
warn "[DEPRECATION] `int_to_ruby_colors` is deprecated. Please use `p52ruby` instead."
66+
warn '[DEPRECATION] `int_to_ruby_colors` is deprecated. Please use `p52ruby` instead.'
6567
p52ruby(p5color)
6668
end
6769

@@ -100,9 +102,9 @@ def max(*args)
100102
def dist(*args)
101103
case args.length
102104
when 4
103-
return dist2d(*args)
105+
dist2d(*args)
104106
when 6
105-
return dist3d(*args)
107+
dist3d(*args)
106108
else
107109
raise ArgumentError, 'takes 4 or 6 parameters'
108110
end
@@ -123,7 +125,7 @@ def find_method(method_name)
123125
# Proxy over a list of Java declared fields that have the same name as
124126
# some methods. Add to this list as needed.
125127
def proxy_java_fields
126-
fields = %w(key frameRate mousePressed keyPressed)
128+
fields = %w[key frameRate mousePressed keyPressed]
127129
methods = fields.map { |field| java_class.declared_field(field) }
128130
@declared_fields = Hash[fields.zip(methods)]
129131
end
@@ -169,6 +171,7 @@ def save_strings(filename, strings)
169171
# frame_rate needs to support reading and writing
170172
def frame_rate(fps = nil)
171173
return @declared_fields['frameRate'].value(java_self) unless fps
174+
172175
super(fps)
173176
end
174177

@@ -184,16 +187,17 @@ def key_pressed?
184187

185188
private
186189

187-
FIXNUM_COL = -> (x) { x.is_a?(Integer) }
188-
STRING_COL = -> (x) { x.is_a?(String) }
189-
FLOAT_COL = -> (x) { x.is_a?(Float) }
190+
FIXNUM_COL = ->(x) { x.is_a?(Integer) }
191+
STRING_COL = ->(x) { x.is_a?(String) }
192+
FLOAT_COL = ->(x) { x.is_a?(Float) }
190193
# parse single argument color int/double/String
191194
def hex_color(a)
192195
case a
193196
when FIXNUM_COL
194197
Java::Monkstone::ColorUtil.colorLong(a)
195198
when STRING_COL
196199
return Java::Monkstone::ColorUtil.colorString(a) if a =~ /#\h+/
200+
197201
raise StandardError, 'Dodgy Hexstring'
198202
when FLOAT_COL
199203
Java::Monkstone::ColorUtil.colorDouble(a)
@@ -206,6 +210,7 @@ def dist2d(*args)
206210
dx = args[0] - args[2]
207211
dy = args[1] - args[3]
208212
return 0 if dx.abs < EPSILON && dy.abs < EPSILON
213+
209214
Math.hypot(dx, dy)
210215
end
211216

@@ -214,6 +219,7 @@ def dist3d(*args)
214219
dy = args[1] - args[4]
215220
dz = args[2] - args[5]
216221
return 0 if dx.abs < EPSILON && dy.abs < EPSILON && dz.abs < EPSILON
222+
217223
Math.sqrt(dx * dx + dy * dy + dz * dz)
218224
end
219225
end

lib/jruby_art/helpers/aabb.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
2+
23
# Axis aligned bounding box class (AABB would clash with Toxicgem)
34
class AaBb
45
attr_reader :center, :extent
@@ -14,6 +15,7 @@ def self.from_min_max(min:, max:)
1415

1516
def position(vec)
1617
return @center = vec unless block_given?
18+
1719
@center = vec if yield
1820
end
1921

@@ -24,6 +26,7 @@ def scale(d)
2426
def contains?(vec)
2527
rad = extent * 0.5
2628
return false unless (center.x - rad.x..center.x + rad.x).cover? vec.x
29+
2730
(center.y - rad.y..center.y + rad.y).cover? vec.y
2831
end
2932
end

lib/jruby_art/helpers/numeric.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: true
2+
23
# Re-open Numeric so that we can do simple degree and radian conversions
34
# conversion factors are 180 / Math::PI and Math::PI / 180
45

lib/jruby_art/installer.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
require_relative 'config'
24
require_relative 'processing_ide'
35

@@ -8,13 +10,14 @@ def initialize
810
end
911

1012
def install
11-
if processing_ide.installed?
12-
config = Config.new(
13-
'processing_ide' => true,
14-
'library_path' => processing_ide.sketchbook_path)
15-
else
16-
config = Config.new('processing_ide' => false)
17-
end
13+
config = if processing_ide.installed?
14+
Config.new(
15+
'processing_ide' => true,
16+
'library_path' => processing_ide.sketchbook_path
17+
)
18+
else
19+
Config.new('processing_ide' => false)
20+
end
1821
config.write_to_file
1922
end
2023
end

lib/jruby_art/java_opts.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# frozen_string_literal: false
2+
23
# class to parse java_args.txt or java_args in config.yml
34
class JavaOpts
45
attr_reader :opts
@@ -8,6 +9,7 @@ def initialize
89
@opts = []
910
@opts += File.read(arg_file).split(/\s+/) if FileTest.exist?(arg_file)
1011
return unless opts.empty? && Processing::RP_CONFIG.fetch('java_args', false)
12+
1113
@opts += Processing::RP_CONFIG['java_args'].split(/\s+/)
1214
end
1315
end

lib/jruby_art/jruby_complete.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# frozen_string_literal: true
2+
23
class JRubyComplete
34
def self.complete
45
rcomplete = File.join(K9_ROOT, 'lib/ruby/jruby-complete.jar')
56
return [rcomplete] if FileTest.exist?(rcomplete)
7+
68
warn "#{rcomplete} does not exist\nTry running `k9 --install`"
79
exit
810
end

0 commit comments

Comments
 (0)