Class: CqlRuby::ModifierSet

Inherits:
CqlNode
  • Object
show all
Defined in:
lib/cql_ruby/cql_nodes.rb,
lib/cql_ruby/cql_to_solr.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from CqlNode

#check_xml, #getResultSetName, #render_prefixes, #render_sortkeys

Constructor Details

#initialize(base) ⇒ ModifierSet

Returns a new instance of ModifierSet.



122
123
124
125
126
# File 'lib/cql_ruby/cql_nodes.rb', line 122

def initialize( base )
  # super
  @base = base.dup
  @modifiers = []
end

Instance Attribute Details

#baseObject

Returns the value of attribute base.



120
121
122
# File 'lib/cql_ruby/cql_nodes.rb', line 120

def base
  @base
end

#modifiersObject

Returns the value of attribute modifiers.



120
121
122
# File 'lib/cql_ruby/cql_nodes.rb', line 120

def modifiers
  @modifiers
end

Instance Method Details

#add_modifier(type, comparison = nil, value = nil) ⇒ Object



128
129
130
# File 'lib/cql_ruby/cql_nodes.rb', line 128

def add_modifier( type, comparison=nil, value=nil)
  modifiers << Modifier.new( type, comparison, value )
end

#sortkey_to_xcql(xml = nil) ⇒ Object



145
146
147
148
# File 'lib/cql_ruby/cql_nodes.rb', line 145

def sortkey_to_xcql( xml=nil )
  xml = check_xml( xml )
  underlying_to_xcql( xml, "key", "index" )
end

#to_cqlObject



132
133
134
135
136
137
138
# File 'lib/cql_ruby/cql_nodes.rb', line 132

def to_cql
  res = @base.dup
  @modifiers.each do |m| 
    res << "/#{m.to_cql}"
  end
  res
end

#to_solrObject

Raises:



163
164
165
166
167
168
# File 'lib/cql_ruby/cql_to_solr.rb', line 163

def to_solr
  raise CqlException.new("#to_solr not supported for PROX operator") if @base.upcase == "PROX"
  raise CqlException.new("#to_solr does not support boolean modifiers: #{to_cql}") if @modifiers.length != 0
  
  "#{@base.upcase}"
end

#to_xcql(xml = nil, top_level_element = "unknowElement") ⇒ Object



140
141
142
143
# File 'lib/cql_ruby/cql_nodes.rb', line 140

def to_xcql( xml=nil, top_level_element="unknowElement" )
  xml = check_xml( xml )
  underlying_to_xcql( xml, top_level_element, "value" )
end

#underlying_to_xcql(xml, top_level_element, value_element) ⇒ Object



150
151
152
153
154
155
156
157
158
159
# File 'lib/cql_ruby/cql_nodes.rb', line 150

def underlying_to_xcql( xml, top_level_element, value_element )
  xml.tag!( top_level_element ) do
    xml.tag!( value_element, @base )
    if @modifiers.any?
      xml.modifiers do
        @modifiers.each { |modifier| modifier.to_xcql( xml, "comparison" ) }
      end
    end
  end
end