Class: VORuby::ADQL::V1_0::Select

Inherits:
Object
  • Object
show all
Includes:
SerializableToXml
Defined in:
lib/voruby/adql/1.0/adql.rb

Overview

The SELECT part of a query

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SerializableToXml

#element

Constructor Details

#initialize(selection_list, options = {}) ⇒ Select

Returns a new instance of Select.



2258
2259
2260
2261
# File 'lib/voruby/adql/1.0/adql.rb', line 2258

def initialize(selection_list, options={})
  options.each { |key, value| send("#{key}=", value) }
  self.selection_list = selection_list
end

Instance Attribute Details

#allowObject

Returns the value of attribute allow.



2253
2254
2255
# File 'lib/voruby/adql/1.0/adql.rb', line 2253

def allow
  @allow
end

#end_commentObject

Returns the value of attribute end_comment.



2253
2254
2255
# File 'lib/voruby/adql/1.0/adql.rb', line 2253

def end_comment
  @end_comment
end

#fromObject

Returns the value of attribute from.



2253
2254
2255
# File 'lib/voruby/adql/1.0/adql.rb', line 2253

def from
  @from
end

#group_byObject

Returns the value of attribute group_by.



2253
2254
2255
# File 'lib/voruby/adql/1.0/adql.rb', line 2253

def group_by
  @group_by
end

#havingObject

Returns the value of attribute having.



2253
2254
2255
# File 'lib/voruby/adql/1.0/adql.rb', line 2253

def having
  @having
end

#intoObject

Returns the value of attribute into.



2253
2254
2255
# File 'lib/voruby/adql/1.0/adql.rb', line 2253

def into
  @into
end

#order_byObject

Returns the value of attribute order_by.



2253
2254
2255
# File 'lib/voruby/adql/1.0/adql.rb', line 2253

def order_by
  @order_by
end

#restrictObject

Returns the value of attribute restrict.



2253
2254
2255
# File 'lib/voruby/adql/1.0/adql.rb', line 2253

def restrict
  @restrict
end

#selection_listObject

Returns the value of attribute selection_list.



2253
2254
2255
# File 'lib/voruby/adql/1.0/adql.rb', line 2253

def selection_list
  @selection_list
end

#start_commentObject

Returns the value of attribute start_comment.



2253
2254
2255
# File 'lib/voruby/adql/1.0/adql.rb', line 2253

def start_comment
  @start_comment
end

#whereObject

Returns the value of attribute where.



2253
2254
2255
# File 'lib/voruby/adql/1.0/adql.rb', line 2253

def where
  @where
end

Class Method Details

.from_xml(xml) ⇒ Object



2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
# File 'lib/voruby/adql/1.0/adql.rb', line 2374

def self.from_xml(xml)
  root = element_from(xml)
  
  options = {}
  
  allow = REXML::XPath.first(root, 'x:Allow', {'x' => obj_ns.uri})
  options[:allow] = xml_to_obj(allow) if allow
  
  restrict = REXML::XPath.first(root, 'x:Restrict', {'x' => obj_ns.uri})
  options[:restrict] = xml_to_obj(restrict) if restrict
  
  into = REXML::XPath.first(root, 'x:InTo', {'x' => obj_ns.uri})
  options[:into] = xml_to_obj(into) if into
  
  from = REXML::XPath.first(root, 'x:From', {'x' => obj_ns.uri})
  options[:from] = xml_to_obj(from) if from
  
  where = REXML::XPath.first(root, 'x:Where', {'x' => obj_ns.uri})
  options[:where] = xml_to_obj(where) if where
  
  group_by = REXML::XPath.first(root, 'x:GroupBy', {'x' => obj_ns.uri})
  options[:group_by] = xml_to_obj(group_by) if group_by
  
  having = REXML::XPath.first(root, 'x:Having', {'x' => obj_ns.uri})
  options[:having] = xml_to_obj(having) if having
  
  order_by = REXML::XPath.first(root, 'x:OrderBy', {'x' => obj_ns.uri})
  options[:order_by] = xml_to_obj(order_by) if order_by
  
  start_comment = REXML::XPath.first(root, 'x:StartComment', {'x' => obj_ns.uri})
  options[:start_comment] = start_comment.text if start_comment
  
  end_comment = REXML::XPath.first(root, 'x:EndComment', {'x' => obj_ns.uri})
  options[:end_comment] = end_comment.text if end_comment
  
  self.new(
    xml_to_obj(REXML::XPath.first(root, 'x:SelectionList', {'x' => obj_ns.uri})),
    options
  )
end

.xml_typeObject



2256
# File 'lib/voruby/adql/1.0/adql.rb', line 2256

def self.xml_type; 'selectType' end

Instance Method Details

#==(s) ⇒ Object



2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
# File 'lib/voruby/adql/1.0/adql.rb', line 2317

def ==(s)
 self.allow == s.allow and
 self.restrict == s.restrict and
 self.selection_list == s.selection_list and
 self.into == s.into and
 self.from == s.from and
 self.where == s.where and
 self.group_by == s.group_by and
 self.having == s.having and
 self.order_by == s.order_by and
 self.start_comment == s.start_comment and
 self.end_comment == s.end_comment 
end

#to_sObject



2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
# File 'lib/voruby/adql/1.0/adql.rb', line 2331

def to_s
  s = 'SELECT'
  s << " #{self.allow}" if self.allow
  s << " #{self.restrict}" if self.restrict
  s << " #{self.selection_list}"
  s << " #{self.into}" if self.into
  s << " #{self.from}" if self.from
  s << " #{self.where}" if self.where
  s << " #{self.group_by}" if self.group_by
  s << " #{self.having}" if self.having
  s << " #{self.order_by}" if self.order_by
  s
end

#to_xml(name = 'Select') ⇒ Object



2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
# File 'lib/voruby/adql/1.0/adql.rb', line 2345

def to_xml(name='Select')
  el = element_root(name)
  
  el.add_element(self.allow.to_xml('Allow')) if self.allow
  el.add_element(self.restrict.to_xml('Restrict')) if self.restrict
  el.add_element(self.selection_list.to_xml('SelectionList'))
  el.add_element(self.into.to_xml('InTo')) if self.into
  el.add_element(self.from.to_xml('From')) if self.from
  el.add_element(self.where.to_xml('Where')) if self.where
  el.add_element(self.group_by.to_xml('GroupBy')) if self.group_by
  el.add_element(self.having.to_xml('Having')) if self.having
  el.add_element(self.order_by.to_xml('OrderBy')) if self.order_by
  
  if self.start_comment
    sc = REXML::Element.new("#{obj_ns.prefix}:StartComment")
    sc.text = self.start_comment
    el.add_element(sc)
  end
  
  if self.end_comment
    ec = REXML::Element.new("#{obj_ns.prefix}:EndComment")
    ec.text = self.end_comment
    el.add_element(ec)
  end
  
  collapse_namespaces(el)
  el
end