Sha256: 8de66cb9b95a5117a3111d7f7c48a161cd98dd53d840ab79a556e4aff7968f33
Contents?: true
Size: 1.72 KB
Versions: 44
Compression:
Stored size: 1.72 KB
Contents
module Eco::Data::Locations::NodeBase module TagValidations include Eco::Language::AuxiliarLogger ALLOWED_CHARACTERS = "A-Za-z0-9 &_'\/.-" VALID_TAG_REGEX = /^[#{ALLOWED_CHARACTERS}]+$/ INVALID_TAG_REGEX = /[^#{ALLOWED_CHARACTERS}]+/ VALID_TAG_CHARS = /[#{ALLOWED_CHARACTERS}]+/ DOUBLE_BLANKS = /\s\s+/ def clean_id(str, notify: true, ref: '') blanks_x2 = has_double_blanks?(str) partial = replace_not_allowed(str) remove_double_blanks(partial).tap do |result| next unless notify next if invalid_warned?(str) if partial != str invalid_chars = identify_invalid_characters(str) log(:warn) { "• #{ref}Invalid characters _#{invalid_chars}_ <<_removed_: '#{str}' :_converted_>> '#{result}'" } elsif blanks_x2 log(:warn) { "• #{ref}Double blanks removed: '#{str}' :_converted_>> '#{result}'" } end invalid_warned!(str) end end def invalid_warned?(str) invalid_warned[str] ||= false end def invalid_warned!(str) invalid_warned[str] = true end def invalid_warned @invalid_warned ||= {} end def has_double_blanks?(str) return false if str.nil? str.match(DOUBLE_BLANKS) end def remove_double_blanks(str) return nil if str.nil? str.gsub(DOUBLE_BLANKS, ' ').strip end def replace_not_allowed(str) return nil if str.nil? return str if str.match(VALID_TAG_REGEX) str.gsub(INVALID_TAG_REGEX, ' ') end def identify_invalid_characters(str) str.gsub(VALID_TAG_CHARS, '') end end end
Version data entries
44 entries across 44 versions & 1 rubygems