Class: CodewarsCli::Kata

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

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(language) ⇒ Kata

Returns a new instance of Kata.



16
17
18
# File 'lib/codewars_cli/kata.rb', line 16

def initialize(language)
  @language = language
end

Instance Attribute Details

#languageObject (readonly)

Returns the value of attribute language.



15
16
17
# File 'lib/codewars_cli/kata.rb', line 15

def language
  @language
end

Class Method Details

.fetch(language) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/codewars_cli/kata.rb', line 4

def self.fetch(language)
  check_for_api_key
  if language
    new(language)
  else
    default_language = Configuration.language
    fail Thor::Error, "ERROR: You must config the language for this command\nSOLUTION: Set up with `config language LANGUAGE`" if default_language.empty?
    new(default_language)
  end
end

Instance Method Details

#create_fileObject



24
25
26
# File 'lib/codewars_cli/kata.rb', line 24

def create_file
  FileCreator.create(get_kata, language)
end

#get_kataObject



20
21
22
# File 'lib/codewars_cli/kata.rb', line 20

def get_kata
  client.next_kata(language: language)
end