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.



1530
1531
1532
1533
1534
# File 'lib/voruby/adql/adql.rb', line 1530

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.



1528
1529
1530
# File 'lib/voruby/adql/adql.rb', line 1528

def arg1
  @arg1
end

#arg2Object

Returns the value of attribute arg2.



1528
1529
1530
# File 'lib/voruby/adql/adql.rb', line 1528

def arg2
  @arg2
end

#arg3Object

Returns the value of attribute arg3.



1528
1529
1530
# File 'lib/voruby/adql/adql.rb', line 1528

def arg3
  @arg3
end

Class Method Details

.create_new_object(attributes) ⇒ Object



1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
# File 'lib/voruby/adql/adql.rb', line 1579

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



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

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

#count_condition(attributes, times) ⇒ Object

This method counts the number of times that a condition appears.



1650
1651
1652
1653
1654
# File 'lib/voruby/adql/adql.rb', line 1650

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



1606
1607
1608
1609
1610
1611
1612
# File 'lib/voruby/adql/adql.rb', line 1606

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



1597
1598
1599
1600
1601
1602
1603
# File 'lib/voruby/adql/adql.rb', line 1597

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.



1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
# File 'lib/voruby/adql/adql.rb', line 1627

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.



1617
1618
1619
1620
1621
1622
1623
# File 'lib/voruby/adql/adql.rb', line 1617

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



1641
1642
1643
1644
1645
1646
1647
# File 'lib/voruby/adql/adql.rb', line 1641

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



1566
1567
1568
# File 'lib/voruby/adql/adql.rb', line 1566

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