Class: InterMine::PathQuery::Template

Inherits:
Query
  • Object
show all
Defined in:
lib/intermine/query.rb

Constant Summary

Constants inherited from Query

Query::HIGHEST_CODE, Query::LOWEST_CODE

Instance Attribute Summary collapse

Attributes inherited from Query

#constraints, #joins, #list_append_uri, #list_upload_uri, #logic, #model, #name, #root, #service, #sort_order, #title, #views

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Query

#add_constraint, #add_join, #add_prefix, #add_sort_order, #add_views, #all, #all_rows, #coded_constraints, #first, #first_row, #get_constraint, #inspect, is_valid_code, #next_code, #outerjoin, #path, #remove_constraint, #results, #results_reader, #rows, #set_logic, #sortOrder=, #subclass_constraints, #subclasses, #to_s, #used_codes, #view=, #where

Constructor Details

#initialize(model, root = nil, service = nil) ⇒ Template

Returns a new instance of Template.



1482
1483
1484
1485
1486
# File 'lib/intermine/query.rb', line 1482

def initialize(model, root=nil, service=nil)
    super
    @constraint_factory = TemplateConstraintFactory.new(self)
    @url = (@service.nil?) ? nil : @service.root + Service::TEMPLATE_RESULTS_PATH
end

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



1480
1481
1482
# File 'lib/intermine/query.rb', line 1480

def comment
  @comment
end

#longDescriptionObject

Returns the value of attribute longDescription.



1480
1481
1482
# File 'lib/intermine/query.rb', line 1480

def longDescription
  @longDescription
end

Class Method Details

.parser(model) ⇒ Object



1488
1489
1490
# File 'lib/intermine/query.rb', line 1488

def self.parser(model)
    return TemplateLoader.new(model)
end

Instance Method Details

#active_constraintsObject



1503
1504
1505
# File 'lib/intermine/query.rb', line 1503

def active_constraints
    return coded_constraints.select {|con| con.switchable != "off"}
end

#cloneObject



1544
1545
1546
1547
1548
# File 'lib/intermine/query.rb', line 1544

def clone
    other = super
    other.instance_variable_set(:@constraints, @constraints.map {|c| c.clone})
    return other
end

#count(params = {}) ⇒ Object



1539
1540
1541
1542
# File 'lib/intermine/query.rb', line 1539

def count(params = {})
    runner = (params.empty?) ? self : get_adjusted(params)
    runner.results_reader.get_size
end

#each_result(params = {}, start = 0, size = nil) ⇒ Object



1534
1535
1536
1537
# File 'lib/intermine/query.rb', line 1534

def each_result(params = {}, start=0, size=nil) 
    runner = (params.empty?) ? self : get_adjusted(params)
    runner.results_reader(start, size).each_result {|r| yield r}
end

#each_row(params = {}, start = 0, size = nil) ⇒ Object



1529
1530
1531
1532
# File 'lib/intermine/query.rb', line 1529

def each_row(params = {}, start=0, size=nil)
    runner = (params.empty?) ? self : get_adjusted(params)
    runner.results_reader(start, size).each_row {|r| yield r}
end

#editable_constraintsObject



1499
1500
1501
# File 'lib/intermine/query.rb', line 1499

def editable_constraints
    return coded_constraints.select {|con| con.editable}
end

#paramsObject



1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
# File 'lib/intermine/query.rb', line 1507

def params 
    p = {"name" => @name}
    actives = active_constraints
    actives.each_index do |idx|
        con = actives[idx]
        count = (idx + 1).to_s
        p["constraint" + count] = con.path.to_s
        p["op" + count] = con.template_param_op
        if con.respond_to? :value
            p["value" + count] = con.value
        elsif con.respond_to? :values
            p["value" + count] = con.values
        elsif con.respond_to? :loopPath
            p["loopPath" + count] = con.loopPath.to_s
        end
        if con.respond_to? :extra_value and !con.extra_value.nil?
            p["extra" + count] = con.extra_value
        end
    end
    return p
end

#to_xmlObject



1492
1493
1494
1495
1496
1497
# File 'lib/intermine/query.rb', line 1492

def to_xml
    doc = REXML::Document.new
    t = doc.add_element 'template', {"name" => @name, "title" => @title, "longDescription" => @longDescription, "comment" => @comment}.reject {|k,v| v.nil?}
    t.add_element super
    return t
end