Sha256: 57442d68ba72f42cf382ed8067412f14a888e8ce73ac112a0205818c1ca7b19b

Contents?: true

Size: 1.33 KB

Versions: 5

Compression:

Stored size: 1.33 KB

Contents

module Chicago
  module ETL
    module Screens
      class ColumnScreen
        attr_reader :column, :table_name
        
        def initialize(table_name, column)
          @table_name = table_name
          @column = column
          @error_name = self.class.name.split('::').last.sub(/Screen$/,'').titlecase
        end

        def self.for_columns(table_name, columns)
          screens = columns.map {|column| new(table_name, column) }
          CompositeScreen.new(screens)
        end

        def call(row, errors=[])
          value = row[column.database_name]

          if applies?(value)
            overwrite_value(row)
            log_error(value, errors)
          end

          [row, errors]
        end

        def severity
          1
        end

        private

        def overwrite_value(row)
          row[column.database_name] = column.default_value
        end

        def log_error(value, errors)
          errors << error_hash(value)
        end

        def error_hash(value)
          {
            :process_name => "StandardTransformations",
            :process_version => 2,
            :table => table_name.to_s,
            :column => column.database_name.to_s,
            :severity => severity,
            :error => @error_name
          }
        end

        def applies?(value)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
chicago-etl-0.0.13 lib/chicago/etl/screens/column_screen.rb
chicago-etl-0.0.12 lib/chicago/etl/screens/column_screen.rb
chicago-etl-0.0.11 lib/chicago/etl/screens/column_screen.rb
chicago-etl-0.0.10 lib/chicago/etl/screens/column_screen.rb
chicago-etl-0.0.9 lib/chicago/etl/screens/column_screen.rb