class NdrImport::Avro::Table

Syntatic sugar to ensure ‘header_lines` and `footer_lines` are 1 and 0 respectively. All other Table logic is inherited from `NdrImport::Table`

Public Class Methods

all_valid_options() click to toggle source
Calls superclass method NdrImport::Table::all_valid_options
# File lib/ndr_import/avro/table.rb, line 20
def self.all_valid_options
  super - %w[delimiter header_lines footer_lines]
end
from_schema(safe_path) click to toggle source

Scaffold an ‘NdrImport::Avro::Table` instance from avro schema file

# File lib/ndr_import/avro/table.rb, line 9
def self.from_schema(safe_path)
  raise SecurityError, "#{safe_path} is not a SafePath" unless safe_path.is_a? SafePath

  table_columns = columns_from(::Avro::Schema.parse(::File.open(safe_path)))
  file_name     = SafeFile.basename(safe_path).sub(/\.avsc\z/, '.avro')

  new(filename_pattern: "/#{file_name}\\z/",
      klass: 'ExampleKlass',
      columns: table_columns)
end

Private Class Methods

columns_from(schema) click to toggle source
# File lib/ndr_import/avro/table.rb, line 32
def self.columns_from(schema)
  schema.fields.map do |field|
    column = { column: field.name }
    column[:mappings] = { field: field.name, daysafter: '1970-01-01' } if date_field?(field)

    column
  end
end
date_field?(field) click to toggle source
# File lib/ndr_import/avro/table.rb, line 41
def self.date_field?(field)
  field.type.schemas.any? { |schema| schema.logical_type == 'date' }
end

Public Instance Methods

header_lines() click to toggle source
# File lib/ndr_import/avro/table.rb, line 24
def header_lines
  1
end