Method: Liquid::Expression.parse

Defined in:
lib/liquid/expression.rb

.parse(markup) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/liquid/expression.rb', line 11

def self.parse(markup)
  if LITERALS.key?(markup)
    LITERALS[markup]
  else
    case markup
    when /\A'(.*)'\z/m # Single quoted strings
      $1
    when /\A"(.*)"\z/m # Double quoted strings
      $1
    when /\A(-?\d+)\z/ # Integer and floats
      $1.to_i
    when /\A\((\S+)\.\.(\S+)\)\z/ # Ranges
      RangeLookup.parse($1, $2)
    when /\A(-?\d[\d\.]+)\z/ # Floats
      $1.to_f
    else
      VariableLookup.parse(markup)
    end
  end
end