Module: Natra::Extensions::String
- Defined in:
- lib/extensions/string.rb
Instance Method Summary collapse
- #camel_case ⇒ Object
- #camel_case! ⇒ Object
- #directory_name ⇒ Object
- #file_name ⇒ Object
- #file_name! ⇒ Object
Instance Method Details
#camel_case ⇒ Object
4 5 6 7 8 9 |
# File 'lib/extensions/string.rb', line 4 def camel_case return self.gsub(/^./) { |l| l.capitalize } if !match(/[_-]/) altered_self = self.downcase.capitalize altered_self.scan(/[_-][a-zA-Z]/).each { |match| altered_self.gsub!(match, match[1].upcase) } altered_self end |
#camel_case! ⇒ Object
11 12 13 |
# File 'lib/extensions/string.rb', line 11 def camel_case! self.replace camel_case end |
#directory_name ⇒ Object
15 16 17 |
# File 'lib/extensions/string.rb', line 15 def directory_name self.downcase.gsub(/[^a-z|\-|\_]/, '') end |
#file_name ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/extensions/string.rb', line 19 def file_name self.gsub(/[\-| ]/, '_'). gsub(/([A-Z]+|[A-Z][a-z])/) { |x| "_#{x}" }. sub(/^_/, ""). gsub(/_{2,}+/, "_"). downcase end |
#file_name! ⇒ Object
27 28 29 |
# File 'lib/extensions/string.rb', line 27 def file_name! self.replace file_name end |