Class: VORuby::ADQL::RegionSearch

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

Overview

Represents the Regions such as circle in Where clause.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shape, intersection = 'overlaps') ⇒ RegionSearch

Returns a new instance of RegionSearch.



1856
1857
1858
1859
# File 'lib/voruby/adql/adql.rb', line 1856

def initialize(shape, intersection='overlaps')
  self.shape = shape
  self.intersection = intersection
end

Instance Attribute Details

#intersectionObject

Returns the value of attribute intersection.



1854
1855
1856
# File 'lib/voruby/adql/adql.rb', line 1854

def intersection
  @intersection
end

#shapeObject

Returns the value of attribute shape.



1854
1855
1856
# File 'lib/voruby/adql/adql.rb', line 1854

def shape
  @shape
end

Class Method Details

.create_new_object(attributes) ⇒ Object



1887
1888
1889
1890
# File 'lib/voruby/adql/adql.rb', line 1887

def self.create_new_object(attributes)
  sh = ObjectBuilder.get_class_for(attributes['shape_type']).create_new_object(attributes)
  return RegionSearch.new(sh, attributes['intersection'].to_s)
end

.from_xml(node) ⇒ Object



1880
1881
1882
1883
1884
1885
# File 'lib/voruby/adql/adql.rb', line 1880

def self.from_xml(node)
  inter = node.attributes['intersection'].to_s
  region_node = REXML::XPath.first(node, 'Region')
  sh = Shape.from_xml(region_node)
  return RegionSearch.new(sh, inter)
end

Instance Method Details

#find_condition(type, attributes) ⇒ Object

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



1897
1898
1899
1900
1901
1902
1903
# File 'lib/voruby/adql/adql.rb', line 1897

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



1892
1893
1894
# File 'lib/voruby/adql/adql.rb', line 1892

def match_attributtes(attributes)
  return self.shape.match_attributtes(attributes)
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.



1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
# File 'lib/voruby/adql/adql.rb', line 1918

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



1908
1909
1910
1911
1912
1913
1914
# File 'lib/voruby/adql/adql.rb', line 1908

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



1932
1933
1934
1935
1936
1937
1938
# File 'lib/voruby/adql/adql.rb', line 1932

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



356
357
358
# File 'lib/voruby/adql/transforms.rb', line 356

def to_adqls
  "Region('#{self.shape.to_adqls}')"
end

#to_adqlxObject



360
361
362
363
364
365
366
367
368
369
# File 'lib/voruby/adql/transforms.rb', line 360

def to_adqlx
  region = "<Condition xsi:type=\"regionSearchType\" intersection=\"#{self.intersection.value}\">\n"
  region << "<Region "

  region << self.shape.to_adqlx
    
  region << "</Region>\n"
  region << "</Condition>\n"
  return region
end

#to_sObject



1876
1877
1878
# File 'lib/voruby/adql/adql.rb', line 1876

def to_s
  "{region={intersection=#{self.intersection},shape=#{self.shape}}}"
end