Class: GreenDay::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/green_day/task.rb

Defined Under Namespace

Classes: SampleAnswer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, path, contest_name) ⇒ Task

Returns a new instance of Task.



8
9
10
11
12
# File 'lib/green_day/task.rb', line 8

def initialize(name, path, contest_name)
  @name = name
  @path = path
  @contest_name = contest_name
end

Instance Attribute Details

#contest_nameObject (readonly)

Returns the value of attribute contest_name.



6
7
8
# File 'lib/green_day/task.rb', line 6

def contest_name
  @contest_name
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/green_day/task.rb', line 6

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/green_day/task.rb', line 6

def path
  @path
end

Instance Method Details

#create_fileObject



14
15
16
17
18
19
20
# File 'lib/green_day/task.rb', line 14

def create_file
  template = if File.exist?(GreenDay::TEMPLATE_FILE_PATH)
               File.read(GreenDay::TEMPLATE_FILE_PATH)
             end

  File.write(file_name, template)
end

#create_spec_fileObject



26
27
28
29
30
31
32
# File 'lib/green_day/task.rb', line 26

def create_spec_file
  test_content = TestBuilder.build_test(
    file_name,
    sample_answers
  )
  File.write("#{contest_name}/spec/#{name}_spec.rb", test_content)
end

#file_nameObject



22
23
24
# File 'lib/green_day/task.rb', line 22

def file_name
  "#{contest_name}/#{name}.rb"
end