Class: Luoma::StringLiteral

Inherits:
Expression show all
Defined in:
lib/luoma/expression.rb,
sig/luoma/expression.rbs

Instance Attribute Summary collapse

Attributes inherited from Expression

#span, #token

Instance Method Summary collapse

Methods inherited from Expression

#scope

Constructor Details

#initialize(token, segments, end_token) ⇒ StringLiteral

(t_token, Array, t_token)

Parameters:

  • token (t_token)
  • segments (Array[String|Expression])
  • end_token (t_token)


753
754
755
756
757
# File 'lib/luoma/expression.rb', line 753

def initialize(token, segments, end_token)
  super(token)
  @segments = segments
  @span = Luoma.span(token, end_token)
end

Instance Attribute Details

#segmentsArray[String|Expression] (readonly)

Returns the value of attribute segments.

Returns:



750
751
752
# File 'lib/luoma/expression.rb', line 750

def segments
  @segments
end

Instance Method Details

#childrenObject



766
767
768
# File 'lib/luoma/expression.rb', line 766

def children
  @segments.grep_v(String) #: Array[Expression]
end

#evaluate(context) ⇒ Object

Signature:

  • (RenderContext) -> untyped



760
761
762
763
764
# File 'lib/luoma/expression.rb', line 760

def evaluate(context)
  @segments.map do |s|
    s.is_a?(String) ? s : context.env.to_string(s.evaluate(context), context)
  end.join
end

#to_sObject

Signature:

  • () -> String



771
772
773
# File 'lib/luoma/expression.rb', line 771

def to_s
  @segments.map { |s| s.is_a?(String) ? s : "${#{s}}" }.join.inspect
end

#valueString?

() -> String?

Returns:

  • (String, nil)


782
783
784
# File 'lib/luoma/expression.rb', line 782

def value
  @segments.first if @segments.length == 1 && @segments.first.is_a?(String) #: String?
end

#with(token) ⇒ self

Parameters:

  • token (t_token)

Returns:

  • (self)


775
776
777
778
# File 'lib/luoma/expression.rb', line 775

def with(token)
  @span = Luoma.span(@token, token)
  self
end