Class: Dlme::Transformer

Inherits:
Object
  • Object
show all
Defined in:
lib/transformer.rb

Overview

Generic Traject transformer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_filepath:, config_filepaths:, settings: {}, debug_writer: nil) ⇒ Transformer

Initialize a new instance of the transformer

Parameters:

  • input_filepath (String)

    filepath of input file

  • config_filepath (Array)

    filepaths of the config file

  • settings (hash) (defaults to: {})

    additional settings


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

def initialize(input_filepath:, config_filepaths:, settings: {}, debug_writer: nil)
  @input_filepath = input_filepath
  @config_filepaths = config_filepaths
  @addl_settings = settings
  @debug_writer = debug_writer
end

Instance Attribute Details

#addl_settingsObject (readonly)

Returns the value of attribute addl_settings


9
10
11
# File 'lib/transformer.rb', line 9

def addl_settings
  @addl_settings
end

#config_filepathsObject (readonly)

Returns the value of attribute config_filepaths


9
10
11
# File 'lib/transformer.rb', line 9

def config_filepaths
  @config_filepaths
end

#debug_writerObject (readonly)

Returns the value of attribute debug_writer


9
10
11
# File 'lib/transformer.rb', line 9

def debug_writer
  @debug_writer
end

#input_filepathObject (readonly)

Returns the value of attribute input_filepath


9
10
11
# File 'lib/transformer.rb', line 9

def input_filepath
  @input_filepath
end

Instance Method Details

#transformObject

Transform a stream into a new representation, using Traject, and returns the number of transformed records.


24
25
26
# File 'lib/transformer.rb', line 24

def transform
  transformer.process(File.open(input_filepath, 'r'))
end