Class: Krikri::Enrichments::SplitAtDelimiter

Inherits:
Object
  • Object
show all
Includes:
FieldEnrichment
Defined in:
lib/krikri/enrichments/split_at_delimiter.rb

Overview

Enrichment to split fields at a specified delimiter

splitter = SplitAtDelimiter.new(',')
splitter.enrich_value('moominpapa, moominmama')
# => ['moominpapa', 'moominmama']

Constant Summary

Constants included from SoftwareAgent

SoftwareAgent::Logger

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FieldEnrichment

#enrich, #enrich_all, #enrich_field

Methods included from Krikri::Enrichment

#enrich, #enrich!, #list_fields

Methods included from SoftwareAgent

#agent_name, #log, #run

Constructor Details

#initialize(delimiter = ';') ⇒ SplitAtDelimiter

Returns a new instance of SplitAtDelimiter


13
14
15
# File 'lib/krikri/enrichments/split_at_delimiter.rb', line 13

def initialize(delimiter = ';')
  @delimiter = delimiter
end

Instance Attribute Details

#delimiterObject

Returns the value of attribute delimiter


11
12
13
# File 'lib/krikri/enrichments/split_at_delimiter.rb', line 11

def delimiter
  @delimiter
end

Instance Method Details

#enrich_value(value) ⇒ Object


17
18
19
20
# File 'lib/krikri/enrichments/split_at_delimiter.rb', line 17

def enrich_value(value)
  return value unless value.respond_to? :split
  value.split(delimiter).map(&:strip)
end