Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/henshin/ext.rb
Instance Method Summary collapse
-
#directory ⇒ Object
Gets the directory from a string.
-
#extension ⇒ Object
Gets the extension from a string.
-
#file_name ⇒ Object
Gets the filename from a string.
-
#slugify ⇒ Object
Turns the string to a slug.
Instance Method Details
#directory ⇒ Object
Gets the directory from a string
68 69 70 71 |
# File 'lib/henshin/ext.rb', line 68 def directory self =~ /((\.?\/?[a-zA-Z0-9 _-]+\/)+)/ $1 end |
#extension ⇒ Object
Gets the extension from a string
62 63 64 65 |
# File 'lib/henshin/ext.rb', line 62 def extension parts = self.split('.') parts[parts.size-1] end |
#file_name ⇒ Object
Gets the filename from a string
74 75 76 |
# File 'lib/henshin/ext.rb', line 74 def file_name self.dup.gsub(/([a-zA-Z0-9_-]+\/)/, '') end |
#slugify ⇒ Object
Turns the string to a slug
51 52 53 54 55 56 57 58 59 |
# File 'lib/henshin/ext.rb', line 51 def slugify slug = self.clone slug.gsub!(/[']+/, '') slug.gsub!(/\W+/, ' ') slug.strip! slug.downcase! slug.gsub!(' ', '-') slug end |