class MindMatch::QueryBuilder
Attributes
fields[R]
Public Class Methods
new()
click to toggle source
# File lib/mind_match/query_builder.rb, line 3 def initialize @fields = {} end
Public Instance Methods
build()
click to toggle source
# File lib/mind_match/query_builder.rb, line 7 def build @fields = @fields.freeze self end
to_h()
click to toggle source
# File lib/mind_match/query_builder.rb, line 12 def to_h Hash[ fields.map { |k, _v| [k, []] } ] end
to_s()
click to toggle source
# File lib/mind_match/query_builder.rb, line 18 def to_s ''.tap do |s| fields.each do |k, v| s << "#{k} {" s << join(v) s << "}\n" end end end
Private Instance Methods
join(v)
click to toggle source
# File lib/mind_match/query_builder.rb, line 32 def join(v) v.each_with_object('') do |f, s| case f when Hash f.each do |key, value| s << "\n" unless s.end_with?("\n") s << "#{key} {" s << join(value) s << "}" end else s << "\n" unless s.end_with?("\n") s << f.to_s end end end
method_missing(m, *args, &block)
click to toggle source
Calls superclass method
# File lib/mind_match/query_builder.rb, line 49 def method_missing(m, *args, &block) method = m.to_s if method.start_with?('with_') key = method.split('with_')[1] @fields[key] = args[0] self else super(m, *args, &block) end end