Class: AtCoderFriends::Emitter
- Inherits:
-
Object
- Object
- AtCoderFriends::Emitter
- 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.
Constant Summary
Constants included from PathUtil
PathUtil::CASES_DIR, PathUtil::SMP_DIR
Instance Method Summary collapse
- #emit(pbm) ⇒ Object
- #emit_sample(pbm, smp) ⇒ Object
- #emit_source(pbm, src) ⇒ Object
-
#initialize(dir) ⇒ Emitter
constructor
A new instance of Emitter.
- #makedirs_unless(dir) ⇒ Object
Methods included from PathUtil
cases_dir, contest_name, smp_dir, split_prg_path
Constructor Details
#initialize(dir) ⇒ Emitter
Returns a new instance of Emitter.
11 12 13 14 |
# File 'lib/at_coder_friends/emitter.rb', line 11 def initialize(dir) @src_dir = dir @smp_dir = smp_dir(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.smps.each { |smp| emit_sample(pbm, smp) } pbm.srcs.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 |
#makedirs_unless(dir) ⇒ Object
39 40 41 |
# File 'lib/at_coder_friends/emitter.rb', line 39 def makedirs_unless(dir) FileUtils.makedirs(dir) unless Dir.exist?(dir) end |