Module: Eco::Data::Locations::NodeBase::TagValidations
- Included in:
- Eco::Data::Locations::NodeBase
- Defined in:
- lib/eco/data/locations/node_base/tag_validations.rb
Constant Summary collapse
- 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+/
Instance Method Summary collapse
- #clean_id(str) ⇒ Object
- #has_double_blanks?(str) ⇒ Boolean
- #identify_invalid_characters(str) ⇒ Object
- #invalid_warned! ⇒ Object
- #invalid_warned? ⇒ Boolean
- #remove_double_blanks(str) ⇒ Object
- #replace_not_allowed(str) ⇒ Object
Instance Method Details
#clean_id(str) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/eco/data/locations/node_base/tag_validations.rb', line 9 def clean_id(str) blanks_x2 = has_double_blanks?(str) partial = replace_not_allowed(str) remove_double_blanks(partial).tap do |result| next if invalid_warned? if partial != str invalid_chars = identify_invalid_characters(str) puts "• (Row: #{self.row_num}) Invalid characters _#{invalid_chars}_ (removed): '#{str}' (converted to '#{result}')" elsif blanks_x2 puts "• (Row: #{self.row_num}) Double blanks (removed): '#{str}' (converted to '#{result}')" end invalid_warned! end end |
#has_double_blanks?(str) ⇒ Boolean
32 33 34 35 |
# File 'lib/eco/data/locations/node_base/tag_validations.rb', line 32 def has_double_blanks?(str) return false if str.nil? str.match(DOUBLE_BLANKS) end |
#identify_invalid_characters(str) ⇒ Object
48 49 50 |
# File 'lib/eco/data/locations/node_base/tag_validations.rb', line 48 def identify_invalid_characters(str) str.gsub(VALID_TAG_CHARS, '') end |
#invalid_warned! ⇒ Object
28 29 30 |
# File 'lib/eco/data/locations/node_base/tag_validations.rb', line 28 def invalid_warned! @invalid_warned = true end |
#invalid_warned? ⇒ Boolean
24 25 26 |
# File 'lib/eco/data/locations/node_base/tag_validations.rb', line 24 def invalid_warned? @invalid_warned ||= false end |
#remove_double_blanks(str) ⇒ Object
37 38 39 40 |
# File 'lib/eco/data/locations/node_base/tag_validations.rb', line 37 def remove_double_blanks(str) return nil if str.nil? str.gsub(DOUBLE_BLANKS, ' ').strip end |
#replace_not_allowed(str) ⇒ Object
42 43 44 45 46 |
# File 'lib/eco/data/locations/node_base/tag_validations.rb', line 42 def replace_not_allowed(str) return nil if str.nil? return str if str.match(VALID_TAG_REGEX) str.gsub(INVALID_TAG_REGEX, ' ') end |