Skip to content

Commit e39b12c

Browse files
rubocopness and file renaming
1 parent 6e17bb8 commit e39b12c

23 files changed

+366
-389
lines changed

.github/shared/setup/action.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
name: "setup ruby"
2+
description: "setup ruby"
3+
4+
runs:
5+
using: "composite"
6+
steps:
7+
- name: Set up Ruby
8+
uses: ruby/setup-ruby@v1
9+
with:
10+
bundler-cache: true
11+
working-directory: ./2024/ruby

.github/workflows/2018-ruby.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ jobs:
2626
with:
2727
ruby-version: ${{ steps.determine-ruby-version.outputs.VERSION }}
2828
bundler-cache: true
29+
working-directory: ./2018/ruby
2930
- name: Run tests
3031
run: bundle exec rspec

.github/workflows/2021-ruby.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@ jobs:
2626
with:
2727
ruby-version: ${{ steps.determine-ruby-version.outputs.VERSION }}
2828
bundler-cache: true
29+
working-directory: ./2021/ruby
2930
- name: Run tests
3031
run: bundle exec rspec

.github/workflows/2024-ruby.yaml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name: 2024-ruby
33
on:
44
pull_request:
55
push:
6-
branches: [master]
76
paths:
87
- 2024/ruby/**
98

@@ -12,14 +11,19 @@ defaults:
1211
working-directory: ./2024/ruby
1312

1413
jobs:
14+
lint:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v3
18+
- name: Setup Ruby
19+
uses: ./.github/shared/setup
20+
- name: Run rubocop
21+
run: bundle exec rubocop
1522
tests:
1623
runs-on: ubuntu-latest
1724
steps:
18-
- uses: actions/checkout@v3
19-
- name: Set up Ruby
20-
uses: ruby/setup-ruby@v1
21-
with:
22-
bundler-cache: true
23-
working-directory: ./2024/ruby
24-
- name: Run tests
25-
run: bundle exec rspec
25+
- uses: actions/checkout@v3
26+
- name: Setup Ruby
27+
uses: ./.github/shared/setup
28+
- name: Run tests
29+
run: bundle exec rspec

2018/ruby/spec/advent_03_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
expect(rectangle.width).to eq(4)
3030
end
3131

32-
it "solves the puzzle", solution: true do
32+
it "solves the puzzle", solution: true, slow: true do
3333
reader = ClaimReader.new(puzzle_input)
3434
claims = reader.process
3535

2018/ruby/spec/advent_05_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
end
2525
end
2626

27-
xit "solves part 1" do
27+
it "solves part 1", slow: true do
2828
reader = AlchemicalReduction.new(puzzle_input)
2929
reader.process
3030

@@ -55,7 +55,7 @@
5555
expect(lowest[1]).to eq(4)
5656
end
5757

58-
xit "solves part 2" do
58+
it "solves part 2", slow: true do
5959
counts = {}
6060

6161
('a'..'z').each do |letter|

2018/ruby/spec/advent_06_spec.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,17 @@
3030
expect(c.largest_area).to eq(17)
3131
end
3232

33-
xit "solves part 1" do
33+
it "solves part 1", slow: true do
3434
coordinates = puzzle_input.collect do |item|
3535
Coordinate.new(item[0], item[1])
3636
end
3737

3838
c = ChronalCoordinates.new(coordinates)
39-
# c.print_grid
4039

4140
expect(c.largest_area).to eq(3401)
4241
end
4342

44-
it "solves part 2" do
43+
it "solves part 2", slow: true do
4544
coordinates = puzzle_input.collect do |item|
4645
Coordinate.new(item[0], item[1])
4746
end

2018/ruby/spec/advent_07_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def create_graph(input, weighted = false, seed_weight = 0)
5858
expect(orderer.compressed_order).to eq("CABDFE")
5959
end
6060

61-
xit "figures out the puzzle order" do
61+
it "figures out the puzzle order", slow: true do
6262
graph = create_graph(puzzle_input)
6363

6464
orderer = Orderer.new(graph)
@@ -76,7 +76,7 @@ def create_graph(input, weighted = false, seed_weight = 0)
7676
expect(seconds).to eq(15)
7777
end
7878

79-
xit "figures out part 2 puzzle order" do
79+
it "figures out part 2 puzzle order", slow: true do
8080
graph = create_graph(puzzle_input, true, 60)
8181

8282
orderer = Orderer.new(graph)

2024/ruby/.rubocop_todo.yml

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,3 @@ Metrics/BlockLength:
2121
# Configuration parameters: CountComments, CountAsOne.
2222
Metrics/ClassLength:
2323
Max: 120
24-
25-
# Offense count: 2
26-
# Configuration parameters: EnforcedStyle, AllowedPatterns.
27-
# SupportedStyles: snake_case, camelCase
28-
Naming/MethodName:
29-
Exclude:
30-
- 'lib/advent_04_ceres_search.rb'
31-
- 'test.rb'
32-
33-
# Offense count: 2
34-
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
35-
# SupportedStyles: snake_case, normalcase, non_integer
36-
# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
37-
Naming/VariableNumber:
38-
Exclude:
39-
- 'lib/advent_04_ceres_search.rb'
40-
41-
# Offense count: 4
42-
# Configuration parameters: AllowedConstants.
43-
Style/Documentation:
44-
Exclude:
45-
- 'spec/**/*'
46-
- 'test/**/*'
47-
- 'lib/advent_01_hystorian_hysteria.rb'
48-
- 'lib/advent_02_red_nosed_reports.rb'
49-
- 'lib/advent_03_mull_it_over.rb'
50-
- 'lib/advent_04_ceres_search.rb'

