Class: WAB::Impl::ExprParser
- Inherits:
-
Object
- Object
- WAB::Impl::ExprParser
- Defined in:
- lib/wab/impl/expr_parser.rb
Constant Summary collapse
- XMAP =
{ between: Between, eq: Eq, gt: Gt, gte: Gte, in: In, has: Has, lt: Lt, lte: Lte, regex: Regex, and: And, or: Or, not: Not, }.freeze
Class Method Summary collapse
-
.parse(native) ⇒ Object
Parses an Array into a set of Expr subsclasses.
Class Method Details
.parse(native) ⇒ Object
Parses an Array into a set of Expr subsclasses.
- native
-
native Ruby representation of the expression.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/wab/impl/expr_parser.rb', line 24 def parse(native) raise WAB::TypeError.new('Invalid expression. Must be an Array.') unless native.is_a?(Array) op = native[0] op = op.downcase.to_sym unless op.is_a?(Symbol) xclass = XMAP[op] raise WAB::Error.new("#{op} is not a valid expression function.") if xclass.nil? args = [] native[1..-1].each { |n| args << if n.is_a?(Array) parse(n) elsif n.is_a?(String) unless n.empty? if "'" == n[0] n[1..-1] else WAB::Impl::Data.detect_string(n) end end else n end } xclass.new(*args) end |