Class: AtCoderFriends::Emitter

Inherits:
Object
  • Object
show all
Includes:
PathUtil
Defined in:
lib/at_coder_friends/emitter.rb

Overview

emits source skeletons and sample input/output(s) of a problem to the specified directory.

Instance Method Summary collapse

Methods included from PathUtil

#makedirs_unless

Constructor Details

#initialize(ctx) ⇒ Emitter

Returns a new instance of Emitter.



11
12
13
14
# File 'lib/at_coder_friends/emitter.rb', line 11

def initialize(ctx)
  @src_dir = ctx.path_info.src_dir
  @smp_dir = ctx.path_info.smp_dir
end

Instance Method Details

#emit(pbm) ⇒ Object



16
17
18
19
# File 'lib/at_coder_friends/emitter.rb', line 16

def emit(pbm)
  pbm.samples.each { |smp| emit_sample(pbm, smp) }
  pbm.sources.each { |src| emit_source(pbm, src) }
end

#emit_sample(pbm, smp) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/at_coder_friends/emitter.rb', line 21

def emit_sample(pbm, smp)
  makedirs_unless @smp_dir
  smp_file = format(
    '%<q>s_%<n>03d.%<ext>s', q: pbm.q, n: smp.no, ext: smp.ext
  )
  smp_path = File.join(@smp_dir, smp_file)
  File.write(smp_path, smp.txt)
  puts smp_file
end

#emit_source(pbm, src) ⇒ Object



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

def emit_source(pbm, src)
  makedirs_unless @src_dir
  src_file = format('%<q>s.%<ext>s', q: pbm.q, ext: src.ext)
  src_path = File.join(@src_dir, src_file)
  File.write(src_path, src.txt)
  puts src_file
end