Sha256: a6d7c49a948231e643fd6392f5791d96f581d03dbeb2ebbafd8682d283303dfe

Contents?: true

Size: 865 Bytes

Versions: 3

Compression:

Stored size: 865 Bytes

Contents

# frozen_string_literal: true

require_relative './structs/node'

module Umwelt::Node
  class Base < Struct::Node
    def semantics
      [:Plain]
    end

    def semantic(semantic_name)
      semantic_klass(semantic_name).new(node: self)
    end

    def ancestry
      if context_id
        context.ancestry << self
      else
        [self]
      end
    end

    def context
      tree.node(context_id)
    end

    def label
      self.class.name.split('::').last.to_sym
    end

    private

    # Umwelt::Node::Space.new.semantic_klass(semantic)
    # => Umwelt::Semantic::Plain::Space
    def semantic_klass(semantic_name)
      [semantic_name, label]
        .reduce(Umwelt::Semantic) do |klass, name|
        klass.const_get name
      end
    end
  end
end

require_relative './node/build'
require_relative './node/root'
require_relative './node/space'

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
umwelt-0.2 lib/umwelt/node.rb
umwelt-0.1.1 lib/umwelt/node.rb
umwelt-0.1.0 lib/umwelt/node.rb