Class: CSV2Avro

Inherits:
Object
  • Object
show all
Defined in:
lib/csv2avro.rb,
lib/csv2avro/schema.rb,
lib/csv2avro/version.rb,
lib/csv2avro/converter.rb,
lib/csv2avro/avro_writer.rb

Defined Under Namespace

Classes: AvroWriter, Converter, Schema

Constant Summary collapse

VERSION =
"1.0.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ CSV2Avro

Returns a new instance of CSV2Avro.



7
8
9
10
11
12
13
14
# File 'lib/csv2avro.rb', line 7

def initialize(options)
  @input_path = ARGV.first
  @schema_path = options.delete(:schema)
  @bad_rows_path = options.delete(:bad_rows)
  @stdout_option = !input_path || options.delete(:stdout)

  @options = options
end

Instance Attribute Details

#bad_rows_pathObject (readonly)

Returns the value of attribute bad_rows_path.



5
6
7
# File 'lib/csv2avro.rb', line 5

def bad_rows_path
  @bad_rows_path
end

#input_pathObject (readonly)

Returns the value of attribute input_path.



5
6
7
# File 'lib/csv2avro.rb', line 5

def input_path
  @input_path
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/csv2avro.rb', line 5

def options
  @options
end

#schema_pathObject (readonly)

Returns the value of attribute schema_path.



5
6
7
# File 'lib/csv2avro.rb', line 5

def schema_path
  @schema_path
end

#stdout_optionObject (readonly)

Returns the value of attribute stdout_option.



5
6
7
# File 'lib/csv2avro.rb', line 5

def stdout_option
  @stdout_option
end

Instance Method Details

#convertObject



16
17
18
19
20
21
# File 'lib/csv2avro.rb', line 16

def convert
  Converter.new(reader, writer, bad_rows_writer, error_writer, options, schema: schema).convert
ensure
  writer.close if writer
  bad_rows_writer.close
end