Class: VORuby::ADQL::BetweenPred

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

Overview

Represents the Between expression of a query.

Direct Known Subclasses

NotBetweenPred

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg1, arg2, arg3) ⇒ BetweenPred

Returns a new instance of BetweenPred.



1502
1503
1504
1505
1506
# File 'lib/voruby/adql/adql.rb', line 1502

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

Instance Attribute Details

#arg1Object

Returns the value of attribute arg1.



1500
1501
1502
# File 'lib/voruby/adql/adql.rb', line 1500

def arg1
  @arg1
end

#arg2Object

Returns the value of attribute arg2.



1500
1501
1502
# File 'lib/voruby/adql/adql.rb', line 1500

def arg2
  @arg2
end

#arg3Object

Returns the value of attribute arg3.



1500
1501
1502
# File 'lib/voruby/adql/adql.rb', line 1500

def arg3
  @arg3
end

Class Method Details

.create_new_object(attributes) ⇒ Object



1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
# File 'lib/voruby/adql/adql.rb', line 1551

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

  arg2 = nil
  arg3 = nil
  if attributes['value_min'].is_a?(Float) and attributes['value_max'].is_a?(Float)
    arg2 = Atom.new(RealType.new(attributes['value_min']))
    arg3 = Atom.new(RealType.new(attributes['value_max']))
  elsif attributes['value_min'].is_a?(Integer) and attributes['value_max'].is_a?(Integer)
    arg2 = Atom.new(IntegerType.new(attributes['value_min']))
    arg3 = Atom.new(IntegerType.new(attributes['value_max']))
  else
    raise "value is not a real or integer"
  end

  return BetweenPred.new(arg1, arg2, arg3)
end

.from_xml(node) ⇒ Object



1542
1543
1544
1545
1546
1547
1548
1549
# File 'lib/voruby/adql/adql.rb', line 1542

def self.from_xml(node)
  arg1_node, arg2_node, arg3_node = node.elements.to_a('Arg')
  	  arg1 = Arg.from_xml(arg1_node)
  	  arg2 = Arg.from_xml(arg2_node)
  	  arg3 = Arg.from_xml(arg3_node)
	  
  	  return BetweenPred.new(arg1, arg2, arg3)
end

Instance Method Details

#find_condition(type, attributes) ⇒ Object

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



1578
1579
1580
1581
1582
1583
1584
# File 'lib/voruby/adql/adql.rb', line 1578

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



1569
1570
1571
1572
1573
1574
1575
# File 'lib/voruby/adql/adql.rb', line 1569

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



1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
# File 'lib/voruby/adql/adql.rb', line 1599

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



1589
1590
1591
1592
1593
1594
1595
# File 'lib/voruby/adql/adql.rb', line 1589

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



1613
1614
1615
1616
1617
1618
1619
# File 'lib/voruby/adql/adql.rb', line 1613

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



307
308
309
# File 'lib/voruby/adql/transforms.rb', line 307

def to_adqls
	"#{self.arg1.to_adqls} BETWEEN #{self.arg2.to_adqls} AND #{self.arg3.to_adqls}"
end

#to_adqlxObject



311
312
313
314
315
316
317
318
# File 'lib/voruby/adql/transforms.rb', line 311

def to_adqlx
  between_pred = "<Condition xsi:type=\"betweenPredType\">\n"
  between_pred << self.arg1.to_adqlx('Arg') + "\n"
  between_pred << self.arg2.to_adqlx('Arg')
  between_pred << self.arg3.to_adqlx('Arg')
  between_pred << "</Condition>\n"
  return between_pred
end

#to_sObject



1538
1539
1540
# File 'lib/voruby/adql/adql.rb', line 1538

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