Skip to content

Instantly share code, notes, and snippets.

@TRex22
Created April 22, 2019 16:11
Show Gist options
  • Save TRex22/ef22f249fa30a61a8ab001fa376a0791 to your computer and use it in GitHub Desktop.
Save TRex22/ef22f249fa30a61a8ab001fa376a0791 to your computer and use it in GitHub Desktop.
StringParser ruby service
module StringParser
extend self
def numeric?(str)
!!(str =~ /\A[+-]?\d+(\.[\d]+)?\z/)
end
def integer?(str)
!!(str =~ /\A[+-]?\d+\z/)
end
def to_slug(str)
str
.to_s
.tr(' ', '_')
.gsub(/[^0-9A-Za-z]/, '_')
.delete(" \t\r\n")
.snakecase
.singularize
.gsub(/_+/, '_')
.chomp('_')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment