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.



6
7
8
9
# File 'lib/tabular/column_mapper.rb', line 6

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

#symbolize(key) ⇒ Object



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

def symbolize(key)
  begin
    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
    nil
  end
end