Sha256: 63c8e9a825d108fc7bf314ea54ee0fb748ca3aa13495218b82354e53548ebbcb

Contents?: true

Size: 1.26 KB

Versions: 29

Compression:

Stored size: 1.26 KB

Contents

# Author::    Eric Crane  (mailto:eric.crane@mac.com)
# Copyright:: Copyright (c) 2019 Eric Crane.  All rights reserved.
#
# An Expression that can be evaluated.
#

module GlooLang
  module Expr
    class LString < GlooLang::Core::Literal

      #
      # Set the value, triming opening and closing
      # quotations if necessary.
      #
      def set_value( value )
        @value = value
        return unless value

        @value = LString.strip_quotes( @value )
      end

      #
      # Is the given token a string?
      #
      def self.string?( token )
        return false unless token.is_a? String
        return true if token.start_with?( '"' )
        return true if token.start_with?( "'" )

        return false
      end

      #
      # Given a string with leading and trailing quotes,
      # strip them out.
      #
      def self.strip_quotes( str )
        if str.start_with?( '"' )
          str = str[ 1..-1 ]
          str = str[ 0..-2 ] if str.end_with?( '"' )
          return str
        elsif str.start_with?( "'" )
          str = str[ 1..-1 ]
          str = str[ 0..-2 ] if str.end_with?( "'" )
          return str
        end
      end

      #
      # Get string representation
      #
      def to_s
        return self.value
      end

    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
gloo-lang-1.4.3 lib/gloo_lang/expr/l_string.rb
gloo-lang-1.4.2 lib/gloo_lang/expr/l_string.rb
gloo-lang-1.4.1 lib/gloo_lang/expr/l_string.rb
gloo-lang-1.4.0 lib/gloo_lang/expr/l_string.rb
gloo-lang-1.3.2 lib/gloo_lang/expr/l_string.rb
gloo-lang-1.3.1 lib/gloo_lang/expr/l_string.rb
gloo-lang-1.3.0 lib/gloo_lang/expr/l_string.rb
gloo-lang-1.2.8 lib/gloo_lang/expr/l_string.rb
gloo-lang-1.2.7 lib/gloo_lang/expr/l_string.rb
gloo-lang-1.2.6 lib/gloo_lang/expr/l_string.rb
gloo-lang-1.2.5 lib/gloo_lang/expr/l_string.rb
gloo-lang-1.2.4 lib/gloo_lang/expr/l_string.rb
gloo-lang-1.2.3 lib/gloo_lang/expr/l_string.rb
gloo-lang-1.2.2 lib/gloo_lang/expr/l_string.rb
gloo-lang-1.2.1 lib/gloo_lang/expr/l_string.rb
gloo-lang-1.2.0 lib/gloo_lang/expr/l_string.rb
gloo-lang-1.1.0 lib/gloo_lang/expr/l_string.rb
gloo-lang-1.0.2 lib/gloo_lang/expr/l_string.rb
gloo-lang-1.0.1 lib/gloo_lang/expr/l_string.rb
gloo-lang-1.0.0 lib/gloo_lang/expr/l_string.rb