Class: Tabular::ColumnMapper

Inherits:
Object
  • Object
show all
Includes:
Blank
Defined in:
lib/tabular/column_mapper.rb

Instance Method Summary collapse

Methods included from Blank

#is_blank?

Instance Method Details

#map(key) ⇒ Object

Convert key to normalized symbol. Subclass for more complex mapping.



8
9
10
11
12
# File 'lib/tabular/column_mapper.rb', line 8

def map(key)
  return nil if is_blank?(key)

  symbolize key
end

#symbolize(key) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tabular/column_mapper.rb', line 14

def symbolize(key)
  key.to_s.strip.gsub(/::/, "/")
     .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
     .gsub(/([a-z\d])([A-Z])/, '\1_\2')
     .tr("-", "_")
     .gsub(/ +/, "_")
     .delete(";")
     .downcase
     .to_sym
rescue StandardError
  nil
end