Class: AtCoderFriends::Generator::RubyBuiltin

Inherits:
Base
  • Object
show all
Includes:
ConstFragmentMixin, DeclFragmentMixin
Defined in:
lib/at_coder_friends/generator/ruby_builtin.rb

Overview

generates Ruby source from problem description

Constant Summary collapse

ACF_HOME =
File.realpath(File.join(__dir__, '..', '..', '..'))
TMPL_DIR =
File.join(ACF_HOME, 'templates')
TEMPLATE =
File.join(TMPL_DIR, 'ruby_builtin.rb.erb')
FRAGMENTS =
File.realpath(File.join(TMPL_DIR, 'ruby_builtin_fragments.yml'))
ATTRS =
Attributes.new(:rb, TEMPLATE, FRAGMENTS)

Instance Attribute Summary

Attributes inherited from Base

#cfg, #pbm

Instance Method Summary collapse

Methods included from DeclFragmentMixin

#gen_decl, #gen_decls

Methods included from ConstFragmentMixin

#gen_const

Methods inherited from Base

#config_file_ext, #config_fragments, #config_template, #embed_lines, #fragments, #generate, #initialize, #process

Constructor Details

This class inherits a constructor from AtCoderFriends::Generator::Base

Instance Method Details

#attrsObject



16
17
18
# File 'lib/at_coder_friends/generator/ruby_builtin.rb', line 16

def attrs
  ATTRS
end

#gen_constsObject



20
21
22
23
24
# File 'lib/at_coder_friends/generator/ruby_builtin.rb', line 20

def gen_consts
  pbm.constants
    .select { |c| c.type == :mod }
    .map { |c| gen_const(c) }
end

#render(src) ⇒ Object

deprecated, use ERB syntax



27
28
29
30
# File 'lib/at_coder_friends/generator/ruby_builtin.rb', line 27

def render(src)
  src = embed_lines(src, '### CONSTS ###', gen_consts)
  embed_lines(src, '### DCLS ###', gen_decls)
end