Class: VORuby::ADQL::ComparisonPred

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

Overview

Represents the Comparison of two expressions.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg1, comparison, arg2) ⇒ ComparisonPred

Returns a new instance of ComparisonPred.



1379
1380
1381
1382
1383
# File 'lib/voruby/adql/adql.rb', line 1379

def initialize(arg1, comparison, arg2)
  self.arg1 = arg1
  self.comparison = comparison
  self.arg2 = arg2
end

Instance Attribute Details

#arg1Object

Returns the value of attribute arg1.



1377
1378
1379
# File 'lib/voruby/adql/adql.rb', line 1377

def arg1
  @arg1
end

#arg2Object

Returns the value of attribute arg2.



1377
1378
1379
# File 'lib/voruby/adql/adql.rb', line 1377

def arg2
  @arg2
end

#comparisonObject

Returns the value of attribute comparison.



1377
1378
1379
# File 'lib/voruby/adql/adql.rb', line 1377

def comparison
  @comparison
end

Class Method Details

.create_new_object(attributes) ⇒ Object



1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
# File 'lib/voruby/adql/adql.rb', line 1428

def self.create_new_object(attributes)
  arg1 = ColumnReference.new(attributes['table'], attributes['name'], nil)

  arg2 = nil
  if attributes['value'].is_a?(Float)
    arg2 = Atom.new(RealType.new(attributes['value']))
  elsif attributes['value'].is_a?(Integer)
    arg2 = Atom.new(IntegerType.new(attributes['value']))
  elsif attributes['value'].is_a?(String)
    arg2 = Atom.new(StringType.new(attributes['value']))
  else
    raise "value is not a real, integer or string"
  end

  return ComparisonPred.new(arg1, attributes['comparison'], arg2)
end

.from_xml(node) ⇒ Object



1419
1420
1421
1422
1423
1424
1425
1426
# File 'lib/voruby/adql/adql.rb', line 1419

def self.from_xml(node)
  comparison_s = node.attributes['Comparison']
  arg1_node, arg2_node = node.elements.to_a('Arg')
  arg1 = Arg.from_xml(arg1_node)
  arg2 = Arg.from_xml(arg2_node)

  return ComparisonPred.new(arg1, comparison_s, arg2)
end

Instance Method Details

#find_condition(type, attributes) ⇒ Object

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



1454
1455
1456
1457
1458
1459
1460
# File 'lib/voruby/adql/adql.rb', line 1454

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



1445
1446
1447
1448
1449
1450
1451
# File 'lib/voruby/adql/adql.rb', line 1445

def match_attributtes(attributes)
  return true if self.arg1.table == attributes['table'] and
      self.arg1.name == attributes['name'] and
      self.comparison.value == attributes['comparison'] and
      self.arg2.literal.value == attributes['value']
  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.



1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
# File 'lib/voruby/adql/adql.rb', line 1475

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 ComparisonPred.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.



1465
1466
1467
1468
1469
1470
1471
# File 'lib/voruby/adql/adql.rb', line 1465

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



1489
1490
1491
1492
1493
1494
1495
# File 'lib/voruby/adql/adql.rb', line 1489

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



293
294
295
# File 'lib/voruby/adql/transforms.rb', line 293

def to_adqls
	"#{self.arg1.to_adqls} #{self.comparison.to_adqls} #{self.arg2.to_adqls}"
end

#to_adqlxObject



297
298
299
300
301
302
303
# File 'lib/voruby/adql/transforms.rb', line 297

def to_adqlx
  comparison_pred = "<Condition xsi:type=\"comparisonPredType\" Comparison=\"#{self.comparison.to_adqlx}\">\n"
        comparison_pred << self.arg1.to_adqlx('Arg') + "\n"
        comparison_pred << self.arg2.to_adqlx('Arg')
        comparison_pred << "</Condition>\n"
        return comparison_pred
end

#to_sObject



1415
1416
1417
# File 'lib/voruby/adql/adql.rb', line 1415

def to_s
  "{arg1=#{self.arg1},comparison=#{self.comparison},arg2=#{self.arg2}}"
end