Class: AdventOfCodeGenerator::Generator

Inherits:
Object
  • Object
show all
Defined in:
lib/advent_of_code_generator/generator.rb

Overview

Creates directory structure and files for daily Advent of Code puzzles:

Generates a file structure like:

username/
│
└── year_2024/
    |
    └── day_01/
        ├── day_01.rb
        ├── day_01_spec.rb
        ├── data.txt
        └── PUZZLE_DESCRIPTION.md

Defined Under Namespace

Classes: FileData

Instance Method Summary collapse

Constructor Details

#initialize(options, scraped_data) ⇒ Generator

Returns a new instance of Generator.



23
24
25
26
27
28
29
# File 'lib/advent_of_code_generator/generator.rb', line 23

def initialize(options, scraped_data)
  @year = options[:year].to_s
  @day = options[:day].to_s.rjust(2, "0") # Ensures day is two digits (e.g., "01" instead of "1")
  @username = options[:username].gsub(/[_\-\.\s]/, "")
  @session = options[:session]
  @scraped_data = scraped_data
end

Instance Method Details

#callObject



31
32
33
34
35
36
37
# File 'lib/advent_of_code_generator/generator.rb', line 31

def call
  FileUtils.mkdir_p(daily_directory)

  [puzzle_description, data_file, main_file, spec_file].each do |file_data|
    generate_file(file_data)
  end
end