Class: VORuby::ADQL::Select

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

Overview

The SELECT part of a query.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(selection_list, allow = nil, restrict = nil, in_to = nil, from = nil, where = nil, group_by = nil, having = nil, order_by = nil, start_comment = nil, end_comment = nil) ⇒ Select

Returns a new instance of Select.



2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
# File 'lib/voruby/adql/adql.rb', line 2435

def initialize(selection_list, allow=nil, restrict=nil, in_to=nil,
  from=nil, where=nil, group_by=nil, having=nil, order_by=nil,
  start_comment=nil, end_comment=nil)
  self.selection_list = selection_list
  self.allow = allow
  self.restrict = restrict
  self.in_to = in_to
  self.from = from
  self.where = where
  self.group_by = group_by
  self.having = having
  self.order_by = order_by
  self.start_comment = start_comment
  self.end_comment = end_comment
end

Instance Attribute Details

#allowObject

Returns the value of attribute allow.



2431
2432
2433
# File 'lib/voruby/adql/adql.rb', line 2431

def allow
  @allow
end

#end_commentObject

Returns the value of attribute end_comment.



2433
2434
2435
# File 'lib/voruby/adql/adql.rb', line 2433

def end_comment
  @end_comment
end

#fromObject

Returns the value of attribute from.



2431
2432
2433
# File 'lib/voruby/adql/adql.rb', line 2431

def from
  @from
end

#group_byObject

Returns the value of attribute group_by.



2431
2432
2433
# File 'lib/voruby/adql/adql.rb', line 2431

def group_by
  @group_by
end

#havingObject

Returns the value of attribute having.



2431
2432
2433
# File 'lib/voruby/adql/adql.rb', line 2431

def having
  @having
end

#in_toObject

Returns the value of attribute in_to.



2431
2432
2433
# File 'lib/voruby/adql/adql.rb', line 2431

def in_to
  @in_to
end

#order_byObject

Returns the value of attribute order_by.



2431
2432
2433
# File 'lib/voruby/adql/adql.rb', line 2431

def order_by
  @order_by
end

#restrictObject

Returns the value of attribute restrict.



2431
2432
2433
# File 'lib/voruby/adql/adql.rb', line 2431

def restrict
  @restrict
end

#selection_listObject

Returns the value of attribute selection_list.



2431
2432
2433
# File 'lib/voruby/adql/adql.rb', line 2431

def selection_list
  @selection_list
end

#start_commentObject

Returns the value of attribute start_comment.



2433
2434
2435
# File 'lib/voruby/adql/adql.rb', line 2433

def start_comment
  @start_comment
end

#whereObject

Returns the value of attribute where.



2431
2432
2433
# File 'lib/voruby/adql/adql.rb', line 2431

def where
  @where
end

Class Method Details

.from_xml(node) ⇒ Object



2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
# File 'lib/voruby/adql/adql.rb', line 2524

def self.from_xml(node)
  # SelectionList
  sl_node = REXML::XPath.first(node, 'SelectionList') or raise "No SelectionList element"
  selection_list = SelectionList.from_xml(sl_node)

  # Allow
  allow_node = REXML::XPath.first(node, 'Allow')
  allow = nil
  allow = Allow.from_xml(allow_node) if allow_node

  # Restrict
  restrict_node = REXML::XPath.first(node, 'Restrict')
  restrict = nil
  restrict = Restrict.from_xml(restrict_node) if restrict_node

  # InTo
  into_node = REXML::XPath.first(node, 'InTo')
  into = nil
  into = InTo.from_xml(into_node) if into_node

  # From
  from_node = REXML::XPath.first(node, 'From')
  from = nil
  from = From.from_xml(from_node) if from_node

  # Where
  where_node = REXML::XPath.first(node, 'Where')
  where = nil
  where = Where.from_xml(where_node) if where_node

  # GroupBy
  groupby_node = REXML::XPath.first(node, 'GroupBy')
  groupby = nil
  groupby = GroupBy.from_xml(groupby_node) if groupby_node

  # Having
  having_node = REXML::XPath.first(node, 'Having')
  having = nil
  having = Having.from_xml(having_node) if having_node

  # OrderBy
  orderby_node = REXML::XPath.first(node, 'OrderBy')
  orderby = nil
  orderby = OrderBy.from_xml(orderby_node) if orderby_node

  # StartComment
  start_comment_node = REXML::XPath.first(node, 'StartComment')
  start_comment = nil
  start_comment = StartComment.from_xml(start_comment_node) if start_comment_node

  # EndComment
  end_comment_node = REXML::XPath.first(node, 'EndComment')
  end_comment = nil
  end_comment = EndComment.from_xml(end_comment_node) if end_comment_node

  return Select.new(selection_list, allow, restrict, into,
                    from, where, groupby, having, orderby,
                    start_comment, end_comment)
end

Instance Method Details

#to_adqlsObject



501
502
503
504
505
506
507
508
509
510
511
512
513
514
# File 'lib/voruby/adql/transforms.rb', line 501

def to_adqls
  select = 'SELECT'
  select << " #{self.allow.to_adqls}" if self.allow
  select << " #{self.restrict.to_adqls}" if self.restrict
  select << " #{self.selection_list.to_adqls}"
  select << " #{self.in_to.to_adqls}" if self.in_to
  select << " #{self.from.to_adqls}" if self.from
  select << " #{self.where.to_adqls}" if self.where
  select << " #{self.group_by.to_adqls}" if self.group_by
  select << " #{self.having.to_adqls}" if self.having
  select << " #{self.order_by.to_adqls}" if self.order_by

  return select
end

#to_adqlxObject



516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
# File 'lib/voruby/adql/transforms.rb', line 516

def to_adqlx
  adqlx = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
      "<Select xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
      "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
      "xmlns=\"http://www.ivoa.net/xml/ADQL/v0.9\" " +
      "xmlns:reg=\"http://www.ivoa.net/xml/STC/STCregion/v1.20\">\n"

  #      adqlx << " #{self.allow.to_adqlx}" if self.allow
  #      adqlx << " #{self.restrict.to_adqlx}" if self.restrict
  adqlx << " #{self.selection_list.to_adqlx}"
  #      adqlx << " #{self.in_to.to_adqlx}" if self.in_to
  adqlx << " #{self.from.to_adqlx}" if self.from
  adqlx << " #{self.where.to_adqlx}" if self.where
  #      adqlx << " #{self.group_by.to_adqlx}" if self.group_by
  #      adqlx << " #{self.having.to_adqlx}" if self.having
  #      adqlx << " #{self.order_by.to_adqlx}" if self.order_by
  adqlx << "</Select>"

  return adqlx
end

#to_file(file_path) ⇒ Object



2518
2519
2520
2521
2522
# File 'lib/voruby/adql/adql.rb', line 2518

def to_file(file_path)
  file = File.new(file_path, 'w')
  file.syswrite(self.to_adqlx)
  file.close()
end

#to_sObject



2511
2512
2513
2514
2515
2516
# File 'lib/voruby/adql/adql.rb', line 2511

def to_s
  "{allow=#{self.allow},restrict=#{self.restrict},selection_list=#{self.selection_list}," +
  "in_to=#{self.in_to},from=#{self.from},where=#{self.where},group_by=#{self.group_by}," +
  "having=#{self.having},order_by=#{self.order_by},start_comment=#{self.start_comment}," +
  "end_comment=#{self.end_comment}}"
end