Sha256: db75af3d594046fe4c9fcb9044343a82dec1eba3432bde50cce2d3ae4c751eb2

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

# Author::    Eric Crane  (mailto:eric.crane@mac.com)
# Copyright:: Copyright (c) 2019 Eric Crane.  All rights reserved.
#
# Show a single object's value.
#
require 'colorized_string'

module GlooLang
  module Verbs
    class Show < GlooLang::Core::Verb

      KEYWORD = 'show'.freeze
      KEYWORD_SHORT = '='.freeze

      #
      # Run the verb.
      #
      def run
        if @tokens.token_count > 1
          expr = GlooLang::Expr::Expression.new( @tokens.params )
          result = expr.evaluate
          $log.show get_formatted_string( result )
          $engine.heap.it.set_to result
        else
          $log.show ''
        end
      end

      #
      # Get the Verb's keyword.
      #
      def self.keyword
        return KEYWORD
      end

      #
      # Get the Verb's keyword shortcut.
      #
      def self.keyword_shortcut
        return KEYWORD_SHORT
      end

      # ---------------------------------------------------------------------
      #    Private functions
      # ---------------------------------------------------------------------

      private

      #
      # Get the formatted string.
      #
      def get_formatted_string( str )
        if @params&.token_count&.positive?
          expr = GlooLang::Expr::Expression.new( @params.tokens )
          val = expr.evaluate
          color = val.to_sym
          return ColorizedString[ str.to_s ].colorize( color )
        end
        return str
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gloo-lang-0.9.5 lib/gloo_lang/verbs/show.rb
gloo-lang-0.9.4 lib/gloo_lang/verbs/show.rb
gloo-lang-0.9.3 lib/gloo_lang/verbs/show.rb