Class: CqlRuby::CqlTermNode
- Defined in:
- lib/cql_ruby/cql_nodes.rb
Overview
Represents a terminal node in a CQL parse-tree. A term node consists of the term String itself, together with, optionally, an index string and a relation. Neither or both of these must be provided - you can’t have an index without a relation or vice versa.
Instance Attribute Summary collapse
-
#index ⇒ Object
Returns the value of attribute index.
-
#relation ⇒ Object
Returns the value of attribute relation.
-
#term ⇒ Object
Returns the value of attribute term.
Instance Method Summary collapse
-
#initialize(index, relation, term) ⇒ CqlTermNode
constructor
A new instance of CqlTermNode.
- #maybe_quote(s) ⇒ Object
- #result_set_index?(qual) ⇒ Boolean
- #result_set_name ⇒ Object
- #to_cql ⇒ Object
- #to_xcql(xml = nil, prefixes = nil, sortkeys = nil) ⇒ Object
Methods inherited from CqlNode
#check_xml, #getResultSetName, #render_prefixes, #render_sortkeys
Constructor Details
#initialize(index, relation, term) ⇒ CqlTermNode
Returns a new instance of CqlTermNode.
201 202 203 204 205 206 207 |
# File 'lib/cql_ruby/cql_nodes.rb', line 201 def initialize( index, relation, term ) super() @index = index.dup @relation = relation.dup @term = term.dup end |
Instance Attribute Details
#index ⇒ Object
Returns the value of attribute index.
200 201 202 |
# File 'lib/cql_ruby/cql_nodes.rb', line 200 def index @index end |
#relation ⇒ Object
Returns the value of attribute relation.
200 201 202 |
# File 'lib/cql_ruby/cql_nodes.rb', line 200 def relation @relation end |
#term ⇒ Object
Returns the value of attribute term.
200 201 202 |
# File 'lib/cql_ruby/cql_nodes.rb', line 200 def term @term end |
Instance Method Details
#maybe_quote(s) ⇒ Object
241 242 243 244 245 246 |
# File 'lib/cql_ruby/cql_nodes.rb', line 241 def maybe_quote( s ) if s == "" || s =~ /[" \t=<>()\/]/ return "\"#{s.gsub( /"/, "\\\"" )}\"" end s end |
#result_set_index?(qual) ⇒ Boolean
209 210 211 |
# File 'lib/cql_ruby/cql_nodes.rb', line 209 def result_set_index?( qual ) /(srw|cql).resultSet(|Id|Name|SetName)/ =~ qual end |
#result_set_name ⇒ Object
213 214 215 216 |
# File 'lib/cql_ruby/cql_nodes.rb', line 213 def result_set_name return term if result_set_index?( @index ) nil end |
#to_cql ⇒ Object
230 231 232 233 234 235 236 237 238 239 |
# File 'lib/cql_ruby/cql_nodes.rb', line 230 def to_cql quoted_index = maybe_quote( @index ) quoted_term = maybe_quote( @term ) res = quoted_term if @index && /(srw|cql)\.serverChoice/i !~ @index res = "#{quoted_index} #{@relation.to_cql} #{quoted_term}" end res end |
#to_xcql(xml = nil, prefixes = nil, sortkeys = nil) ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/cql_ruby/cql_nodes.rb', line 218 def to_xcql( xml=nil, prefixes=nil, sortkeys=nil ) xml = check_xml( xml ) xml.searchClause do render_prefixes( xml, prefixes ) xml.index( @index ) @relation.to_xcql( xml ) xml.term( @term ) render_sortkeys( xml, sortkeys ) end end |