2024/ruby/Gemfile

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
# frozen_string_literal: true
22

3-
source 'https://rubygems.org'
3+
source "https://rubygems.org"
44

5-
ruby File.open('.ruby-version', 'rb') { |f| f.read.chomp }
5+
ruby File.open(".ruby-version", "rb") { |f| f.read.chomp }
66

7-
gem 'awesome_print'
7+
gem "awesome_print"
88

9-
gem 'guard'
10-
gem 'guard-rspec', require: false
9+
gem "guard"
10+
gem "guard-rspec", require: false
1111

12-
gem 'pry', '~> 0.15.0'
12+
gem "pry", "~> 0.15.0"
1313

14-
gem 'rake', '~> 13.2'
15-
gem 'rspec', '~> 3.13.0'
16-
gem 'rubocop', '~> 1.69.0'
17-
gem 'rubocop-rake', '0.6.0', require: false
18-
gem 'rubocop-rspec', '3.2.0', require: false
14+
gem "rake", "~> 13.2"
15+
gem "rspec", "~> 3.13.0"
16+
gem "rubocop", "~> 1.69.0"
17+
gem "rubocop-rake", "0.6.0", require: false
18+
gem "rubocop-rspec", "3.2.0", require: false

2024/ruby/Guardfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
# * zeus: 'zeus rspec' (requires the server to be started separately)
2727
# * 'just' rspec: 'rspec'
2828

29-
guard :rspec, cmd: 'bundle exec rspec' do
30-
require 'guard/rspec/dsl'
29+
guard :rspec, cmd: "bundle exec rspec" do
30+
require "guard/rspec/dsl"
3131
dsl = Guard::RSpec::Dsl.new(self)
3232

3333
# Feel free to open issues for suggestions and improvements
@@ -67,6 +67,6 @@ guard :rspec, cmd: 'bundle exec rspec' do
6767
# Turnip features and steps
6868
watch(%r{^spec/acceptance/(.+)\.feature$})
6969
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
70-
Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
70+
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
7171
end
7272
end

2024/ruby/Rakefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ task :new do
4242
erb = ERB.new(File.read(h[:template]))
4343
rendered = erb.result_with_hash(require_path: basename, day_number: formatted_day)
4444

45-
puts "creating #{path}"
46-
puts rendered.inspect
47-
puts "----------------"
48-
4945
File.write(path, rendered)
5046
end
5147

2024/ruby/lib/advent_01_hystorian_hysteria.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
require 'pry'
1+
require "pry"
22

33
class DistanceCalculator
44
def initialize(list_one, list_two)
5-
raise 'lists must be the same length' if list_one.length != list_two.length
5+
raise "lists must be the same length" if list_one.length != list_two.length
66

77
@list_one = list_one
88
@list_two = list_two

2024/ruby/lib/advent_02_red_nosed_reports.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def initialize(levels)
66
end
77

88
def initial_direction(levels)
9-
levels.length > 1 && levels[0] < levels[1] ? 'increasing' : 'decreasing'
9+
levels.length > 1 && levels[0] < levels[1] ? "increasing" : "decreasing"
1010
end
1111

