Class: NxtSupport::Preprocessor

Inherits:
Object
  • Object
show all
Extended by:
NxtRegistry
Defined in:
lib/nxt_support/preprocessor.rb

Constant Summary collapse

PREPROCESSORS =
registry :type, callable: false do
  level :preprocessors
end

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes, options) ⇒ Preprocessor

Returns a new instance of Preprocessor.



15
16
17
18
19
20
21
22
# File 'lib/nxt_support/preprocessor.rb', line 15

def initialize(attributes, options)
  @type = options.fetch(:column_type) { :string }
  @options = options

  attributes_to_preprocess(attributes, options)
  extract_preprocessors
  register_default_preprocessors
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



12
13
14
# File 'lib/nxt_support/preprocessor.rb', line 12

def attributes
  @attributes
end

#optionsObject

Returns the value of attribute options.



12
13
14
# File 'lib/nxt_support/preprocessor.rb', line 12

def options
  @options
end

#preprocessorsObject

Returns the value of attribute preprocessors.



12
13
14
# File 'lib/nxt_support/preprocessor.rb', line 12

def preprocessors
  @preprocessors
end

#typeObject (readonly)

Returns the value of attribute type.



13
14
15
# File 'lib/nxt_support/preprocessor.rb', line 13

def type
  @type
end

Class Method Details

.register(name, preprocessor, type = :string) ⇒ Object



71
72
73
# File 'lib/nxt_support/preprocessor.rb', line 71

def register(name, preprocessor, type = :string)
  PREPROCESSORS.type(type).preprocessors!(name, preprocessor)
end

Instance Method Details

#process(record) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/nxt_support/preprocessor.rb', line 24

def process(record)
  attributes.each do |attr|
    value_to_process = record[attr]
    processed_value = process_value(value_to_process)
    record[attr] = processed_value
  end
end