Class: VORuby::ADQL::ComparisonPred
- Defined in:
- lib/voruby/adql/adql.rb,
lib/voruby/adql/transforms.rb
Overview
Represents the Comparison of two expressions.
Instance Attribute Summary collapse
-
#arg1 ⇒ Object
Returns the value of attribute arg1.
-
#arg2 ⇒ Object
Returns the value of attribute arg2.
-
#comparison ⇒ Object
Returns the value of attribute comparison.
Class Method Summary collapse
Instance Method Summary collapse
-
#count_condition(attributes, times) ⇒ Object
This method counts the number of times that a condition appears.
-
#find_condition(type, attributes) ⇒ Object
This method finds a condition given its attributes and it returns it.
-
#initialize(arg1, comparison, arg2) ⇒ ComparisonPred
constructor
A new instance of ComparisonPred.
- #match_attributtes(attributes) ⇒ Object
-
#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.
-
#remove_condition(type, attributes) ⇒ Object
This method removes a condition.
-
#replace_condition(type, attributes, new_condition) ⇒ Object
This method replaces a condition given its attributes.
- #to_adqls ⇒ Object
- #to_adqlx ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(arg1, comparison, arg2) ⇒ ComparisonPred
Returns a new instance of ComparisonPred.
1400 1401 1402 1403 1404 |
# File 'lib/voruby/adql/adql.rb', line 1400 def initialize(arg1, comparison, arg2) self.arg1 = arg1 self.comparison = comparison self.arg2 = arg2 end |
Instance Attribute Details
#arg1 ⇒ Object
Returns the value of attribute arg1.
1398 1399 1400 |
# File 'lib/voruby/adql/adql.rb', line 1398 def arg1 @arg1 end |
#arg2 ⇒ Object
Returns the value of attribute arg2.
1398 1399 1400 |
# File 'lib/voruby/adql/adql.rb', line 1398 def arg2 @arg2 end |
#comparison ⇒ Object
Returns the value of attribute comparison.
1398 1399 1400 |
# File 'lib/voruby/adql/adql.rb', line 1398 def comparison @comparison end |
Class Method Details
.create_new_object(attributes) ⇒ Object
1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 |
# File 'lib/voruby/adql/adql.rb', line 1449 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
1440 1441 1442 1443 1444 1445 1446 1447 |
# File 'lib/voruby/adql/adql.rb', line 1440 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
#count_condition(attributes, times) ⇒ Object
This method counts the number of times that a condition appears.
1519 1520 1521 1522 1523 |
# File 'lib/voruby/adql/adql.rb', line 1519 def count_condition(attributes, times) return times += 1 if self.arg1.table == attributes['table'] and self.arg1.name == attributes['name'] return times end |
#find_condition(type, attributes) ⇒ Object
This method finds a condition given its attributes and it returns it
1475 1476 1477 1478 1479 1480 1481 |
# File 'lib/voruby/adql/adql.rb', line 1475 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
1466 1467 1468 1469 1470 1471 1472 |
# File 'lib/voruby/adql/adql.rb', line 1466 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.
1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 |
# File 'lib/voruby/adql/adql.rb', line 1496 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.
1486 1487 1488 1489 1490 1491 1492 |
# File 'lib/voruby/adql/adql.rb', line 1486 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
1510 1511 1512 1513 1514 1515 1516 |
# File 'lib/voruby/adql/adql.rb', line 1510 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_adqls ⇒ Object
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_adqlx ⇒ Object
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_s ⇒ Object
1436 1437 1438 |
# File 'lib/voruby/adql/adql.rb', line 1436 def to_s "{arg1=#{self.arg1},comparison=#{self.comparison},arg2=#{self.arg2}}" end |