Class: VORuby::ADQL::LikePred

Inherits:
Search show all
Defined in:
lib/voruby/adql/adql.rb,
lib/voruby/adql/transforms.rb

Overview

The Like expression of a query.

Direct Known Subclasses

NotLikePred

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg, pattern) ⇒ LikePred

Returns a new instance of LikePred.



1174
1175
1176
1177
# File 'lib/voruby/adql/adql.rb', line 1174

def initialize(arg, pattern)
  self.arg = arg
  self.pattern = pattern
end

Instance Attribute Details

#argObject

Returns the value of attribute arg.



1172
1173
1174
# File 'lib/voruby/adql/adql.rb', line 1172

def arg
  @arg
end

#patternObject

Returns the value of attribute pattern.



1172
1173
1174
# File 'lib/voruby/adql/adql.rb', line 1172

def pattern
  @pattern
end

Class Method Details

.create_new_object(attributes) ⇒ Object



1212
1213
1214
1215
1216
# File 'lib/voruby/adql/adql.rb', line 1212

def self.create_new_object(attributes)
  arg = ColumnReference.new(attributes['table'], attributes['name'], nil)
  pattern = StringType.new(attributes['pattern'])
  return LikePred.new(arg, pattern)
end

.from_xml(node) ⇒ Object



1203
1204
1205
1206
1207
1208
1209
1210
# File 'lib/voruby/adql/adql.rb', line 1203

def self.from_xml(node)
  arg_node = REXML::XPath.first(node, 'Arg')
  arg = Arg.from_xml(arg_node)
  pattern_node = REXML::XPath.first(node, 'Pattern')
  pattern = Pattern.from_xml(pattern_node)

  return LikePred.new(arg, pattern)
end

Instance Method Details

#find_condition(type, attributes) ⇒ Object

This method finds a condition given its attributes and it returns it



1226
1227
1228
1229
1230
1231
1232
# File 'lib/voruby/adql/adql.rb', line 1226

def find_condition(type, attributes)
  if ObjectBuilder.get_class_for(type).to_s() == self.class.to_s()
    return self if self.match_attributtes(attributes)
    return nil
  end
  return nil
end

#match_attributtes(attributes) ⇒ Object



1218
1219
1220
1221
1222
1223
# File 'lib/voruby/adql/adql.rb', line 1218

def match_attributtes(attributes)
  return true if self.arg.table == attributes['table'] and
      self.arg.name == attributes['name'] and
      self.pattern.literal.value == attributes['pattern']
  return false
end

#modify_condition(type, attributes_old, attributes_new) ⇒ Object

This method modifies a condition given its old attributes, replacing the old attributes with the new attributes.



1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
# File 'lib/voruby/adql/adql.rb', line 1247

def modify_condition(type, attributes_old, attributes_new)
  if ObjectBuilder.get_class_for(type).to_s() == self.class.to_s()
    if self.match_attributtes(attributes_old)
      return LikePred.create_new_object(attributes_new)
    else
      return nil
    end
  end
  return nil
end

#remove_condition(type, attributes) ⇒ Object

This method removes a condition. -1 means that the condition must be removed. 1 means that the condition given its attributes wasn’t found, so that the process must continue.



1237
1238
1239
1240
1241
1242
1243
# File 'lib/voruby/adql/adql.rb', line 1237

def remove_condition(type, attributes)
  if ObjectBuilder.get_class_for(type).to_s() == self.class.to_s()
    return -1 if self.match_attributtes(attributes)
    return 1
  end
  return 1
end

#replace_condition(type, attributes, new_condition) ⇒ Object

This method replaces a condition given its attributes. Returns -1 if the object must be replaced, or returns 1 if isn’t the object that must be replaced, so the process must continue



1261
1262
1263
1264
1265
1266
1267
# File 'lib/voruby/adql/adql.rb', line 1261

def replace_condition(type, attributes, new_condition)
  if ObjectBuilder.get_class_for(type).to_s() == self.class.to_s()
    return -1 if self.match_attributtes(attributes)
    return 1
  end
  return 1
end

#to_adqlsObject



260
261
262
# File 'lib/voruby/adql/transforms.rb', line 260

def to_adqls
	"#{self.arg.to_adqls} LIKE #{self.pattern.to_adqls}"
end

#to_adqlxObject



264
265
266
267
268
269
270
271
# File 'lib/voruby/adql/transforms.rb', line 264

def to_adqlx
  like_pred = "<Condition xsi:type=\"likePredType\">\n"
  like_pred << self.arg.to_adqlx('Arg') + "\n"
  like_pred << self.pattern.to_adqlx('Pattern')
  like_pred << "</Condition>\n"

  return like_pred
end

#to_sObject



1199
1200
1201
# File 'lib/voruby/adql/adql.rb', line 1199

def to_s
  "{arg=#{self.arg},pattern=#{self.pattern}}"
end