Class: Dbtools::Database::Violation
- Inherits:
-
Object
- Object
- Dbtools::Database::Violation
- Defined in:
- lib/dbtools/database/violation.rb
Instance Attribute Summary collapse
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#metric ⇒ Object
readonly
Returns the value of attribute metric.
-
#offender ⇒ Object
readonly
Returns the value of attribute offender.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#solution ⇒ Object
readonly
Returns the value of attribute solution.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
-
#total_records ⇒ Object
readonly
Returns the value of attribute total_records.
-
#violating_records ⇒ Object
readonly
Returns the value of attribute violating_records.
Instance Method Summary collapse
-
#initialize(metric:, database:, offender:, schema: nil, table: nil, column: nil, violating_records: nil, total_records: nil, solution: nil) ⇒ Violation
constructor
A new instance of Violation.
- #to_s ⇒ Object
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
#column ⇒ Object (readonly)
Returns the value of attribute column.
6 7 8 |
# File 'lib/dbtools/database/violation.rb', line 6 def column @column end |
#database ⇒ Object (readonly)
Returns the value of attribute database.
6 7 8 |
# File 'lib/dbtools/database/violation.rb', line 6 def database @database end |
#metric ⇒ Object (readonly)
Returns the value of attribute metric.
6 7 8 |
# File 'lib/dbtools/database/violation.rb', line 6 def metric @metric end |
#offender ⇒ Object (readonly)
Returns the value of attribute offender.
6 7 8 |
# File 'lib/dbtools/database/violation.rb', line 6 def offender @offender end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
6 7 8 |
# File 'lib/dbtools/database/violation.rb', line 6 def schema @schema end |
#solution ⇒ Object (readonly)
Returns the value of attribute solution.
6 7 8 |
# File 'lib/dbtools/database/violation.rb', line 6 def solution @solution end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
6 7 8 |
# File 'lib/dbtools/database/violation.rb', line 6 def table @table end |
#total_records ⇒ Object (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_records ⇒ Object (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_s ⇒ Object
41 42 43 |
# File 'lib/dbtools/database/violation.rb', line 41 def to_s @violation.to_json end |