Sha256: 4bc6695b916b26421bf1901c7c29af61187212878c0154f49ea01f2333a982c1

Contents?: true

Size: 1.02 KB

Versions: 19

Compression:

Stored size: 1.02 KB

Contents

#!/usr/bin/env ruby
module Rtt
  module QueryBuilder
    # Query among all tasks filtering based on parameters.
    # 
    #
    def query options = {}
      Task.all(rtt_build_conditions(options))
    end

    private

    def rtt_build_conditions options
      # default filter for today unless a date range is specified
      options[:date] = Date.today.strftime('%d-%m-%Y') if options[:to].blank? and options[:from].blank? and options[:date].blank?
      conditions = options
      conditions[:date.gte] = Date.parse(options.delete(:from)) if options[:from]
      conditions[:date.lte] = Date.parse(options.delete(:to)) if options[:to]
      conditions[:date] = Date.parse(options.delete(:date)) if options[:date]
      conditions[:user] = { :nickname => options.delete(:nickname) } if options[:nickname]
      conditions[:project] = { :name => options.delete(:project) } if options[:project]
      conditions.deep_merge!({ :project => { :client => { :name => options.delete(:client) } }}) if options[:client]
      conditions
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
rtt-0.0.0.47 lib/rtt/query_builder.rb
rtt-0.0.0.46 lib/rtt/query_builder.rb
rtt-0.0.0.45 lib/rtt/query_builder.rb
rtt-0.0.0.44 lib/rtt/query_builder.rb
rtt-0.0.0.43 lib/rtt/query_builder.rb
rtt-0.0.0.42 lib/rtt/query_builder.rb
rtt-0.0.0.41 lib/rtt/query_builder.rb
rtt-0.0.0.39 lib/rtt/query_builder.rb
rtt-0.0.0.38 lib/rtt/query_builder.rb
rtt-0.0.0.37 lib/rtt/query_builder.rb
rtt-0.0.0.36 lib/rtt/query_builder.rb
rtt-0.0.0.35 lib/rtt/query_builder.rb
rtt-0.0.0.33 lib/rtt/query_builder.rb
rtt-0.0.0.32 lib/rtt/query_builder.rb
rtt-0.0.0.31 lib/rtt/query_builder.rb
rtt-0.0.0.28 lib/rtt/query_builder.rb
rtt-0.0.0.27 lib/rtt/query_builder.rb
rtt-0.0.0.26 lib/rtt/query_builder.rb
rtt-0.0.0.25 lib/rtt/query_builder.rb