Class: CodewarsCli::FileCreator

Inherits:
Object
  • Object
show all
Includes:
GenericHelpers
Defined in:
lib/codewars_cli/file_creator.rb

Constant Summary collapse

DESCRIPTION_FILE_NAME =
'description.md'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from GenericHelpers

#check_for_api_key, #client, #error, #extend_object, included, #info, #presenter

Constructor Details

#initialize(data, language, folder_path) ⇒ FileCreator

Returns a new instance of FileCreator.



15
16
17
18
19
# File 'lib/codewars_cli/file_creator.rb', line 15

def initialize(data, language, folder_path)
  @data = extend_object(data)
  @language = language
  @folder_path = folder_path
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



14
15
16
# File 'lib/codewars_cli/file_creator.rb', line 14

def data
  @data
end

#folder_pathObject (readonly)

Returns the value of attribute folder_path.



14
15
16
# File 'lib/codewars_cli/file_creator.rb', line 14

def folder_path
  @folder_path
end

#languageObject (readonly)

Returns the value of attribute language.



14
15
16
# File 'lib/codewars_cli/file_creator.rb', line 14

def language
  @language
end

Class Method Details

.create(kata_info, language) ⇒ Object



8
9
10
11
12
# File 'lib/codewars_cli/file_creator.rb', line 8

def self.create(kata_info, language)
  folder_path = Configuration.folder
  fail Thor::Error, "ERROR: You must config the folder\nSOLUTION: Set up with `config folder FOLDER_LOCATION`" if folder_path.empty?
  new(kata_info, language, folder_path).create_file
end

Instance Method Details

#create_fileObject



21
22
23
24
# File 'lib/codewars_cli/file_creator.rb', line 21

def create_file
  _create_missing_dirs unless File.exists?(_destination_path)
  _fill_template_with_kata_info
end