Class: Canql::Parser
- Inherits:
-
Object
- Object
- Canql::Parser
- Defined in:
- lib/canql/parser.rb
Overview
This class simplifies CANQL queries by wrapping them in a little syntactic sugar.
Instance Attribute Summary collapse
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
Instance Method Summary collapse
- #failure_column ⇒ Object
- #failure_line ⇒ Object
- #failure_reason ⇒ Object
-
#initialize(query) ⇒ Parser
constructor
A new instance of Parser.
- #meta_data ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(query) ⇒ Parser
Returns a new instance of Parser.
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
#parser ⇒ Object (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_column ⇒ Object
34 35 36 |
# File 'lib/canql/parser.rb', line 34 def failure_column valid? ? nil : @parser.failure_column end |
#failure_line ⇒ Object
30 31 32 |
# File 'lib/canql/parser.rb', line 30 def failure_line valid? ? nil : @parser.failure_line end |
#failure_reason ⇒ Object
26 27 28 |
# File 'lib/canql/parser.rb', line 26 def failure_reason valid? ? nil : @parser.failure_reason end |
#meta_data ⇒ Object
38 39 40 |
# File 'lib/canql/parser.rb', line 38 def valid? ? @result. : {} end |
#valid? ⇒ Boolean
22 23 24 |
# File 'lib/canql/parser.rb', line 22 def valid? !@result.nil? end |