Sha256: 7b62a688a544a5db990358b3efb4498a47c2e47458ee25e68bef3de469448bb7

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 KB

Contents

require_relative 'feature_domain'

module Zenlish
  module Feature
    class FeatureStructDef < FeatureDomain
      attr_reader :parent
      attr_reader :struct

      # @param aParent [FeatureStructDef]
      def initialize(aParent = nil)
        @parent = validated_parent(aParent)
        @struct = {}
      end

      # @param aFeatureName [String]
      def [](aFeatureName)
        return struct[aFeatureName] if struct.include? aFeatureName
        if parent
          p_struct = parent.struct
          return p_struct[aFeatureName] if p_struct.include? aFeatureName
        end

        raise StandardError, "Unknown feature name #{aFeatureName}"
      end

      # @param aFeatureDef [Zenlish::Feature::FeatureDef]
      def add_feature_def(aFeatureDef)
        struct[aFeatureDef.name] = aFeatureDef
      end

      private

      def validated_parent(aParent)
        if aParent.kind_of?(FeatureStructDef)
          aParent
        elsif aParent
          aParent.struct
        else
          nil
        end
      end
    end # class
  end # module
end # module

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
zenlish-0.2.05 lib/zenlish/feature/feature_struct_def.rb
zenlish-0.2.04 lib/zenlish/feature/feature_struct_def.rb
zenlish-0.2.03 lib/zenlish/feature/feature_struct_def.rb
zenlish-0.2.02 lib/zenlish/feature/feature_struct_def.rb
zenlish-0.2.01 lib/zenlish/feature/feature_struct_def.rb
zenlish-0.2.00 lib/zenlish/feature/feature_struct_def.rb