Sha256: fc3a6c61323d3600b02cf9961dc7b52eb0fdb4040a0dff5d48c5cc04b06cbe4b

Contents?: true

Size: 692 Bytes

Versions: 5

Compression:

Stored size: 692 Bytes

Contents

module MindMatch
  class QueryBuilder
    def initialize
      @fields = {}
    end

    def build
      @fields = @fields.freeze
      self
    end

    def to_h
      Hash[
        fields.map { |k, _v| [k, []] }
      ]
    end

    def to_s
      ''.tap do |s|
        fields.each do |k, v|
          s << "#{k} {\n"
          s << v.join("\n")
          s << "}\n"
        end
      end
    end

    private

    attr_reader :fields

    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
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mindmatch-0.1.2 lib/mind_match/query_builder.rb
mindmatch-0.1.1 lib/mind_match/query_builder.rb
mindmatch-0.1.0 lib/mind_match/query_builder.rb
mindmatch-0.0.4 lib/mind_match/query_builder.rb
mindmatch-0.0.3 lib/mind_match/query_builder.rb