class InterMine::PathQuery::QueryBuilder

Public Class Methods

new(model) click to toggle source
   # File lib/intermine/query.rb
76 def initialize(model)
77     @model = model
78     @query_attributes = {}
79     @subclass_constraints = []
80     @coded_constraints = []
81     @joins = []
82 end

Public Instance Methods

process_constraint(attrs) click to toggle source
    # File lib/intermine/query.rb
120 def process_constraint(attrs)
121     if attrs.has_key?("type")
122         @subclass_constraints.push({:path => attrs["path"], :sub_class => attrs["type"]})
123     else
124         args = {}
125         args[:path] = attrs["path"]
126         args[:op] = attrs["op"]
127         args[:value] = attrs["value"] if attrs.has_key?("value")
128         args[:loopPath] = attrs["loopPath"] if attrs.has_key?("loopPath")
129         args[:extra_value] = attrs["extraValue"] if attrs.has_key?("extraValue")
130         args[:code] = attrs["code"]
131         if MultiValueConstraint.valid_ops.include?(attrs["op"])
132             args[:values] = [] # actual values will be pushed on later
133         end
134         if attrs.has_key?("loopPath")
135             LoopConstraint.xml_ops.each do |k,v|
136                 args[:op] = k if v == args[:op]
137             end
138         end
139         @coded_constraints.push(args)
140     end 
141 end
query() click to toggle source
    # File lib/intermine/query.rb
 84 def query
 85     q = create_query
 86     # Add first, in case other bits depend on them
 87     @subclass_constraints.each do |sc|
 88         q.add_constraint(sc)
 89     end
 90     @joins.each do |j|
 91         q.add_join(*j)
 92     end
 93     @coded_constraints.each do |con|
 94         q.add_constraint(con)
 95     end
 96     @query_attributes.sort_by {|k, v| k}.reverse.each do |k,v|
 97         begin
 98             q.send(k + "=", v)
 99         rescue
100         end
101     end
102     return q
103 end
tag_start(name, attrs) click to toggle source
    # File lib/intermine/query.rb
105 def tag_start(name, attrs)
106     @in_value = false
107     if name == "query"
108         attrs.each do |a|
109             @query_attributes[a.first] = a.last if a.first != "model"
110         end
111     elsif name=="constraint"
112         process_constraint(attrs)
113     elsif name=="value"
114         @in_value = true
115     elsif name=="join"
116         @joins.push([attrs["path"], attrs["style"]])
117     end
118 end
text(t) click to toggle source
    # File lib/intermine/query.rb
143 def text(t)
144     @coded_constraints.last[:values].push(t)
145 end

Private Instance Methods

create_query() click to toggle source
    # File lib/intermine/query.rb
149 def create_query
150     return Query.new(@model)
151 end