Module: GuardianSearcher::Helpers::Util
- Included in:
- Content
- Defined in:
- lib/guardian_searcher/helpers/util.rb
Instance Method Summary collapse
-
#snakecase(key) ⇒ Object
this method comes from the facets library I took it from there because it was easier for what I have in mind.
Instance Method Details
#snakecase(key) ⇒ Object
this method comes from the facets library I took it from there because it was easier for what I have in mind
original here github.com/rubyworks/facets docs here www.rubydoc.info/github/rubyworks/facets/String:snakecase
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/guardian_searcher/helpers/util.rb', line 12 def snakecase(key) return unless key.is_a? String key.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .tr("-", "_") .gsub(/\s/, "_") .gsub(/__+/, "_") .downcase end |