Sha256: 6e71faa2d18fd3e3625b810e46be8b0e3730b758a7751b8e70d4ea561b630ff4

Contents?: true

Size: 1.06 KB

Versions: 7

Compression:

Stored size: 1.06 KB

Contents

module Appstats
  class Result < ActiveRecord::Base
    set_table_name "appstats_results"

    attr_accessible :name, :result_type, :query, :query_as_sql, :count, :action, :host, :from_date, :to_date, :contexts

    def date_to_s
      return "" if from_date.nil? && to_date.nil?
      return "#{from_date_to_s} to present" if !from_date.nil? && to_date.nil? && created_at.nil?
      return "#{from_date_to_s} to #{created_at.strftime('%Y-%m-%d')}" if !from_date.nil? && to_date.nil? && !created_at.nil?
      return "up to #{to_date_to_s}" if from_date.nil? && !to_date.nil?
      "#{from_date_to_s} to #{to_date_to_s}"
    end

    def from_date_to_s
      return "" if from_date.nil?
      from_date.strftime('%Y-%m-%d')
    end

    def to_date_to_s
      return "" if to_date.nil?
      to_date.strftime('%Y-%m-%d')
    end

    def ==(o)
       o.class == self.class && o.send(:state) == state
    end
    alias_method :eql?, :==

    private

      def state
        [name, result_type, query, query_as_sql, count, action, host, from_date, to_date,contexts]
      end

    
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
appstats-0.11.7 lib/appstats/result.rb
appstats-0.11.6 lib/appstats/result.rb
appstats-0.11.5 lib/appstats/result.rb
appstats-0.11.4 lib/appstats/result.rb
appstats-0.11.3 lib/appstats/result.rb
appstats-0.11.2 lib/appstats/result.rb
appstats-0.10.0 lib/appstats/result.rb