Class: Dbtools::Database::Violation

Inherits:
Object
  • Object
show all
Defined in:
lib/dbtools/database/violation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metric:, database:, offender:, schema: nil, table: nil, column: nil, violating_records: nil, total_records: nil, solution: nil) ⇒ Violation

Returns a new instance of Violation.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dbtools/database/violation.rb', line 8

def initialize(metric:, database:, offender:, 
               schema: nil, table: nil, column: nil, 
               violating_records: nil, total_records: nil, solution: nil)
  @metric = metric
  @database = database
  @offender = offender
  @violating_records = violating_records
  @total_records = total_records
  @solution = solution
  @timestamp = Time.now.utc.iso8601

  # Save everything in a Hash to make json serialization easily possible.
  @violation = Hash.new
  @violation['metric'] = @metric
  @violation['database'] = @database
  @violation['offender'] = @offender

  @schema, @table, @column = @offender.split(".")
  @schema ||= schema
  @table ||= table
  @column ||= column
  
  @violation['schema'] = @schema 
  @violation['table'] = @table
  @violation['column'] = @column

  @violation['violating_records'] = @violating_records unless violating_records.nil?
  @violation['total_records'] = @total_records unless total_records.nil?
  @violation['measure'] = @violating_records.to_f / total_records.to_f unless (violating_records.nil? || total_records.to_i.zero?)
  @violation['solution'] = @solution unless solution.nil?
  @violation['timestamp'] = @timestamp
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



6
7
8
# File 'lib/dbtools/database/violation.rb', line 6

def column
  @column
end

#databaseObject (readonly)

Returns the value of attribute database.



6
7
8
# File 'lib/dbtools/database/violation.rb', line 6

def database
  @database
end

#metricObject (readonly)

Returns the value of attribute metric.



6
7
8
# File 'lib/dbtools/database/violation.rb', line 6

def metric
  @metric
end

#offenderObject (readonly)

Returns the value of attribute offender.



6
7
8
# File 'lib/dbtools/database/violation.rb', line 6

def offender
  @offender
end

#schemaObject (readonly)

Returns the value of attribute schema.



6
7
8
# File 'lib/dbtools/database/violation.rb', line 6

def schema
  @schema
end

#solutionObject (readonly)

Returns the value of attribute solution.



6
7
8
# File 'lib/dbtools/database/violation.rb', line 6

def solution
  @solution
end

#tableObject (readonly)

Returns the value of attribute table.



6
7
8
# File 'lib/dbtools/database/violation.rb', line 6

def table
  @table
end

#total_recordsObject (readonly)

Returns the value of attribute total_records.



6
7
8
# File 'lib/dbtools/database/violation.rb', line 6

def total_records
  @total_records
end

#violating_recordsObject (readonly)

Returns the value of attribute violating_records.



6
7
8
# File 'lib/dbtools/database/violation.rb', line 6

def violating_records
  @violating_records
end

Instance Method Details

#to_sObject



41
42
43
# File 'lib/dbtools/database/violation.rb', line 41

def to_s
  @violation.to_json
end