Class: Katagen::Generators::Solution

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/katagen/generators/solution.rb

Overview

Generates a solution package

Constant Summary

Constants included from Logging

Logging::COLOR_CODES

Instance Method Summary collapse

Methods included from Utils

#generate_file, #generate_folder

Methods included from Logging

#info, #success, #warning

Constructor Details

#initialize(strategy, options) ⇒ Solution

Initialize generator with chosen method.

Parameters:

  • strategy: (#build_question_info)

    instance of FromId or FromUrl

  • options: (Hash)

    see cli.rb

  • options (Hash)

    a customizable set of options

Options Hash (options):

  • cwd (String)

    current working directory, defaults is “./”

  • lang_ext (String)

    solution file extension, defaults to “rb” (ruby)



20
21
22
23
24
# File 'lib/katagen/generators/solution.rb', line 20

def initialize(strategy, options)
  @strategy = strategy
  @lang_ext = options[:lang] || "rb"
  @cwd = options[:cwd] || "./"
end

Instance Method Details

#create_packageObject

Create the folder containing: solution.rb, solution_spec.rb (defaults to rb)

Parameters:

  • cwd: (String)

    default to ./



31
32
33
34
35
36
37
# File 'lib/katagen/generators/solution.rb', line 31

def create_package
  question_info = @strategy.build_question_info
  root = File.expand_path(File.join(@cwd, question_info.root))
  generate_folder(root)
  create_solution(root, question_info.url)
  create_solution_spec(root)
end