Sha256: b1c0484ac077fadbd89fc2c027fb9556b33e712912ef37273b4c8779bc506b01

Contents?: true

Size: 1019 Bytes

Versions: 5

Compression:

Stored size: 1019 Bytes

Contents

module NexposeTicketing
  class TicketMetrics
    attr_accessor :ticket_counts

    #Create the specific metric collecting methods
    @@ticket_counts = {}
    [:created, :updated, :closed].each do |action|
      @@ticket_counts[action] = 0
      define_method(action) do |increment=nil|
        @@ticket_counts[action] += increment || 1
      end

      define_method("get_#{action}") do
        @@ticket_counts[action]
      end
    end

    def initialize
      @start_time = nil
      @log = NexposeTicketing::NxLogger.instance
    end

    def start
      return if @start_time != nil
      @start_time = Time.now
    end

    def finish
      return if @start_time == nil  
      @time_taken = Time.at(Time.now - @start_time).utc.strftime('%H:%M:%S')
      @start_time = nil

      @log.log_message("Ticket processing took #{@time_taken} to complete.")
      @@ticket_counts.keys.each do |action|
        @log.log_message("Metrics: #{@@ticket_counts[action]} tickets were #{action}.")
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
nexpose_ticketing-1.5.2 lib/nexpose_ticketing/ticket_metrics.rb
nexpose_ticketing-1.5.1 lib/nexpose_ticketing/ticket_metrics.rb
nexpose_ticketing-1.5.0 lib/nexpose_ticketing/ticket_metrics.rb
nexpose_ticketing-1.4.2 lib/nexpose_ticketing/ticket_metrics.rb
nexpose_ticketing-1.4.1 lib/nexpose_ticketing/ticket_metrics.rb