Module: Singu::Extensions::String
- Defined in:
- lib/singu/extensions.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 10 11 12 |
# File 'lib/singu/extensions.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 do |match| altered_self.gsub!(match, match[1].upcase) end altered_self end |
#camel_case! ⇒ Object
14 15 16 |
# File 'lib/singu/extensions.rb', line 14 def camel_case! self.replace camel_case end |
#directory_name ⇒ Object
18 19 20 |
# File 'lib/singu/extensions.rb', line 18 def directory_name self.downcase.gsub(/[^a-z|\-|\_]/, '') end |
#file_name ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/singu/extensions.rb', line 22 def file_name self.gsub(/[\-| ]/, '_'). gsub(/([A-Z]+|[A-Z][a-z])/) { |x| "_#{x}" }. sub(/^_/, ""). gsub(/_{2,}+/, "_"). downcase end |
#file_name! ⇒ Object
30 31 32 |
# File 'lib/singu/extensions.rb', line 30 def file_name! self.replace file_name end |