Class: SqlReporter::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/sql_reporter/query.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s, c, d, cc) ⇒ Query

Returns a new instance of Query.



12
13
14
15
16
17
# File 'lib/sql_reporter/query.rb', line 12

def initialize(s, c, d, cc)
  @sql = s
  @count = c
  @duration = d
  @cached_count = cc
end

Instance Attribute Details

#cached_countObject

Returns the value of attribute cached_count.



6
7
8
# File 'lib/sql_reporter/query.rb', line 6

def cached_count
  @cached_count
end

#countObject

Returns the value of attribute count.



6
7
8
# File 'lib/sql_reporter/query.rb', line 6

def count
  @count
end

#durationObject

Returns the value of attribute duration.



6
7
8
# File 'lib/sql_reporter/query.rb', line 6

def duration
  @duration
end

#sqlObject

Returns the value of attribute sql.



6
7
8
# File 'lib/sql_reporter/query.rb', line 6

def sql
  @sql
end

Class Method Details

.null(query_name) ⇒ Object



8
9
10
# File 'lib/sql_reporter/query.rb', line 8

def self.null(query_name)
  self.new(query_name, 0, 0, 0)
end

Instance Method Details

#+(other) ⇒ Object



19
20
21
# File 'lib/sql_reporter/query.rb', line 19

def +(other)
  self.class.new(sql, count + other.count, duration + other.duration, cached_count + other.cached_count)
end

#-(other) ⇒ Object



23
24
25
# File 'lib/sql_reporter/query.rb', line 23

def -(other)
  self.class.new(sql, count - other.count, duration - other.duration, cached_count - other.cached_count)
end

#duration_formattedObject



31
32
33
# File 'lib/sql_reporter/query.rb', line 31

def duration_formatted
  duration&.round(2)
end

#post_decimal_score(max_count) ⇒ Object



27
28
29
# File 'lib/sql_reporter/query.rb', line 27

def post_decimal_score(max_count)
  count * (1 / (max_count + 1))
end