Class: JsonQL::Tolkienizer

Inherits:
Object
  • Object
show all
Defined in:
lib/json_q_l/tolkienizer.rb

Constant Summary collapse

TOKEN_LOOKUP =

the lord of the things

{
  "=" => "==",
  "OR" => "||",
  "AND" => "&&"
}

Class Method Summary collapse

Class Method Details

.run(query) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/json_q_l/tolkienizer.rb', line 11

def self.run(query)
  query.split(/\s(?=(?:[^']|'[^']*')*$)/).map do |token|
    if TOKEN_LOOKUP[token.upcase]
      TOKEN_LOOKUP[token.upcase]
    else
      token
    end
  end
end