Created
April 22, 2019 16:11
-
-
Save TRex22/ef22f249fa30a61a8ab001fa376a0791 to your computer and use it in GitHub Desktop.
StringParser ruby service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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