Sha256: 550851da485ef74af46f8485e3db39c36e7f276d636e7b15a302be014941012d

Contents?: true

Size: 718 Bytes

Versions: 5

Compression:

Stored size: 718 Bytes

Contents

# Abstract class for a generator. All generators should inherit from this class
class CGen::Generator::BasicGenerator

  attr_accessor(:param)
  attr_accessor(:data)
  attr_accessor(:lang)

  def initialize(param, data, lang)
    @param = param
    @data = data
    @lang = lang
  end

  def generate
    raise 'Abstract class'
  end

  def get_value(keys_str)
    keys = keys_str.split('.').reverse
    if keys.empty?
      '' # return
    else
      data_tmp = @data.dup
      until keys.empty?
        key = keys.pop
        data_tmp = data_tmp[key]
      end
      data_tmp # return
    end
  end

  def evaluate(input, context)
    eruby = Erubis::Eruby.new(input)
    eruby.evaluate(context) # return
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
curriculum-generator-1.0.4 lib/cgen/generator/basic_generator.rb
curriculum-generator-1.0.3 lib/cgen/generator/basic_generator.rb
curriculum-generator-1.0.2 lib/cgen/generator/basic_generator.rb
curriculum-generator-1.0.1 lib/cgen/generator/basic_generator.rb
curriculum-generator-1.0.0 lib/cgen/generator/basic_generator.rb