Class: Canql::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/canql/parser.rb

Overview

This class simplifies CANQL queries by wrapping them in a little syntactic sugar.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(query) ⇒ Parser

Returns a new instance of Parser.

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
# File 'lib/canql/parser.rb', line 11

def initialize(query)
  raise ArgumentError unless query.is_a?(String)

  @parser = CanqlParser.new
  @result = @parser.parse(query.downcase)

  return if valid?
  # FIXME: should log "Parser failed parsing \"#{query}\": #{@parser.failure_reason} " \
  #                   "(line: #{@parser.failure_line}, column: #{@parser.failure_column})"
end

Instance Attribute Details

#parserObject (readonly)

Returns the value of attribute parser.



9
10
11
# File 'lib/canql/parser.rb', line 9

def parser
  @parser
end

Instance Method Details

#failure_columnObject



34
35
36
# File 'lib/canql/parser.rb', line 34

def failure_column
  valid? ? nil : @parser.failure_column
end

#failure_lineObject



30
31
32
# File 'lib/canql/parser.rb', line 30

def failure_line
  valid? ? nil : @parser.failure_line
end

#failure_reasonObject



26
27
28
# File 'lib/canql/parser.rb', line 26

def failure_reason
  valid? ? nil : @parser.failure_reason
end

#meta_dataObject



38
39
40
# File 'lib/canql/parser.rb', line 38

def 
  valid? ? @result. : {}
end

#valid?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/canql/parser.rb', line 22

def valid?
  !@result.nil?
end