Sha256: 3faa378f462c37ce452ffde9c9ebc7030e59d4e64bbd6a4b0f1b8d6115c815c1
Contents?: true
Size: 995 Bytes
Versions: 1
Compression:
Stored size: 995 Bytes
Contents
module HoneyFormat # Header column converter module ConvertHeaderValue # Replace map REPLACE_MAP = [ [/ \(/, '('], [/ \[/, '['], [/ \{/, '{'], [/\) /, ')'], [/\] /, ']'], [/\} /, '}'], [/ /, '_'], [/-/, '_'] ].map { |array| array.freeze }.freeze # Returns converted value and mutates the argument. # @return [Symbol] the cleaned header column. # @param [String] column the string to be cleaned. # @example Convert simple header # ConvertHeaderValue.call(" User name ") #=> "user_name" # @example Convert complex header # ConvertHeaderValue.call(" First name (user)") #=> :'first_name(user)' def self.call(column, index) return :"column#{index}" if column.nil? || column.empty? column = column.dup column.strip! column.downcase! REPLACE_MAP.each do |data| from, to = data column.gsub!(from, to) end column.to_sym end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
honey_format-0.9.0 | lib/honey_format/convert_header_value.rb |