Class: NxtSupport::Preprocessor
- Inherits:
-
Object
- Object
- NxtSupport::Preprocessor
- 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
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#options ⇒ Object
Returns the value of attribute options.
-
#preprocessors ⇒ Object
Returns the value of attribute preprocessors.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attributes, options) ⇒ Preprocessor
constructor
A new instance of Preprocessor.
- #process(record) ⇒ Object
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, ) @type = .fetch(:column_type) { :string } @options = attributes_to_preprocess(attributes, ) extract_preprocessors register_default_preprocessors end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
12 13 14 |
# File 'lib/nxt_support/preprocessor.rb', line 12 def attributes @attributes end |
#options ⇒ Object
Returns the value of attribute options.
12 13 14 |
# File 'lib/nxt_support/preprocessor.rb', line 12 def @options end |
#preprocessors ⇒ Object
Returns the value of attribute preprocessors.
12 13 14 |
# File 'lib/nxt_support/preprocessor.rb', line 12 def preprocessors @preprocessors end |
#type ⇒ Object (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 |