Sha256: 50e66489dd1e87ffc5dc0ea99c89ced9932cbaa5700f8855309e84a8934d0c18

Contents?: true

Size: 888 Bytes

Versions: 3

Compression:

Stored size: 888 Bytes

Contents

module CurriculumGenerator
  module Generator
    # Abstract class for a generator.
    # All generators should inherit from this class.
    class BasicGenerator

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

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

      def generate
        fail("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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
curriculum-generator-1.0.7 lib/curriculum-generator/generator/basic_generator.rb
curriculum-generator-1.0.6 lib/curriculum-generator/generator/basic_generator.rb
curriculum-generator-1.0.5 lib/curriculum-generator/generator/basic_generator.rb