Sha256: 6533446815191cc8d0c5ac728ab777de8d0f4484e6603f5ac75ba9ef958ffa7f

Contents?: true

Size: 1.86 KB

Versions: 2

Compression:

Stored size: 1.86 KB

Contents

# Author::    Eric Crane  (mailto:eric.crane@mac.com)
# Copyright:: Copyright (c) 2019 Eric Crane.  All rights reserved.
#
# An object that contains a collection of other objects.
#

module Gloo
  module Objs
    class Container < Gloo::Core::Obj

      KEYWORD = 'container'.freeze
      KEYWORD_SHORT = 'can'.freeze

      #
      # The name of the object type.
      #
      def self.typename
        return KEYWORD
      end

      #
      # The short name of the object type.
      #
      def self.short_typename
        return KEYWORD_SHORT
      end

      # ---------------------------------------------------------------------
      #    Messages
      # ---------------------------------------------------------------------

      #
      # Get a list of message names that this object receives.
      #
      def self.messages
        return super + %w[count delete_children child_exists show_key_value_table]
      end

      #
      # Count the number of children in the container.
      #
      def msg_count
        i = child_count
        @engine.heap.it.set_to i
        return i
      end

      #
      # Delete all children in the container.
      #
      def msg_delete_children
        self.delete_children
      end

      #
      # Show the given table data.
      #
      def msg_show_key_value_table
        data = self.children.map { |o| [ o.name, o.value ] }

        # TODO: this doesn't work:
        # @engine.platform.show_table nil, data, title
      end

      # 
      # Check to see if there is a child with the given name.
      # 
      def msg_child_exists
        if @params&.token_count&.positive?
          expr = Gloo::Expr::Expression.new( @engine, @params.tokens )
          data = expr.evaluate
        end
        return unless data

        val = self.contains_child?( data )
        @engine.heap.it.set_to val
        return val
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gloo-3.3.0 lib/gloo/objs/basic/container.rb
gloo-3.2.0 lib/gloo/objs/basic/container.rb