1212
def safe_with_dampener?
@@ -44,7 +44,7 @@ def safe?
4444
end
4545

4646
def valid_direction?(direction, level, prev)
47-
(prev < level && direction == 'increasing') || (prev > level && direction == 'decreasing')
47+
(prev < level && direction == "increasing") || (prev > level && direction == "decreasing")
4848
end
4949

5050
def adjacent_safe?(prev, level)

2024/ruby/lib/advent_03_mull_it_over.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def uncorrupted_pieces
2525
end
2626

2727
def process_piece(str)
28-
splits = str.tr('^0123456789,', '').split(',')
28+
splits = str.tr("^0123456789,", "").split(",")
2929

3030
splits[0].to_i * splits[1].to_i
3131
end

2024/ruby/lib/advent_04_ceres_search.rb

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class WordSearch
22
attr_reader :data, :word
33

4-
def initialize(data, word = 'XMAS')
4+
def initialize(data, word = "XMAS")
55
@data = data
66
@word = word
77
end
@@ -19,16 +19,16 @@ def count_at(row, col)
1919
end
2020

2121
def letter_at(row, col)
22-
in_bounds?(row, col) ? data[row][col] : ''
22+
in_bounds?(row, col) ? data[row][col] : ""
2323
end
2424

2525
def horizontal_word(row, col)
2626
first = col
2727
last = col + word.length - 1
2828

29-
return '' unless in_bounds?(first, last)
29+
return "" unless in_bounds?(first, last)
3030

31-
data[row][first..last] * ''
31+
data[row][first..last] * ""
3232
end
3333

3434
def horizontal?(row, col)
@@ -38,7 +38,7 @@ def horizontal?(row, col)
3838
def vertical_word(row, col)
3939
(row..row + word.length - 1).map do |pos|
4040
letter_at(pos, col)
41-
end * ''
41+
end * ""
4242
end
4343

4444
def vertical?(row, col)
@@ -48,41 +48,41 @@ def vertical?(row, col)
4848
def diagonal_top_left_word(row, col)
4949
(0..word.length - 1).map do |pos|
5050
letter_at(row - pos, col - pos)
51-
end * ''
51+
end * ""
5252
end
5353

5454
def diagonal_top_right_word(row, col)
5555
(0..word.length - 1).map do |pos|
5656
letter_at(row - pos, col + pos)
57-
end * ''
57+
end * ""
5858
end
5959

6060
def diagonal_bottom_right_word(row, col)
6161
(0..word.length - 1).map do |pos|
6262
letter_at(row + pos, col + pos)
63-
end * ''
63+
end * ""
6464
end
6565

6666
def diagonal_bottom_left_word(row, col)
6767
(0..word.length - 1).map do |pos|
6868
letter_at(row + pos, col - pos)
69-
end * ''
69+
end * ""
7070
end
7171

7272
def match?(str)
7373
[str, str.reverse].any? { |w| w == word }
7474
end
7575

7676
def cross_word_at?(row, col)
77-
cross_word = 'MAS'
77+
cross_word = "MAS"
7878

79-
diag_1 = letter_at(row - 1, col - 1) + letter_at(row, col) + letter_at(row + 1, col + 1)
80-
diag_2 = letter_at(row + 1, col - 1) + letter_at(row, col) + letter_at(row - 1, col + 1)
79+
diag1 = letter_at(row - 1, col - 1) + letter_at(row, col) + letter_at(row + 1, col + 1)
80+
diag2 = letter_at(row + 1, col - 1) + letter_at(row, col) + letter_at(row - 1, col + 1)
8181

82-
diag_1_match = [cross_word, cross_word.reverse].any? { |str| str == diag_1 }
83-
diag_2_match = [cross_word, cross_word.reverse].any? { |str| str == diag_2 }
82+
diag1_match = [cross_word, cross_word.reverse].any? { |str| str == diag1 }
83+
diag2_match = [cross_word, cross_word.reverse].any? { |str| str == diag2 }
8484

85-
diag_1_match && diag_2_match
85+
diag1_match && diag2_match
8686
end
8787

8888
def cross_word_count
@@ -147,9 +147,3 @@ def render
147147
end
148148
end
149149
end
150-
151-
def badName
152-
return unless something
153-
154-
test
155-
end

0 commit comments

Comments
 (0)