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.



2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
# File 'lib/voruby/adql/adql.rb', line 2487

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.



2483
2484
2485
# File 'lib/voruby/adql/adql.rb', line 2483

def allow
  @allow
end

#end_commentObject

Returns the value of attribute end_comment.



2485
2486
2487
# File 'lib/voruby/adql/adql.rb', line 2485

def end_comment
  @end_comment
end

#fromObject

Returns the value of attribute from.



2483
2484
2485
# File 'lib/voruby/adql/adql.rb', line 2483

def from
  @from
end

#group_byObject

Returns the value of attribute group_by.



2483
2484
2485
# File 'lib/voruby/adql/adql.rb', line 2483

def group_by
  @group_by
end

#havingObject

Returns the value of attribute having.



2483
2484
2485
# File 'lib/voruby/adql/adql.rb', line 2483

def having
  @having
end

#in_toObject

Returns the value of attribute in_to.



2483
2484
2485
# File 'lib/voruby/adql/adql.rb', line 2483

def in_to
  @in_to
end

#order_byObject

Returns the value of attribute order_by.



2483
2484
2485
# File 'lib/voruby/adql/adql.rb', line 2483

def order_by
  @order_by
end

#restrictObject

Returns the value of attribute restrict.



2483
2484
2485
# File 'lib/voruby/adql/adql.rb', line 2483

def restrict
  @restrict
end

#selection_listObject

Returns the value of attribute selection_list.



2483
2484
2485
# File 'lib/voruby/adql/adql.rb', line 2483

def selection_list
  @selection_list
end

#start_commentObject

Returns the value of attribute start_comment.



2485
2486
2487
# File 'lib/voruby/adql/adql.rb', line 2485

def start_comment
  @start_comment
end

#whereObject

Returns the value of attribute where.



2483
2484
2485
# File 'lib/voruby/adql/adql.rb', line 2483

def where
  @where
end

Class Method Details

.from_xml(node) ⇒ Object



2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
# File 'lib/voruby/adql/adql.rb', line 2576

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



2570
2571
2572
2573
2574
# File 'lib/voruby/adql/adql.rb', line 2570

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

#to_sObject



2563
2564
2565
2566
2567
2568
# File 'lib/voruby/adql/adql.rb', line 2563

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