Class: Gloo::Expr::LString

Inherits:
Core::Literal show all
Defined in:
lib/gloo/expr/l_string.rb

Instance Attribute Summary

Attributes inherited from Core::Literal

#value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Core::Literal

#initialize

Constructor Details

This class inherits a constructor from Gloo::Core::Literal

Class Method Details

.string?(token) ⇒ Boolean

Is the given token a string?

Returns:

  • (Boolean)


25
26
27
28
29
30
31
# File 'lib/gloo/expr/l_string.rb', line 25

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

.strip_quotes(str) ⇒ Object

Given a string with leading and trailing quotes, strip them out.



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/gloo/expr/l_string.rb', line 37

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

Instance Method Details

#set_value(value) ⇒ Object

Set the value, triming opening and closing quotations if necessary.



15
16
17
18
19
20
# File 'lib/gloo/expr/l_string.rb', line 15

def set_value( value )
  @value = value
  return unless value

  @value = LString.strip_quotes( @value )
end

#to_sObject

Get string representation



52
53
54
# File 'lib/gloo/expr/l_string.rb', line 52

def to_s
  return self.value
end