Additional specs for #1374

This commit is contained in:
erwanlr
2019-07-23 16:26:13 +01:00
parent 0e9eb34626
commit 4ce39951a9
3 changed files with 33 additions and 5 deletions

View File

@@ -6,12 +6,14 @@ rescue StandardError => e
raise "JSON parsing error in #{file} #{e}"
end
# @return [ Symbol ]
# Sanitize and classify a slug
# @note As a class can not start with a digit or underscore, a D_ is
# put as a prefix in such case. Ugly but well :x
# Not only used to classify slugs though, but Dynamic Finder names as well
# put as a prefix in such case. Ugly but well :x
# Not only used to classify slugs though, but Dynamic Finder names as well
#
# @return [ Symbol ]
def classify_slug(slug)
classified = slug.to_s.tr('-', '_').camelize.to_s
classified = slug.to_s.gsub(/[^a-z\d\-]/i, '-').gsub(/\-{1,}/, '_').camelize.to_s
classified = "D_#{classified}" if classified[0] =~ /\d/
classified.to_sym