Class: Tnql::Parser
- Inherits:
-
Object
- Object
- Tnql::Parser
- Defined in:
- lib/tnql/parser.rb
Overview
This class simplifies TNQL 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
- #diagnosis_range ⇒ Object
- #failure_column ⇒ Object
- #failure_line ⇒ Object
- #failure_reason ⇒ Object
-
#initialize(query) ⇒ Parser
constructor
A new instance of Parser.
-
#messages ⇒ Object
check if any query conditions been ignored or modified.
- #meta_data ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(query) ⇒ Parser
Returns a new instance of Parser.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/tnql/parser.rb', line 9 def initialize(query) raise ArgumentError unless query.is_a?(String) @parser = TnqlParser.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.
7 8 9 |
# File 'lib/tnql/parser.rb', line 7 def parser @parser end |
Instance Method Details
#diagnosis_range ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/tnql/parser.rb', line 36 def diagnosis_range tumour_diagnosisdate = ['tumour.diagnosisdate'] return nil unless tumour_diagnosisdate starts, ends = tumour_diagnosisdate[Tnql::LIMITS] Daterange.new(Date.parse(starts), Date.parse(ends)) end |
#failure_column ⇒ Object
32 33 34 |
# File 'lib/tnql/parser.rb', line 32 def failure_column valid? ? nil : @parser.failure_column end |
#failure_line ⇒ Object
28 29 30 |
# File 'lib/tnql/parser.rb', line 28 def failure_line valid? ? nil : @parser.failure_line end |
#failure_reason ⇒ Object
24 25 26 |
# File 'lib/tnql/parser.rb', line 24 def failure_reason valid? ? nil : @parser.failure_reason end |
#messages ⇒ Object
check if any query conditions been ignored or modified
44 45 46 47 48 49 50 |
# File 'lib/tnql/parser.rb', line 44 def # check if any query conditions been ignored or modified msg = ''.html_safe .each do |_canonical_name, filter| msg += filter[Tnql::MESSAGE] if filter.key?(Tnql::MESSAGE) end msg end |
#meta_data ⇒ Object
52 53 54 |
# File 'lib/tnql/parser.rb', line 52 def valid? ? @result. : {} end |
#valid? ⇒ Boolean
20 21 22 |
# File 'lib/tnql/parser.rb', line 20 def valid? !@result.nil? end |