module HoneyFormat::ConvertHeaderColumn
Header
column converter
Constants
- BRACKETS
Bracket character matcher
- NON_PRINT
Non-printable characters
- REPLACE_MAP
Replace map
- SEPS
Separator characters
- SPACES
Space characters
- ZERO_WIDTH
zero-width characters - see stackoverflow.com/q/50647999
Public Class Methods
call(column, index = nil)
click to toggle source
Returns converted value and mutates the argument. @return [Symbol] the cleaned header column. @param [String, Symbol] column the string to be cleaned. @param [Integer] index the column index. @example Convert simple header
HeaderColumnConverter.call(" User name ") #=> "user_name"
@example Convert complex header
HeaderColumnConverter.call(" First name (user)") #=> :'first_name(user)'
# File lib/honey_format/converters/header_column_converter.rb, line 54 def self.call(column, index = nil) if column.nil? || column.empty? raise(ArgumentError, "column and column index can't be blank/nil") unless index return :"column#{index}" end column = column.to_s.dup column.strip! column.downcase! REPLACE_MAP.each do |data| from, to = data column.gsub!(from, to) end column.to_sym end