129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
# File 'lib/libertree/query.rb', line 129
def to_s
res = []
apply_template = lambda do |template, groups|
res += groups[:negations].map {|v| '-' + template.call(v)}
res += groups[:requirements].map {|v| '+' + template.call(v)}
res += groups[:regular].map {|v| template.call(v)}
end
@parsed_query.each_pair do |key, groups|
template = case key
when 'phrase'
lambda {|v| "\"%s\"" % v }
when 'via'
lambda {|v| ":via \"%s\"" % v }
when 'visibility'
lambda {|v| ":visibility %s" % v }
when 'word-count'
lambda {|v| ":word-count %s" % v }
when 'flag'
lambda {|v| ":%s" % v }
when 'word'
lambda {|v| v }
when 'tag'
lambda {|v| "#%s" % v }
when 'from'
lambda {|v| ":from %s" % Model::Member[v.to_i].handle }
when 'river'
lambda {|v| ":river \"%s\"" % Model::River[v.id.to_i].label }
when 'contact-list'
template = lambda {|v| ":contact-list \"%s\"" % Model::ContactList[v.first.to_i].name }
when 'spring'
lambda {|v| pool = Model::Pool[v.id.to_i]; ":spring \"%s\" \"%s\"" % [pool.name, pool.member.handle] }
end
apply_template.call(template, groups)
end
res.join(' ')
end
|